blob: 5eb0d55a39d5ff373ebf5800d8d81ce61b659c9d [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 Gregor820ba7b2011-01-04 17:33:58 +00001916 /// \brief Build a new expression to compute the length of a parameter pack.
1917 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1918 SourceLocation PackLoc,
1919 SourceLocation RParenLoc,
1920 unsigned Length) {
1921 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1922 OperatorLoc, Pack, PackLoc,
1923 RParenLoc, Length);
1924 }
1925
Douglas Gregora16548e2009-08-11 05:31:07 +00001926 /// \brief Build a new Objective-C @encode expression.
1927 ///
1928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001931 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001932 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001933 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001934 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001935 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001936
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001937 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001938 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001939 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001940 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001941 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001943 MultiExprArg Args,
1944 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001945 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1946 ReceiverTypeInfo->getType(),
1947 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001948 Sel, Method, LBracLoc, SelectorLoc,
1949 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001950 }
1951
1952 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00001953 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001954 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001955 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001956 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001957 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001958 MultiExprArg Args,
1959 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00001960 return SemaRef.BuildInstanceMessage(Receiver,
1961 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001962 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001963 Sel, Method, LBracLoc, SelectorLoc,
1964 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001965 }
1966
Douglas Gregord51d90d2010-04-26 20:11:03 +00001967 /// \brief Build a new Objective-C ivar reference expression.
1968 ///
1969 /// By default, performs semantic analysis to build the new expression.
1970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001971 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001972 SourceLocation IvarLoc,
1973 bool IsArrow, bool IsFreeIvar) {
1974 // FIXME: We lose track of the IsFreeIvar bit.
1975 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00001976 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00001977 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1978 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00001979 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001980 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00001981 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00001982 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001983 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001984 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001985
Douglas Gregord51d90d2010-04-26 20:11:03 +00001986 if (Result.get())
1987 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001988
John McCallb268a282010-08-23 23:25:46 +00001989 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001990 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001991 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001992 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001993 /*TemplateArgs=*/0);
1994 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001995
1996 /// \brief Build a new Objective-C property reference expression.
1997 ///
1998 /// By default, performs semantic analysis to build the new expression.
1999 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002000 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002001 ObjCPropertyDecl *Property,
2002 SourceLocation PropertyLoc) {
2003 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002004 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002005 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2006 Sema::LookupMemberName);
2007 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002009 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002010 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002011 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002012 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002013
Douglas Gregor9faee212010-04-26 20:47:02 +00002014 if (Result.get())
2015 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002016
John McCallb268a282010-08-23 23:25:46 +00002017 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002018 /*FIXME:*/PropertyLoc, IsArrow,
2019 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002020 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002021 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002022 /*TemplateArgs=*/0);
2023 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002024
John McCallb7bd14f2010-12-02 01:19:52 +00002025 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002026 ///
2027 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002028 /// Subclasses may override this routine to provide different behavior.
2029 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2030 ObjCMethodDecl *Getter,
2031 ObjCMethodDecl *Setter,
2032 SourceLocation PropertyLoc) {
2033 // Since these expressions can only be value-dependent, we do not
2034 // need to perform semantic analysis again.
2035 return Owned(
2036 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2037 VK_LValue, OK_ObjCProperty,
2038 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002039 }
2040
Douglas Gregord51d90d2010-04-26 20:11:03 +00002041 /// \brief Build a new Objective-C "isa" expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002045 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002046 bool IsArrow) {
2047 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002048 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002049 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2050 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002051 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002052 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002053 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002054 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002055 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002056
Douglas Gregord51d90d2010-04-26 20:11:03 +00002057 if (Result.get())
2058 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002059
John McCallb268a282010-08-23 23:25:46 +00002060 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002061 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002062 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002063 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002064 /*TemplateArgs=*/0);
2065 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002066
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 /// \brief Build a new shuffle vector expression.
2068 ///
2069 /// By default, performs semantic analysis to build the new expression.
2070 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002071 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002072 MultiExprArg SubExprs,
2073 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002075 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2077 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2078 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2079 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002080
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 // Build a reference to the __builtin_shufflevector builtin
2082 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002083 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002085 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002087
2088 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 unsigned NumSubExprs = SubExprs.size();
2090 Expr **Subs = (Expr **)SubExprs.release();
2091 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2092 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002093 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002094 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002096 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002097
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002101 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002102
Douglas Gregora16548e2009-08-11 05:31:07 +00002103 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002104 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
John McCall31f82722010-11-12 08:19:04 +00002106
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002107 /// \brief Build a new template argument pack expansion.
2108 ///
2109 /// By default, performs semantic analysis to build a new pack expansion
2110 /// for a template argument. Subclasses may override this routine to provide
2111 /// different behavior.
2112 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2113 SourceLocation EllipsisLoc) {
2114 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002115 case TemplateArgument::Expression: {
2116 ExprResult Result
2117 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2118 EllipsisLoc);
2119 if (Result.isInvalid())
2120 return TemplateArgumentLoc();
2121
2122 return TemplateArgumentLoc(Result.get(), Result.get());
2123 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002124
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002125 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002126 return TemplateArgumentLoc(TemplateArgument(
2127 Pattern.getArgument().getAsTemplate(),
2128 true),
2129 Pattern.getTemplateQualifierRange(),
2130 Pattern.getTemplateNameLoc(),
2131 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002132
2133 case TemplateArgument::Null:
2134 case TemplateArgument::Integral:
2135 case TemplateArgument::Declaration:
2136 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002137 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002138 llvm_unreachable("Pack expansion pattern has no parameter packs");
2139
2140 case TemplateArgument::Type:
2141 if (TypeSourceInfo *Expansion
2142 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2143 EllipsisLoc))
2144 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2145 Expansion);
2146 break;
2147 }
2148
2149 return TemplateArgumentLoc();
2150 }
2151
Douglas Gregor968f23a2011-01-03 19:31:53 +00002152 /// \brief Build a new expression pack expansion.
2153 ///
2154 /// By default, performs semantic analysis to build a new pack expansion
2155 /// for an expression. Subclasses may override this routine to provide
2156 /// different behavior.
2157 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2158 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2159 }
2160
John McCall31f82722010-11-12 08:19:04 +00002161private:
2162 QualType TransformTypeInObjectScope(QualType T,
2163 QualType ObjectType,
2164 NamedDecl *FirstQualifierInScope,
2165 NestedNameSpecifier *Prefix);
2166
2167 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2168 QualType ObjectType,
2169 NamedDecl *FirstQualifierInScope,
2170 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002171};
Douglas Gregora16548e2009-08-11 05:31:07 +00002172
Douglas Gregorebe10102009-08-20 07:17:43 +00002173template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002174StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002175 if (!S)
2176 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregorebe10102009-08-20 07:17:43 +00002178 switch (S->getStmtClass()) {
2179 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002180
Douglas Gregorebe10102009-08-20 07:17:43 +00002181 // Transform individual statement nodes
2182#define STMT(Node, Parent) \
2183 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2184#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002185#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregorebe10102009-08-20 07:17:43 +00002187 // Transform expressions by calling TransformExpr.
2188#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002189#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002190#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002191#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002192 {
John McCalldadc5752010-08-24 06:29:42 +00002193 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002194 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002195 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002196
John McCallb268a282010-08-23 23:25:46 +00002197 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199 }
2200
John McCallc3007a22010-10-26 07:05:15 +00002201 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002202}
Mike Stump11289f42009-09-09 15:08:12 +00002203
2204
Douglas Gregore922c772009-08-04 22:27:00 +00002205template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002206ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 if (!E)
2208 return SemaRef.Owned(E);
2209
2210 switch (E->getStmtClass()) {
2211 case Stmt::NoStmtClass: break;
2212#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002213#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002214#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002215 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002216#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002217 }
2218
John McCallc3007a22010-10-26 07:05:15 +00002219 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002220}
2221
2222template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002223bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2224 unsigned NumInputs,
2225 bool IsCall,
2226 llvm::SmallVectorImpl<Expr *> &Outputs,
2227 bool *ArgChanged) {
2228 for (unsigned I = 0; I != NumInputs; ++I) {
2229 // If requested, drop call arguments that need to be dropped.
2230 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2231 if (ArgChanged)
2232 *ArgChanged = true;
2233
2234 break;
2235 }
2236
Douglas Gregor968f23a2011-01-03 19:31:53 +00002237 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2238 Expr *Pattern = Expansion->getPattern();
2239
2240 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2241 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2242 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2243
2244 // Determine whether the set of unexpanded parameter packs can and should
2245 // be expanded.
2246 bool Expand = true;
2247 unsigned NumExpansions = 0;
2248 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2249 Pattern->getSourceRange(),
2250 Unexpanded.data(),
2251 Unexpanded.size(),
2252 Expand, NumExpansions))
2253 return true;
2254
2255 if (!Expand) {
2256 // The transform has determined that we should perform a simple
2257 // transformation on the pack expansion, producing another pack
2258 // expansion.
2259 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2260 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2261 if (OutPattern.isInvalid())
2262 return true;
2263
2264 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2265 Expansion->getEllipsisLoc());
2266 if (Out.isInvalid())
2267 return true;
2268
2269 if (ArgChanged)
2270 *ArgChanged = true;
2271 Outputs.push_back(Out.get());
2272 continue;
2273 }
2274
2275 // The transform has determined that we should perform an elementwise
2276 // expansion of the pattern. Do so.
2277 for (unsigned I = 0; I != NumExpansions; ++I) {
2278 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2279 ExprResult Out = getDerived().TransformExpr(Pattern);
2280 if (Out.isInvalid())
2281 return true;
2282
2283 if (ArgChanged)
2284 *ArgChanged = true;
2285 Outputs.push_back(Out.get());
2286 }
2287
2288 continue;
2289 }
2290
Douglas Gregora3efea12011-01-03 19:04:46 +00002291 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2292 if (Result.isInvalid())
2293 return true;
2294
2295 if (Result.get() != Inputs[I] && ArgChanged)
2296 *ArgChanged = true;
2297
2298 Outputs.push_back(Result.get());
2299 }
2300
2301 return false;
2302}
2303
2304template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002305NestedNameSpecifier *
2306TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002307 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002308 QualType ObjectType,
2309 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002310 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002311
Douglas Gregorebe10102009-08-20 07:17:43 +00002312 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002313 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002314 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002315 ObjectType,
2316 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002317 if (!Prefix)
2318 return 0;
2319 }
Mike Stump11289f42009-09-09 15:08:12 +00002320
Douglas Gregor1135c352009-08-06 05:28:30 +00002321 switch (NNS->getKind()) {
2322 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002323 if (Prefix) {
2324 // The object type and qualifier-in-scope really apply to the
2325 // leftmost entity.
2326 ObjectType = QualType();
2327 FirstQualifierInScope = 0;
2328 }
2329
Mike Stump11289f42009-09-09 15:08:12 +00002330 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002331 "Identifier nested-name-specifier with no prefix or object type");
2332 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2333 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002334 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002335
2336 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002337 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002338 ObjectType,
2339 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002340
Douglas Gregor1135c352009-08-06 05:28:30 +00002341 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002342 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002343 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002344 getDerived().TransformDecl(Range.getBegin(),
2345 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002347 Prefix == NNS->getPrefix() &&
2348 NS == NNS->getAsNamespace())
2349 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002350
Douglas Gregor1135c352009-08-06 05:28:30 +00002351 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2352 }
Mike Stump11289f42009-09-09 15:08:12 +00002353
Douglas Gregor1135c352009-08-06 05:28:30 +00002354 case NestedNameSpecifier::Global:
2355 // There is no meaningful transformation that one could perform on the
2356 // global scope.
2357 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002358
Douglas Gregor1135c352009-08-06 05:28:30 +00002359 case NestedNameSpecifier::TypeSpecWithTemplate:
2360 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002361 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002362 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2363 ObjectType,
2364 FirstQualifierInScope,
2365 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002366 if (T.isNull())
2367 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002368
Douglas Gregor1135c352009-08-06 05:28:30 +00002369 if (!getDerived().AlwaysRebuild() &&
2370 Prefix == NNS->getPrefix() &&
2371 T == QualType(NNS->getAsType(), 0))
2372 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002373
2374 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2375 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002376 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002377 }
2378 }
Mike Stump11289f42009-09-09 15:08:12 +00002379
Douglas Gregor1135c352009-08-06 05:28:30 +00002380 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002381 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002382}
2383
2384template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002385DeclarationNameInfo
2386TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002387::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002388 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002389 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002390 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002391
2392 switch (Name.getNameKind()) {
2393 case DeclarationName::Identifier:
2394 case DeclarationName::ObjCZeroArgSelector:
2395 case DeclarationName::ObjCOneArgSelector:
2396 case DeclarationName::ObjCMultiArgSelector:
2397 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002398 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002399 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002400 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002401
Douglas Gregorf816bd72009-09-03 22:13:48 +00002402 case DeclarationName::CXXConstructorName:
2403 case DeclarationName::CXXDestructorName:
2404 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002405 TypeSourceInfo *NewTInfo;
2406 CanQualType NewCanTy;
2407 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002408 NewTInfo = getDerived().TransformType(OldTInfo);
2409 if (!NewTInfo)
2410 return DeclarationNameInfo();
2411 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002412 }
2413 else {
2414 NewTInfo = 0;
2415 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002416 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002417 if (NewT.isNull())
2418 return DeclarationNameInfo();
2419 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2420 }
Mike Stump11289f42009-09-09 15:08:12 +00002421
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002422 DeclarationName NewName
2423 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2424 NewCanTy);
2425 DeclarationNameInfo NewNameInfo(NameInfo);
2426 NewNameInfo.setName(NewName);
2427 NewNameInfo.setNamedTypeInfo(NewTInfo);
2428 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002429 }
Mike Stump11289f42009-09-09 15:08:12 +00002430 }
2431
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002432 assert(0 && "Unknown name kind.");
2433 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002434}
2435
2436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002437TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002438TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002439 QualType ObjectType,
2440 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002441 SourceLocation Loc = getDerived().getBaseLocation();
2442
Douglas Gregor71dc5092009-08-06 06:41:21 +00002443 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002444 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002445 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002446 /*FIXME*/ SourceRange(Loc),
2447 ObjectType,
2448 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002449 if (!NNS)
2450 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002451
Douglas Gregor71dc5092009-08-06 06:41:21 +00002452 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002453 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002454 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002455 if (!TransTemplate)
2456 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002457
Douglas Gregor71dc5092009-08-06 06:41:21 +00002458 if (!getDerived().AlwaysRebuild() &&
2459 NNS == QTN->getQualifier() &&
2460 TransTemplate == Template)
2461 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002462
Douglas Gregor71dc5092009-08-06 06:41:21 +00002463 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2464 TransTemplate);
2465 }
Mike Stump11289f42009-09-09 15:08:12 +00002466
John McCalle66edc12009-11-24 19:00:30 +00002467 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002468 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002469 }
Mike Stump11289f42009-09-09 15:08:12 +00002470
Douglas Gregor71dc5092009-08-06 06:41:21 +00002471 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002472 NestedNameSpecifier *NNS = DTN->getQualifier();
2473 if (NNS) {
2474 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2475 /*FIXME:*/SourceRange(Loc),
2476 ObjectType,
2477 FirstQualifierInScope);
2478 if (!NNS) return TemplateName();
2479
2480 // These apply to the scope specifier, not the template.
2481 ObjectType = QualType();
2482 FirstQualifierInScope = 0;
2483 }
Mike Stump11289f42009-09-09 15:08:12 +00002484
Douglas Gregor71dc5092009-08-06 06:41:21 +00002485 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002486 NNS == DTN->getQualifier() &&
2487 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002488 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002489
Douglas Gregora5614c52010-09-08 23:56:00 +00002490 if (DTN->isIdentifier()) {
2491 // FIXME: Bad range
2492 SourceRange QualifierRange(getDerived().getBaseLocation());
2493 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2494 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002495 ObjectType,
2496 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002497 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002498
2499 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002500 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002501 }
Mike Stump11289f42009-09-09 15:08:12 +00002502
Douglas Gregor71dc5092009-08-06 06:41:21 +00002503 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002504 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002505 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002506 if (!TransTemplate)
2507 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002508
Douglas Gregor71dc5092009-08-06 06:41:21 +00002509 if (!getDerived().AlwaysRebuild() &&
2510 TransTemplate == Template)
2511 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002512
Douglas Gregor71dc5092009-08-06 06:41:21 +00002513 return TemplateName(TransTemplate);
2514 }
Mike Stump11289f42009-09-09 15:08:12 +00002515
John McCalle66edc12009-11-24 19:00:30 +00002516 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002517 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002518 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002519}
2520
2521template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002522void TreeTransform<Derived>::InventTemplateArgumentLoc(
2523 const TemplateArgument &Arg,
2524 TemplateArgumentLoc &Output) {
2525 SourceLocation Loc = getDerived().getBaseLocation();
2526 switch (Arg.getKind()) {
2527 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002528 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002529 break;
2530
2531 case TemplateArgument::Type:
2532 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002533 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002534
John McCall0ad16662009-10-29 08:12:44 +00002535 break;
2536
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002537 case TemplateArgument::Template:
2538 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2539 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002540
2541 case TemplateArgument::TemplateExpansion:
2542 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2543 break;
2544
John McCall0ad16662009-10-29 08:12:44 +00002545 case TemplateArgument::Expression:
2546 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2547 break;
2548
2549 case TemplateArgument::Declaration:
2550 case TemplateArgument::Integral:
2551 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002552 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002553 break;
2554 }
2555}
2556
2557template<typename Derived>
2558bool TreeTransform<Derived>::TransformTemplateArgument(
2559 const TemplateArgumentLoc &Input,
2560 TemplateArgumentLoc &Output) {
2561 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002562 switch (Arg.getKind()) {
2563 case TemplateArgument::Null:
2564 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002565 Output = Input;
2566 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002567
Douglas Gregore922c772009-08-04 22:27:00 +00002568 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002569 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002570 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002571 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002572
2573 DI = getDerived().TransformType(DI);
2574 if (!DI) return true;
2575
2576 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2577 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002578 }
Mike Stump11289f42009-09-09 15:08:12 +00002579
Douglas Gregore922c772009-08-04 22:27:00 +00002580 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002581 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002582 DeclarationName Name;
2583 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2584 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002585 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002586 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002587 if (!D) return true;
2588
John McCall0d07eb32009-10-29 18:45:58 +00002589 Expr *SourceExpr = Input.getSourceDeclExpression();
2590 if (SourceExpr) {
2591 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002592 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002593 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002594 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002595 }
2596
2597 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002598 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002599 }
Mike Stump11289f42009-09-09 15:08:12 +00002600
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002601 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002602 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002603 TemplateName Template
2604 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2605 if (Template.isNull())
2606 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002607
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002608 Output = TemplateArgumentLoc(TemplateArgument(Template),
2609 Input.getTemplateQualifierRange(),
2610 Input.getTemplateNameLoc());
2611 return false;
2612 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002613
2614 case TemplateArgument::TemplateExpansion:
2615 llvm_unreachable("Caller should expand pack expansions");
2616
Douglas Gregore922c772009-08-04 22:27:00 +00002617 case TemplateArgument::Expression: {
2618 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002619 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002620 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002621
John McCall0ad16662009-10-29 08:12:44 +00002622 Expr *InputExpr = Input.getSourceExpression();
2623 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2624
John McCalldadc5752010-08-24 06:29:42 +00002625 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002626 = getDerived().TransformExpr(InputExpr);
2627 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002628 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002629 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002630 }
Mike Stump11289f42009-09-09 15:08:12 +00002631
Douglas Gregore922c772009-08-04 22:27:00 +00002632 case TemplateArgument::Pack: {
2633 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2634 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002635 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002636 AEnd = Arg.pack_end();
2637 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002638
John McCall0ad16662009-10-29 08:12:44 +00002639 // FIXME: preserve source information here when we start
2640 // caring about parameter packs.
2641
John McCall0d07eb32009-10-29 18:45:58 +00002642 TemplateArgumentLoc InputArg;
2643 TemplateArgumentLoc OutputArg;
2644 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2645 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002646 return true;
2647
John McCall0d07eb32009-10-29 18:45:58 +00002648 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002649 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002650
2651 TemplateArgument *TransformedArgsPtr
2652 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2653 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2654 TransformedArgsPtr);
2655 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2656 TransformedArgs.size()),
2657 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002658 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002659 }
2660 }
Mike Stump11289f42009-09-09 15:08:12 +00002661
Douglas Gregore922c772009-08-04 22:27:00 +00002662 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002663 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002664}
2665
Douglas Gregorfe921a72010-12-20 23:36:19 +00002666/// \brief Iterator adaptor that invents template argument location information
2667/// for each of the template arguments in its underlying iterator.
2668template<typename Derived, typename InputIterator>
2669class TemplateArgumentLocInventIterator {
2670 TreeTransform<Derived> &Self;
2671 InputIterator Iter;
2672
2673public:
2674 typedef TemplateArgumentLoc value_type;
2675 typedef TemplateArgumentLoc reference;
2676 typedef typename std::iterator_traits<InputIterator>::difference_type
2677 difference_type;
2678 typedef std::input_iterator_tag iterator_category;
2679
2680 class pointer {
2681 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002682
Douglas Gregorfe921a72010-12-20 23:36:19 +00002683 public:
2684 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2685
2686 const TemplateArgumentLoc *operator->() const { return &Arg; }
2687 };
2688
2689 TemplateArgumentLocInventIterator() { }
2690
2691 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2692 InputIterator Iter)
2693 : Self(Self), Iter(Iter) { }
2694
2695 TemplateArgumentLocInventIterator &operator++() {
2696 ++Iter;
2697 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002698 }
2699
Douglas Gregorfe921a72010-12-20 23:36:19 +00002700 TemplateArgumentLocInventIterator operator++(int) {
2701 TemplateArgumentLocInventIterator Old(*this);
2702 ++(*this);
2703 return Old;
2704 }
2705
2706 reference operator*() const {
2707 TemplateArgumentLoc Result;
2708 Self.InventTemplateArgumentLoc(*Iter, Result);
2709 return Result;
2710 }
2711
2712 pointer operator->() const { return pointer(**this); }
2713
2714 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2715 const TemplateArgumentLocInventIterator &Y) {
2716 return X.Iter == Y.Iter;
2717 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002718
Douglas Gregorfe921a72010-12-20 23:36:19 +00002719 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2720 const TemplateArgumentLocInventIterator &Y) {
2721 return X.Iter != Y.Iter;
2722 }
2723};
2724
Douglas Gregor42cafa82010-12-20 17:42:22 +00002725template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002726template<typename InputIterator>
2727bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2728 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002729 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002730 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002731 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002732 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002733
2734 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2735 // Unpack argument packs, which we translate them into separate
2736 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002737 // FIXME: We could do much better if we could guarantee that the
2738 // TemplateArgumentLocInfo for the pack expansion would be usable for
2739 // all of the template arguments in the argument pack.
2740 typedef TemplateArgumentLocInventIterator<Derived,
2741 TemplateArgument::pack_iterator>
2742 PackLocIterator;
2743 if (TransformTemplateArguments(PackLocIterator(*this,
2744 In.getArgument().pack_begin()),
2745 PackLocIterator(*this,
2746 In.getArgument().pack_end()),
2747 Outputs))
2748 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002749
2750 continue;
2751 }
2752
2753 if (In.getArgument().isPackExpansion()) {
2754 // We have a pack expansion, for which we will be substituting into
2755 // the pattern.
2756 SourceLocation Ellipsis;
2757 TemplateArgumentLoc Pattern
2758 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2759
2760 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2761 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2762 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2763
2764 // Determine whether the set of unexpanded parameter packs can and should
2765 // be expanded.
2766 bool Expand = true;
2767 unsigned NumExpansions = 0;
2768 if (getDerived().TryExpandParameterPacks(Ellipsis,
2769 Pattern.getSourceRange(),
2770 Unexpanded.data(),
2771 Unexpanded.size(),
2772 Expand, NumExpansions))
2773 return true;
2774
2775 if (!Expand) {
2776 // The transform has determined that we should perform a simple
2777 // transformation on the pack expansion, producing another pack
2778 // expansion.
2779 TemplateArgumentLoc OutPattern;
2780 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2781 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2782 return true;
2783
2784 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2785 if (Out.getArgument().isNull())
2786 return true;
2787
2788 Outputs.addArgument(Out);
2789 continue;
2790 }
2791
2792 // The transform has determined that we should perform an elementwise
2793 // expansion of the pattern. Do so.
2794 for (unsigned I = 0; I != NumExpansions; ++I) {
2795 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2796
2797 if (getDerived().TransformTemplateArgument(Pattern, Out))
2798 return true;
2799
2800 Outputs.addArgument(Out);
2801 }
2802
2803 continue;
2804 }
2805
2806 // The simple case:
2807 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002808 return true;
2809
2810 Outputs.addArgument(Out);
2811 }
2812
2813 return false;
2814
2815}
2816
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817//===----------------------------------------------------------------------===//
2818// Type transformation
2819//===----------------------------------------------------------------------===//
2820
2821template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002822QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002823 if (getDerived().AlreadyTransformed(T))
2824 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002825
John McCall550e0c22009-10-21 00:40:46 +00002826 // Temporary workaround. All of these transformations should
2827 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002828 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002829 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002830
John McCall31f82722010-11-12 08:19:04 +00002831 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002832
John McCall550e0c22009-10-21 00:40:46 +00002833 if (!NewDI)
2834 return QualType();
2835
2836 return NewDI->getType();
2837}
2838
2839template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002840TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002841 if (getDerived().AlreadyTransformed(DI->getType()))
2842 return DI;
2843
2844 TypeLocBuilder TLB;
2845
2846 TypeLoc TL = DI->getTypeLoc();
2847 TLB.reserve(TL.getFullDataSize());
2848
John McCall31f82722010-11-12 08:19:04 +00002849 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002850 if (Result.isNull())
2851 return 0;
2852
John McCallbcd03502009-12-07 02:54:59 +00002853 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002854}
2855
2856template<typename Derived>
2857QualType
John McCall31f82722010-11-12 08:19:04 +00002858TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002859 switch (T.getTypeLocClass()) {
2860#define ABSTRACT_TYPELOC(CLASS, PARENT)
2861#define TYPELOC(CLASS, PARENT) \
2862 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002863 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002864#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865 }
Mike Stump11289f42009-09-09 15:08:12 +00002866
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002867 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002868 return QualType();
2869}
2870
2871/// FIXME: By default, this routine adds type qualifiers only to types
2872/// that can have qualifiers, and silently suppresses those qualifiers
2873/// that are not permitted (e.g., qualifiers on reference or function
2874/// types). This is the right thing for template instantiation, but
2875/// probably not for other clients.
2876template<typename Derived>
2877QualType
2878TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002879 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002880 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002881
John McCall31f82722010-11-12 08:19:04 +00002882 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002883 if (Result.isNull())
2884 return QualType();
2885
2886 // Silently suppress qualifiers if the result type can't be qualified.
2887 // FIXME: this is the right thing for template instantiation, but
2888 // probably not for other clients.
2889 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002890 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCallcb0f89a2010-06-05 06:41:15 +00002892 if (!Quals.empty()) {
2893 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2894 TLB.push<QualifiedTypeLoc>(Result);
2895 // No location information to preserve.
2896 }
John McCall550e0c22009-10-21 00:40:46 +00002897
2898 return Result;
2899}
2900
John McCall31f82722010-11-12 08:19:04 +00002901/// \brief Transforms a type that was written in a scope specifier,
2902/// given an object type, the results of unqualified lookup, and
2903/// an already-instantiated prefix.
2904///
2905/// The object type is provided iff the scope specifier qualifies the
2906/// member of a dependent member-access expression. The prefix is
2907/// provided iff the the scope specifier in which this appears has a
2908/// prefix.
2909///
2910/// This is private to TreeTransform.
2911template<typename Derived>
2912QualType
2913TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2914 QualType ObjectType,
2915 NamedDecl *UnqualLookup,
2916 NestedNameSpecifier *Prefix) {
2917 if (getDerived().AlreadyTransformed(T))
2918 return T;
2919
2920 TypeSourceInfo *TSI =
2921 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2922
2923 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2924 UnqualLookup, Prefix);
2925 if (!TSI) return QualType();
2926 return TSI->getType();
2927}
2928
2929template<typename Derived>
2930TypeSourceInfo *
2931TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2932 QualType ObjectType,
2933 NamedDecl *UnqualLookup,
2934 NestedNameSpecifier *Prefix) {
2935 // TODO: in some cases, we might be some verification to do here.
2936 if (ObjectType.isNull())
2937 return getDerived().TransformType(TSI);
2938
2939 QualType T = TSI->getType();
2940 if (getDerived().AlreadyTransformed(T))
2941 return TSI;
2942
2943 TypeLocBuilder TLB;
2944 QualType Result;
2945
2946 if (isa<TemplateSpecializationType>(T)) {
2947 TemplateSpecializationTypeLoc TL
2948 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2949
2950 TemplateName Template =
2951 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
2952 ObjectType, UnqualLookup);
2953 if (Template.isNull()) return 0;
2954
2955 Result = getDerived()
2956 .TransformTemplateSpecializationType(TLB, TL, Template);
2957 } else if (isa<DependentTemplateSpecializationType>(T)) {
2958 DependentTemplateSpecializationTypeLoc TL
2959 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
2960
2961 Result = getDerived()
2962 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
2963 } else {
2964 // Nothing special needs to be done for these.
2965 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
2966 }
2967
2968 if (Result.isNull()) return 0;
2969 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
2970}
2971
John McCall550e0c22009-10-21 00:40:46 +00002972template <class TyLoc> static inline
2973QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2974 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2975 NewT.setNameLoc(T.getNameLoc());
2976 return T.getType();
2977}
2978
John McCall550e0c22009-10-21 00:40:46 +00002979template<typename Derived>
2980QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002981 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002982 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2983 NewT.setBuiltinLoc(T.getBuiltinLoc());
2984 if (T.needsExtraLocalData())
2985 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2986 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987}
Mike Stump11289f42009-09-09 15:08:12 +00002988
Douglas Gregord6ff3322009-08-04 16:50:30 +00002989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002990QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002991 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002992 // FIXME: recurse?
2993 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994}
Mike Stump11289f42009-09-09 15:08:12 +00002995
Douglas Gregord6ff3322009-08-04 16:50:30 +00002996template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002997QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002998 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002999 QualType PointeeType
3000 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003001 if (PointeeType.isNull())
3002 return QualType();
3003
3004 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003005 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003006 // A dependent pointer type 'T *' has is being transformed such
3007 // that an Objective-C class type is being replaced for 'T'. The
3008 // resulting pointer type is an ObjCObjectPointerType, not a
3009 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003010 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003011
John McCall8b07ec22010-05-15 11:32:37 +00003012 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3013 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003014 return Result;
3015 }
John McCall31f82722010-11-12 08:19:04 +00003016
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003017 if (getDerived().AlwaysRebuild() ||
3018 PointeeType != TL.getPointeeLoc().getType()) {
3019 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3020 if (Result.isNull())
3021 return QualType();
3022 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003023
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003024 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3025 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003026 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003027}
Mike Stump11289f42009-09-09 15:08:12 +00003028
3029template<typename Derived>
3030QualType
John McCall550e0c22009-10-21 00:40:46 +00003031TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003032 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003033 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003034 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3035 if (PointeeType.isNull())
3036 return QualType();
3037
3038 QualType Result = TL.getType();
3039 if (getDerived().AlwaysRebuild() ||
3040 PointeeType != TL.getPointeeLoc().getType()) {
3041 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003042 TL.getSigilLoc());
3043 if (Result.isNull())
3044 return QualType();
3045 }
3046
Douglas Gregor049211a2010-04-22 16:50:51 +00003047 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003048 NewT.setSigilLoc(TL.getSigilLoc());
3049 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050}
3051
John McCall70dd5f62009-10-30 00:06:24 +00003052/// Transforms a reference type. Note that somewhat paradoxically we
3053/// don't care whether the type itself is an l-value type or an r-value
3054/// type; we only care if the type was *written* as an l-value type
3055/// or an r-value type.
3056template<typename Derived>
3057QualType
3058TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003059 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003060 const ReferenceType *T = TL.getTypePtr();
3061
3062 // Note that this works with the pointee-as-written.
3063 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3064 if (PointeeType.isNull())
3065 return QualType();
3066
3067 QualType Result = TL.getType();
3068 if (getDerived().AlwaysRebuild() ||
3069 PointeeType != T->getPointeeTypeAsWritten()) {
3070 Result = getDerived().RebuildReferenceType(PointeeType,
3071 T->isSpelledAsLValue(),
3072 TL.getSigilLoc());
3073 if (Result.isNull())
3074 return QualType();
3075 }
3076
3077 // r-value references can be rebuilt as l-value references.
3078 ReferenceTypeLoc NewTL;
3079 if (isa<LValueReferenceType>(Result))
3080 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3081 else
3082 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3083 NewTL.setSigilLoc(TL.getSigilLoc());
3084
3085 return Result;
3086}
3087
Mike Stump11289f42009-09-09 15:08:12 +00003088template<typename Derived>
3089QualType
John McCall550e0c22009-10-21 00:40:46 +00003090TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003091 LValueReferenceTypeLoc TL) {
3092 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
3094
Mike Stump11289f42009-09-09 15:08:12 +00003095template<typename Derived>
3096QualType
John McCall550e0c22009-10-21 00:40:46 +00003097TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003098 RValueReferenceTypeLoc TL) {
3099 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003100}
Mike Stump11289f42009-09-09 15:08:12 +00003101
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003103QualType
John McCall550e0c22009-10-21 00:40:46 +00003104TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003105 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003106 MemberPointerType *T = TL.getTypePtr();
3107
3108 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109 if (PointeeType.isNull())
3110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 // TODO: preserve source information for this.
3113 QualType ClassType
3114 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115 if (ClassType.isNull())
3116 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003117
John McCall550e0c22009-10-21 00:40:46 +00003118 QualType Result = TL.getType();
3119 if (getDerived().AlwaysRebuild() ||
3120 PointeeType != T->getPointeeType() ||
3121 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003122 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3123 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003124 if (Result.isNull())
3125 return QualType();
3126 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003127
John McCall550e0c22009-10-21 00:40:46 +00003128 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3129 NewTL.setSigilLoc(TL.getSigilLoc());
3130
3131 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003132}
3133
Mike Stump11289f42009-09-09 15:08:12 +00003134template<typename Derived>
3135QualType
John McCall550e0c22009-10-21 00:40:46 +00003136TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003137 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003138 ConstantArrayType *T = TL.getTypePtr();
3139 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140 if (ElementType.isNull())
3141 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003142
John McCall550e0c22009-10-21 00:40:46 +00003143 QualType Result = TL.getType();
3144 if (getDerived().AlwaysRebuild() ||
3145 ElementType != T->getElementType()) {
3146 Result = getDerived().RebuildConstantArrayType(ElementType,
3147 T->getSizeModifier(),
3148 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003149 T->getIndexTypeCVRQualifiers(),
3150 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003151 if (Result.isNull())
3152 return QualType();
3153 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003154
John McCall550e0c22009-10-21 00:40:46 +00003155 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3156 NewTL.setLBracketLoc(TL.getLBracketLoc());
3157 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCall550e0c22009-10-21 00:40:46 +00003159 Expr *Size = TL.getSizeExpr();
3160 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003161 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003162 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3163 }
3164 NewTL.setSizeExpr(Size);
3165
3166 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003167}
Mike Stump11289f42009-09-09 15:08:12 +00003168
Douglas Gregord6ff3322009-08-04 16:50:30 +00003169template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003170QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003171 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003172 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003173 IncompleteArrayType *T = TL.getTypePtr();
3174 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003175 if (ElementType.isNull())
3176 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003177
John McCall550e0c22009-10-21 00:40:46 +00003178 QualType Result = TL.getType();
3179 if (getDerived().AlwaysRebuild() ||
3180 ElementType != T->getElementType()) {
3181 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003182 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003183 T->getIndexTypeCVRQualifiers(),
3184 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003185 if (Result.isNull())
3186 return QualType();
3187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003188
John McCall550e0c22009-10-21 00:40:46 +00003189 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3190 NewTL.setLBracketLoc(TL.getLBracketLoc());
3191 NewTL.setRBracketLoc(TL.getRBracketLoc());
3192 NewTL.setSizeExpr(0);
3193
3194 return Result;
3195}
3196
3197template<typename Derived>
3198QualType
3199TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003200 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003201 VariableArrayType *T = TL.getTypePtr();
3202 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3203 if (ElementType.isNull())
3204 return QualType();
3205
3206 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003207 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003208
John McCalldadc5752010-08-24 06:29:42 +00003209 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003210 = getDerived().TransformExpr(T->getSizeExpr());
3211 if (SizeResult.isInvalid())
3212 return QualType();
3213
John McCallb268a282010-08-23 23:25:46 +00003214 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003215
3216 QualType Result = TL.getType();
3217 if (getDerived().AlwaysRebuild() ||
3218 ElementType != T->getElementType() ||
3219 Size != T->getSizeExpr()) {
3220 Result = getDerived().RebuildVariableArrayType(ElementType,
3221 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003222 Size,
John McCall550e0c22009-10-21 00:40:46 +00003223 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003224 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003225 if (Result.isNull())
3226 return QualType();
3227 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003228
John McCall550e0c22009-10-21 00:40:46 +00003229 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3230 NewTL.setLBracketLoc(TL.getLBracketLoc());
3231 NewTL.setRBracketLoc(TL.getRBracketLoc());
3232 NewTL.setSizeExpr(Size);
3233
3234 return Result;
3235}
3236
3237template<typename Derived>
3238QualType
3239TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003240 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003241 DependentSizedArrayType *T = TL.getTypePtr();
3242 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3243 if (ElementType.isNull())
3244 return QualType();
3245
3246 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003247 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003248
John McCalldadc5752010-08-24 06:29:42 +00003249 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003250 = getDerived().TransformExpr(T->getSizeExpr());
3251 if (SizeResult.isInvalid())
3252 return QualType();
3253
3254 Expr *Size = static_cast<Expr*>(SizeResult.get());
3255
3256 QualType Result = TL.getType();
3257 if (getDerived().AlwaysRebuild() ||
3258 ElementType != T->getElementType() ||
3259 Size != T->getSizeExpr()) {
3260 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3261 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003262 Size,
John McCall550e0c22009-10-21 00:40:46 +00003263 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003264 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003265 if (Result.isNull())
3266 return QualType();
3267 }
3268 else SizeResult.take();
3269
3270 // We might have any sort of array type now, but fortunately they
3271 // all have the same location layout.
3272 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3273 NewTL.setLBracketLoc(TL.getLBracketLoc());
3274 NewTL.setRBracketLoc(TL.getRBracketLoc());
3275 NewTL.setSizeExpr(Size);
3276
3277 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003278}
Mike Stump11289f42009-09-09 15:08:12 +00003279
3280template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003281QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003282 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003283 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003284 DependentSizedExtVectorType *T = TL.getTypePtr();
3285
3286 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003287 QualType ElementType = getDerived().TransformType(T->getElementType());
3288 if (ElementType.isNull())
3289 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregore922c772009-08-04 22:27:00 +00003291 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003292 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003293
John McCalldadc5752010-08-24 06:29:42 +00003294 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295 if (Size.isInvalid())
3296 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003297
John McCall550e0c22009-10-21 00:40:46 +00003298 QualType Result = TL.getType();
3299 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003300 ElementType != T->getElementType() ||
3301 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003302 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003303 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003305 if (Result.isNull())
3306 return QualType();
3307 }
John McCall550e0c22009-10-21 00:40:46 +00003308
3309 // Result might be dependent or not.
3310 if (isa<DependentSizedExtVectorType>(Result)) {
3311 DependentSizedExtVectorTypeLoc NewTL
3312 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3313 NewTL.setNameLoc(TL.getNameLoc());
3314 } else {
3315 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3316 NewTL.setNameLoc(TL.getNameLoc());
3317 }
3318
3319 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003320}
Mike Stump11289f42009-09-09 15:08:12 +00003321
3322template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003323QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003324 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003325 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003326 QualType ElementType = getDerived().TransformType(T->getElementType());
3327 if (ElementType.isNull())
3328 return QualType();
3329
John McCall550e0c22009-10-21 00:40:46 +00003330 QualType Result = TL.getType();
3331 if (getDerived().AlwaysRebuild() ||
3332 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003333 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003334 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003335 if (Result.isNull())
3336 return QualType();
3337 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003338
John McCall550e0c22009-10-21 00:40:46 +00003339 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3340 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003341
John McCall550e0c22009-10-21 00:40:46 +00003342 return Result;
3343}
3344
3345template<typename Derived>
3346QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003347 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003348 VectorType *T = TL.getTypePtr();
3349 QualType ElementType = getDerived().TransformType(T->getElementType());
3350 if (ElementType.isNull())
3351 return QualType();
3352
3353 QualType Result = TL.getType();
3354 if (getDerived().AlwaysRebuild() ||
3355 ElementType != T->getElementType()) {
3356 Result = getDerived().RebuildExtVectorType(ElementType,
3357 T->getNumElements(),
3358 /*FIXME*/ SourceLocation());
3359 if (Result.isNull())
3360 return QualType();
3361 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003362
John McCall550e0c22009-10-21 00:40:46 +00003363 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3364 NewTL.setNameLoc(TL.getNameLoc());
3365
3366 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003367}
Mike Stump11289f42009-09-09 15:08:12 +00003368
3369template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003370ParmVarDecl *
3371TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3372 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3373 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3374 if (!NewDI)
3375 return 0;
3376
3377 if (NewDI == OldDI)
3378 return OldParm;
3379 else
3380 return ParmVarDecl::Create(SemaRef.Context,
3381 OldParm->getDeclContext(),
3382 OldParm->getLocation(),
3383 OldParm->getIdentifier(),
3384 NewDI->getType(),
3385 NewDI,
3386 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003387 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003388 /* DefArg */ NULL);
3389}
3390
3391template<typename Derived>
3392bool TreeTransform<Derived>::
3393 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
3394 llvm::SmallVectorImpl<QualType> &PTypes,
3395 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
3396 FunctionProtoType *T = TL.getTypePtr();
3397
3398 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3399 ParmVarDecl *OldParm = TL.getArg(i);
3400
3401 QualType NewType;
3402 ParmVarDecl *NewParm;
3403
3404 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00003405 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
3406 if (!NewParm)
3407 return true;
3408 NewType = NewParm->getType();
3409
3410 // Deal with the possibility that we don't have a parameter
3411 // declaration for this parameter.
3412 } else {
3413 NewParm = 0;
3414
3415 QualType OldType = T->getArgType(i);
3416 NewType = getDerived().TransformType(OldType);
3417 if (NewType.isNull())
3418 return true;
3419 }
3420
3421 PTypes.push_back(NewType);
3422 PVars.push_back(NewParm);
3423 }
3424
3425 return false;
3426}
3427
3428template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003429QualType
John McCall550e0c22009-10-21 00:40:46 +00003430TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003431 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003432 // Transform the parameters and return type.
3433 //
3434 // We instantiate in source order, with the return type first followed by
3435 // the parameters, because users tend to expect this (even if they shouldn't
3436 // rely on it!).
3437 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003438 // When the function has a trailing return type, we instantiate the
3439 // parameters before the return type, since the return type can then refer
3440 // to the parameters themselves (via decltype, sizeof, etc.).
3441 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003442 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003443 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003444 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003445
Douglas Gregor7fb25412010-10-01 18:44:50 +00003446 QualType ResultType;
3447
3448 if (TL.getTrailingReturn()) {
3449 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3450 return QualType();
3451
3452 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3453 if (ResultType.isNull())
3454 return QualType();
3455 }
3456 else {
3457 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3458 if (ResultType.isNull())
3459 return QualType();
3460
3461 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
3462 return QualType();
3463 }
3464
John McCall550e0c22009-10-21 00:40:46 +00003465 QualType Result = TL.getType();
3466 if (getDerived().AlwaysRebuild() ||
3467 ResultType != T->getResultType() ||
3468 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3469 Result = getDerived().RebuildFunctionProtoType(ResultType,
3470 ParamTypes.data(),
3471 ParamTypes.size(),
3472 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003473 T->getTypeQuals(),
3474 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003475 if (Result.isNull())
3476 return QualType();
3477 }
Mike Stump11289f42009-09-09 15:08:12 +00003478
John McCall550e0c22009-10-21 00:40:46 +00003479 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3480 NewTL.setLParenLoc(TL.getLParenLoc());
3481 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003482 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003483 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3484 NewTL.setArg(i, ParamDecls[i]);
3485
3486 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003487}
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregord6ff3322009-08-04 16:50:30 +00003489template<typename Derived>
3490QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003491 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003492 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003493 FunctionNoProtoType *T = TL.getTypePtr();
3494 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3495 if (ResultType.isNull())
3496 return QualType();
3497
3498 QualType Result = TL.getType();
3499 if (getDerived().AlwaysRebuild() ||
3500 ResultType != T->getResultType())
3501 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3502
3503 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3504 NewTL.setLParenLoc(TL.getLParenLoc());
3505 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003506 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003507
3508 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003509}
Mike Stump11289f42009-09-09 15:08:12 +00003510
John McCallb96ec562009-12-04 22:46:56 +00003511template<typename Derived> QualType
3512TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003513 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003514 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003515 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003516 if (!D)
3517 return QualType();
3518
3519 QualType Result = TL.getType();
3520 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3521 Result = getDerived().RebuildUnresolvedUsingType(D);
3522 if (Result.isNull())
3523 return QualType();
3524 }
3525
3526 // We might get an arbitrary type spec type back. We should at
3527 // least always get a type spec type, though.
3528 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3529 NewTL.setNameLoc(TL.getNameLoc());
3530
3531 return Result;
3532}
3533
Douglas Gregord6ff3322009-08-04 16:50:30 +00003534template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003535QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003536 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003537 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003538 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003539 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3540 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003541 if (!Typedef)
3542 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003543
John McCall550e0c22009-10-21 00:40:46 +00003544 QualType Result = TL.getType();
3545 if (getDerived().AlwaysRebuild() ||
3546 Typedef != T->getDecl()) {
3547 Result = getDerived().RebuildTypedefType(Typedef);
3548 if (Result.isNull())
3549 return QualType();
3550 }
Mike Stump11289f42009-09-09 15:08:12 +00003551
John McCall550e0c22009-10-21 00:40:46 +00003552 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3553 NewTL.setNameLoc(TL.getNameLoc());
3554
3555 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003556}
Mike Stump11289f42009-09-09 15:08:12 +00003557
Douglas Gregord6ff3322009-08-04 16:50:30 +00003558template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003559QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003560 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003561 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003562 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003563
John McCalldadc5752010-08-24 06:29:42 +00003564 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003565 if (E.isInvalid())
3566 return QualType();
3567
John McCall550e0c22009-10-21 00:40:46 +00003568 QualType Result = TL.getType();
3569 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003570 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003571 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003572 if (Result.isNull())
3573 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003574 }
John McCall550e0c22009-10-21 00:40:46 +00003575 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003576
John McCall550e0c22009-10-21 00:40:46 +00003577 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003578 NewTL.setTypeofLoc(TL.getTypeofLoc());
3579 NewTL.setLParenLoc(TL.getLParenLoc());
3580 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003581
3582 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003583}
Mike Stump11289f42009-09-09 15:08:12 +00003584
3585template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003586QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003587 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003588 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3589 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3590 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003591 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003592
John McCall550e0c22009-10-21 00:40:46 +00003593 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003594 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3595 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003596 if (Result.isNull())
3597 return QualType();
3598 }
Mike Stump11289f42009-09-09 15:08:12 +00003599
John McCall550e0c22009-10-21 00:40:46 +00003600 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003601 NewTL.setTypeofLoc(TL.getTypeofLoc());
3602 NewTL.setLParenLoc(TL.getLParenLoc());
3603 NewTL.setRParenLoc(TL.getRParenLoc());
3604 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003605
3606 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003607}
Mike Stump11289f42009-09-09 15:08:12 +00003608
3609template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003610QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003611 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003612 DecltypeType *T = TL.getTypePtr();
3613
Douglas Gregore922c772009-08-04 22:27:00 +00003614 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003615 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003616
John McCalldadc5752010-08-24 06:29:42 +00003617 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003618 if (E.isInvalid())
3619 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003620
John McCall550e0c22009-10-21 00:40:46 +00003621 QualType Result = TL.getType();
3622 if (getDerived().AlwaysRebuild() ||
3623 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003624 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003625 if (Result.isNull())
3626 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003627 }
John McCall550e0c22009-10-21 00:40:46 +00003628 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003629
John McCall550e0c22009-10-21 00:40:46 +00003630 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3631 NewTL.setNameLoc(TL.getNameLoc());
3632
3633 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003634}
3635
3636template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003637QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003638 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003639 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003640 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003641 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3642 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003643 if (!Record)
3644 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003645
John McCall550e0c22009-10-21 00:40:46 +00003646 QualType Result = TL.getType();
3647 if (getDerived().AlwaysRebuild() ||
3648 Record != T->getDecl()) {
3649 Result = getDerived().RebuildRecordType(Record);
3650 if (Result.isNull())
3651 return QualType();
3652 }
Mike Stump11289f42009-09-09 15:08:12 +00003653
John McCall550e0c22009-10-21 00:40:46 +00003654 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3655 NewTL.setNameLoc(TL.getNameLoc());
3656
3657 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003658}
Mike Stump11289f42009-09-09 15:08:12 +00003659
3660template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003661QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003662 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003663 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003664 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003665 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3666 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003667 if (!Enum)
3668 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003669
John McCall550e0c22009-10-21 00:40:46 +00003670 QualType Result = TL.getType();
3671 if (getDerived().AlwaysRebuild() ||
3672 Enum != T->getDecl()) {
3673 Result = getDerived().RebuildEnumType(Enum);
3674 if (Result.isNull())
3675 return QualType();
3676 }
Mike Stump11289f42009-09-09 15:08:12 +00003677
John McCall550e0c22009-10-21 00:40:46 +00003678 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3679 NewTL.setNameLoc(TL.getNameLoc());
3680
3681 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003682}
John McCallfcc33b02009-09-05 00:15:47 +00003683
John McCalle78aac42010-03-10 03:28:59 +00003684template<typename Derived>
3685QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3686 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003687 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003688 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3689 TL.getTypePtr()->getDecl());
3690 if (!D) return QualType();
3691
3692 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3693 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3694 return T;
3695}
3696
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregord6ff3322009-08-04 16:50:30 +00003698template<typename Derived>
3699QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003700 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003701 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003702 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003703}
3704
Mike Stump11289f42009-09-09 15:08:12 +00003705template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003706QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003707 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003708 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003709 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003710}
3711
3712template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003713QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003714 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003715 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003716 const TemplateSpecializationType *T = TL.getTypePtr();
3717
Mike Stump11289f42009-09-09 15:08:12 +00003718 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003719 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003720 if (Template.isNull())
3721 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003722
John McCall31f82722010-11-12 08:19:04 +00003723 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3724}
3725
Douglas Gregorfe921a72010-12-20 23:36:19 +00003726namespace {
3727 /// \brief Simple iterator that traverses the template arguments in a
3728 /// container that provides a \c getArgLoc() member function.
3729 ///
3730 /// This iterator is intended to be used with the iterator form of
3731 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3732 template<typename ArgLocContainer>
3733 class TemplateArgumentLocContainerIterator {
3734 ArgLocContainer *Container;
3735 unsigned Index;
3736
3737 public:
3738 typedef TemplateArgumentLoc value_type;
3739 typedef TemplateArgumentLoc reference;
3740 typedef int difference_type;
3741 typedef std::input_iterator_tag iterator_category;
3742
3743 class pointer {
3744 TemplateArgumentLoc Arg;
3745
3746 public:
3747 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3748
3749 const TemplateArgumentLoc *operator->() const {
3750 return &Arg;
3751 }
3752 };
3753
3754
3755 TemplateArgumentLocContainerIterator() {}
3756
3757 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3758 unsigned Index)
3759 : Container(&Container), Index(Index) { }
3760
3761 TemplateArgumentLocContainerIterator &operator++() {
3762 ++Index;
3763 return *this;
3764 }
3765
3766 TemplateArgumentLocContainerIterator operator++(int) {
3767 TemplateArgumentLocContainerIterator Old(*this);
3768 ++(*this);
3769 return Old;
3770 }
3771
3772 TemplateArgumentLoc operator*() const {
3773 return Container->getArgLoc(Index);
3774 }
3775
3776 pointer operator->() const {
3777 return pointer(Container->getArgLoc(Index));
3778 }
3779
3780 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003781 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003782 return X.Container == Y.Container && X.Index == Y.Index;
3783 }
3784
3785 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003786 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003787 return !(X == Y);
3788 }
3789 };
3790}
3791
3792
John McCall31f82722010-11-12 08:19:04 +00003793template <typename Derived>
3794QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3795 TypeLocBuilder &TLB,
3796 TemplateSpecializationTypeLoc TL,
3797 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00003798 TemplateArgumentListInfo NewTemplateArgs;
3799 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3800 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003801 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3802 ArgIterator;
3803 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3804 ArgIterator(TL, TL.getNumArgs()),
3805 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003806 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003807
John McCall0ad16662009-10-29 08:12:44 +00003808 // FIXME: maybe don't rebuild if all the template arguments are the same.
3809
3810 QualType Result =
3811 getDerived().RebuildTemplateSpecializationType(Template,
3812 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003813 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003814
3815 if (!Result.isNull()) {
3816 TemplateSpecializationTypeLoc NewTL
3817 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3818 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3819 NewTL.setLAngleLoc(TL.getLAngleLoc());
3820 NewTL.setRAngleLoc(TL.getRAngleLoc());
3821 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3822 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003823 }
Mike Stump11289f42009-09-09 15:08:12 +00003824
John McCall0ad16662009-10-29 08:12:44 +00003825 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003826}
Mike Stump11289f42009-09-09 15:08:12 +00003827
3828template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003829QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003830TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003831 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003832 ElaboratedType *T = TL.getTypePtr();
3833
3834 NestedNameSpecifier *NNS = 0;
3835 // NOTE: the qualifier in an ElaboratedType is optional.
3836 if (T->getQualifier() != 0) {
3837 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003838 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00003839 if (!NNS)
3840 return QualType();
3841 }
Mike Stump11289f42009-09-09 15:08:12 +00003842
John McCall31f82722010-11-12 08:19:04 +00003843 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3844 if (NamedT.isNull())
3845 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003846
John McCall550e0c22009-10-21 00:40:46 +00003847 QualType Result = TL.getType();
3848 if (getDerived().AlwaysRebuild() ||
3849 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003850 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00003851 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
3852 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003853 if (Result.isNull())
3854 return QualType();
3855 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003856
Abramo Bagnara6150c882010-05-11 21:36:43 +00003857 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003858 NewTL.setKeywordLoc(TL.getKeywordLoc());
3859 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003860
3861 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003862}
Mike Stump11289f42009-09-09 15:08:12 +00003863
3864template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00003865QualType
3866TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
3867 ParenTypeLoc TL) {
3868 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
3869 if (Inner.isNull())
3870 return QualType();
3871
3872 QualType Result = TL.getType();
3873 if (getDerived().AlwaysRebuild() ||
3874 Inner != TL.getInnerLoc().getType()) {
3875 Result = getDerived().RebuildParenType(Inner);
3876 if (Result.isNull())
3877 return QualType();
3878 }
3879
3880 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
3881 NewTL.setLParenLoc(TL.getLParenLoc());
3882 NewTL.setRParenLoc(TL.getRParenLoc());
3883 return Result;
3884}
3885
3886template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003887QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003888 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003889 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003890
Douglas Gregord6ff3322009-08-04 16:50:30 +00003891 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003892 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003893 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003894 if (!NNS)
3895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003896
John McCallc392f372010-06-11 00:33:02 +00003897 QualType Result
3898 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3899 T->getIdentifier(),
3900 TL.getKeywordLoc(),
3901 TL.getQualifierRange(),
3902 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003903 if (Result.isNull())
3904 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003905
Abramo Bagnarad7548482010-05-19 21:37:53 +00003906 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3907 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003908 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3909
Abramo Bagnarad7548482010-05-19 21:37:53 +00003910 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3911 NewTL.setKeywordLoc(TL.getKeywordLoc());
3912 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003913 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003914 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3915 NewTL.setKeywordLoc(TL.getKeywordLoc());
3916 NewTL.setQualifierRange(TL.getQualifierRange());
3917 NewTL.setNameLoc(TL.getNameLoc());
3918 }
John McCall550e0c22009-10-21 00:40:46 +00003919 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003920}
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregord6ff3322009-08-04 16:50:30 +00003922template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003923QualType TreeTransform<Derived>::
3924 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003925 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00003926 DependentTemplateSpecializationType *T = TL.getTypePtr();
3927
3928 NestedNameSpecifier *NNS
3929 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00003930 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003931 if (!NNS)
3932 return QualType();
3933
John McCall31f82722010-11-12 08:19:04 +00003934 return getDerived()
3935 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
3936}
3937
3938template<typename Derived>
3939QualType TreeTransform<Derived>::
3940 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3941 DependentTemplateSpecializationTypeLoc TL,
3942 NestedNameSpecifier *NNS) {
3943 DependentTemplateSpecializationType *T = TL.getTypePtr();
3944
John McCallc392f372010-06-11 00:33:02 +00003945 TemplateArgumentListInfo NewTemplateArgs;
3946 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3947 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00003948
3949 typedef TemplateArgumentLocContainerIterator<
3950 DependentTemplateSpecializationTypeLoc> ArgIterator;
3951 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3952 ArgIterator(TL, TL.getNumArgs()),
3953 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003954 return QualType();
John McCallc392f372010-06-11 00:33:02 +00003955
Douglas Gregora5614c52010-09-08 23:56:00 +00003956 QualType Result
3957 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
3958 NNS,
3959 TL.getQualifierRange(),
3960 T->getIdentifier(),
3961 TL.getNameLoc(),
3962 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00003963 if (Result.isNull())
3964 return QualType();
3965
3966 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3967 QualType NamedT = ElabT->getNamedType();
3968
3969 // Copy information relevant to the template specialization.
3970 TemplateSpecializationTypeLoc NamedTL
3971 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3972 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3973 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3974 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3975 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3976
3977 // Copy information relevant to the elaborated type.
3978 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3979 NewTL.setKeywordLoc(TL.getKeywordLoc());
3980 NewTL.setQualifierRange(TL.getQualifierRange());
3981 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003982 TypeLoc NewTL(Result, TL.getOpaqueData());
3983 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003984 }
3985 return Result;
3986}
3987
3988template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00003989QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
3990 PackExpansionTypeLoc TL) {
Douglas Gregor79aaca42011-01-05 19:06:29 +00003991 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregord2fa7662010-12-20 02:24:11 +00003992 return QualType();
3993}
3994
3995template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003996QualType
3997TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003998 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003999 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004000 TLB.pushFullCopy(TL);
4001 return TL.getType();
4002}
4003
4004template<typename Derived>
4005QualType
4006TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004007 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004008 // ObjCObjectType is never dependent.
4009 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004010 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004011}
Mike Stump11289f42009-09-09 15:08:12 +00004012
4013template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004014QualType
4015TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004017 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004018 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004019 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004020}
4021
Douglas Gregord6ff3322009-08-04 16:50:30 +00004022//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004023// Statement transformation
4024//===----------------------------------------------------------------------===//
4025template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004026StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004027TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004028 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004029}
4030
4031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004032StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004033TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4034 return getDerived().TransformCompoundStmt(S, false);
4035}
4036
4037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004039TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004040 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004041 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004042 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004043 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004044 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4045 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004046 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004047 if (Result.isInvalid()) {
4048 // Immediately fail if this was a DeclStmt, since it's very
4049 // likely that this will cause problems for future statements.
4050 if (isa<DeclStmt>(*B))
4051 return StmtError();
4052
4053 // Otherwise, just keep processing substatements and fail later.
4054 SubStmtInvalid = true;
4055 continue;
4056 }
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregorebe10102009-08-20 07:17:43 +00004058 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4059 Statements.push_back(Result.takeAs<Stmt>());
4060 }
Mike Stump11289f42009-09-09 15:08:12 +00004061
John McCall1ababa62010-08-27 19:56:05 +00004062 if (SubStmtInvalid)
4063 return StmtError();
4064
Douglas Gregorebe10102009-08-20 07:17:43 +00004065 if (!getDerived().AlwaysRebuild() &&
4066 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004067 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004068
4069 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4070 move_arg(Statements),
4071 S->getRBracLoc(),
4072 IsStmtExpr);
4073}
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregorebe10102009-08-20 07:17:43 +00004075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004076StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004077TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004078 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004079 {
4080 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004081 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004082
Eli Friedman06577382009-11-19 03:14:00 +00004083 // Transform the left-hand case value.
4084 LHS = getDerived().TransformExpr(S->getLHS());
4085 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004086 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004087
Eli Friedman06577382009-11-19 03:14:00 +00004088 // Transform the right-hand case value (for the GNU case-range extension).
4089 RHS = getDerived().TransformExpr(S->getRHS());
4090 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004091 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004092 }
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregorebe10102009-08-20 07:17:43 +00004094 // Build the case statement.
4095 // Case statements are always rebuilt so that they will attached to their
4096 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004097 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004098 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004099 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004100 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004101 S->getColonLoc());
4102 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004103 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregorebe10102009-08-20 07:17:43 +00004105 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004106 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004107 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004108 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004109
Douglas Gregorebe10102009-08-20 07:17:43 +00004110 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004111 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004112}
4113
4114template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004115StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004116TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004117 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004118 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004119 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004120 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregorebe10102009-08-20 07:17:43 +00004122 // Default statements are always rebuilt
4123 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004124 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004125}
Mike Stump11289f42009-09-09 15:08:12 +00004126
Douglas Gregorebe10102009-08-20 07:17:43 +00004127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004128StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004129TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004130 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004131 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004132 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregorebe10102009-08-20 07:17:43 +00004134 // FIXME: Pass the real colon location in.
4135 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4136 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004137 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004138}
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregorebe10102009-08-20 07:17:43 +00004140template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004141StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004142TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004143 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004144 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004145 VarDecl *ConditionVar = 0;
4146 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004147 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004148 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004149 getDerived().TransformDefinition(
4150 S->getConditionVariable()->getLocation(),
4151 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004152 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004153 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004154 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004155 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004156
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004157 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004158 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004159
4160 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004161 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004162 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4163 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004164 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004165 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004166
John McCallb268a282010-08-23 23:25:46 +00004167 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004168 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004169 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004170
John McCallb268a282010-08-23 23:25:46 +00004171 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4172 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004173 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004174
Douglas Gregorebe10102009-08-20 07:17:43 +00004175 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004176 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004177 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004178 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregorebe10102009-08-20 07:17:43 +00004180 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004181 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004182 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004183 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregorebe10102009-08-20 07:17:43 +00004185 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004186 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004187 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004188 Then.get() == S->getThen() &&
4189 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004190 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004192 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004193 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004194 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004195}
4196
4197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004198StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004199TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004200 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004201 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004202 VarDecl *ConditionVar = 0;
4203 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004204 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004205 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004206 getDerived().TransformDefinition(
4207 S->getConditionVariable()->getLocation(),
4208 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004209 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004210 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004211 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004212 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004213
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004214 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004215 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004216 }
Mike Stump11289f42009-09-09 15:08:12 +00004217
Douglas Gregorebe10102009-08-20 07:17:43 +00004218 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004219 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004220 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004221 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004222 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004223 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregorebe10102009-08-20 07:17:43 +00004225 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004226 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004227 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004228 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregorebe10102009-08-20 07:17:43 +00004230 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004231 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4232 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004233}
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregorebe10102009-08-20 07:17:43 +00004235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004236StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004237TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004238 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004239 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004240 VarDecl *ConditionVar = 0;
4241 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004242 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004243 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004244 getDerived().TransformDefinition(
4245 S->getConditionVariable()->getLocation(),
4246 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004247 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004248 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004249 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004250 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004251
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004252 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004253 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004254
4255 if (S->getCond()) {
4256 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004257 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4258 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004259 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004260 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004261 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004262 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004263 }
Mike Stump11289f42009-09-09 15:08:12 +00004264
John McCallb268a282010-08-23 23:25:46 +00004265 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4266 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
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 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004270 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004271 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004272 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004273
Douglas Gregorebe10102009-08-20 07:17:43 +00004274 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004275 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004276 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004277 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004278 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004280 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004281 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004282}
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregorebe10102009-08-20 07:17:43 +00004284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004285StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004286TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004287 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004288 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004289 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004290 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004291
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004292 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004293 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004294 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004295 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004296
Douglas Gregorebe10102009-08-20 07:17:43 +00004297 if (!getDerived().AlwaysRebuild() &&
4298 Cond.get() == S->getCond() &&
4299 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004300 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004301
John McCallb268a282010-08-23 23:25:46 +00004302 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4303 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004304 S->getRParenLoc());
4305}
Mike Stump11289f42009-09-09 15:08:12 +00004306
Douglas Gregorebe10102009-08-20 07:17:43 +00004307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004308StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004309TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004310 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004311 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004312 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004313 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregorebe10102009-08-20 07:17:43 +00004315 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004316 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004317 VarDecl *ConditionVar = 0;
4318 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004319 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004320 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004321 getDerived().TransformDefinition(
4322 S->getConditionVariable()->getLocation(),
4323 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004324 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004325 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004326 } else {
4327 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004328
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004329 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004330 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004331
4332 if (S->getCond()) {
4333 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004334 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4335 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004336 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004337 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004338
John McCallb268a282010-08-23 23:25:46 +00004339 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004340 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004341 }
Mike Stump11289f42009-09-09 15:08:12 +00004342
John McCallb268a282010-08-23 23:25:46 +00004343 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4344 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004345 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004346
Douglas Gregorebe10102009-08-20 07:17:43 +00004347 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004348 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004349 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004350 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004351
John McCallb268a282010-08-23 23:25:46 +00004352 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4353 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004354 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004355
Douglas Gregorebe10102009-08-20 07:17:43 +00004356 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004357 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004358 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004359 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregorebe10102009-08-20 07:17:43 +00004361 if (!getDerived().AlwaysRebuild() &&
4362 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004363 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004364 Inc.get() == S->getInc() &&
4365 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004366 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004367
Douglas Gregorebe10102009-08-20 07:17:43 +00004368 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004369 Init.get(), FullCond, ConditionVar,
4370 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004371}
4372
4373template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004374StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004375TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004376 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004377 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004378 S->getLabel());
4379}
4380
4381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004382StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004383TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004384 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004385 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004386 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregorebe10102009-08-20 07:17:43 +00004388 if (!getDerived().AlwaysRebuild() &&
4389 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004390 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004391
4392 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004393 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004394}
4395
4396template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004397StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004398TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004399 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004400}
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregorebe10102009-08-20 07:17:43 +00004402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004403StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004404TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004405 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregorebe10102009-08-20 07:17:43 +00004408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004409StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004410TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004411 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004412 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004413 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004414
Mike Stump11289f42009-09-09 15:08:12 +00004415 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004416 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004417 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregorebe10102009-08-20 07:17:43 +00004420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004421StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004422TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004423 bool DeclChanged = false;
4424 llvm::SmallVector<Decl *, 4> Decls;
4425 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4426 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004427 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4428 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004429 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004430 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregorebe10102009-08-20 07:17:43 +00004432 if (Transformed != *D)
4433 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004434
Douglas Gregorebe10102009-08-20 07:17:43 +00004435 Decls.push_back(Transformed);
4436 }
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregorebe10102009-08-20 07:17:43 +00004438 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004439 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004440
4441 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004442 S->getStartLoc(), S->getEndLoc());
4443}
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregorebe10102009-08-20 07:17:43 +00004445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004446StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004447TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004448 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004449 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004450}
4451
4452template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004453StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004454TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004455
John McCall37ad5512010-08-23 06:44:23 +00004456 ASTOwningVector<Expr*> Constraints(getSema());
4457 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004458 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004459
John McCalldadc5752010-08-24 06:29:42 +00004460 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004461 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004462
4463 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004464
Anders Carlssonaaeef072010-01-24 05:50:09 +00004465 // Go through the outputs.
4466 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004467 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004468
Anders Carlssonaaeef072010-01-24 05:50:09 +00004469 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004470 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004471
Anders Carlssonaaeef072010-01-24 05:50:09 +00004472 // Transform the output expr.
4473 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004474 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004475 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004476 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004477
Anders Carlssonaaeef072010-01-24 05:50:09 +00004478 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004479
John McCallb268a282010-08-23 23:25:46 +00004480 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004482
Anders Carlssonaaeef072010-01-24 05:50:09 +00004483 // Go through the inputs.
4484 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004485 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004486
Anders Carlssonaaeef072010-01-24 05:50:09 +00004487 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004488 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004489
Anders Carlssonaaeef072010-01-24 05:50:09 +00004490 // Transform the input expr.
4491 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004492 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004493 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004494 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004495
Anders Carlssonaaeef072010-01-24 05:50:09 +00004496 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004497
John McCallb268a282010-08-23 23:25:46 +00004498 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004499 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004500
Anders Carlssonaaeef072010-01-24 05:50:09 +00004501 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004502 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004503
4504 // Go through the clobbers.
4505 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004506 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004507
4508 // No need to transform the asm string literal.
4509 AsmString = SemaRef.Owned(S->getAsmString());
4510
4511 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4512 S->isSimple(),
4513 S->isVolatile(),
4514 S->getNumOutputs(),
4515 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004516 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004517 move_arg(Constraints),
4518 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004519 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004520 move_arg(Clobbers),
4521 S->getRParenLoc(),
4522 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004523}
4524
4525
4526template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004527StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004528TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004529 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004530 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004531 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004532 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004533
Douglas Gregor96c79492010-04-23 22:50:49 +00004534 // Transform the @catch statements (if present).
4535 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004536 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004537 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004538 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004539 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004540 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004541 if (Catch.get() != S->getCatchStmt(I))
4542 AnyCatchChanged = true;
4543 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004544 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004545
Douglas Gregor306de2f2010-04-22 23:59:56 +00004546 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004547 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004548 if (S->getFinallyStmt()) {
4549 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4550 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004551 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004552 }
4553
4554 // If nothing changed, just retain this statement.
4555 if (!getDerived().AlwaysRebuild() &&
4556 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004557 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004558 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004559 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004560
Douglas Gregor306de2f2010-04-22 23:59:56 +00004561 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004562 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4563 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004564}
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregorebe10102009-08-20 07:17:43 +00004566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004567StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004568TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004569 // Transform the @catch parameter, if there is one.
4570 VarDecl *Var = 0;
4571 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4572 TypeSourceInfo *TSInfo = 0;
4573 if (FromVar->getTypeSourceInfo()) {
4574 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4575 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004576 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004577 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004578
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004579 QualType T;
4580 if (TSInfo)
4581 T = TSInfo->getType();
4582 else {
4583 T = getDerived().TransformType(FromVar->getType());
4584 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004585 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004586 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004587
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004588 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4589 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004590 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004591 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004592
John McCalldadc5752010-08-24 06:29:42 +00004593 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004594 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004595 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004596
4597 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004598 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004599 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregorebe10102009-08-20 07:17:43 +00004602template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004603StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004604TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004605 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004606 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004607 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004608 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004609
Douglas Gregor306de2f2010-04-22 23:59:56 +00004610 // If nothing changed, just retain this statement.
4611 if (!getDerived().AlwaysRebuild() &&
4612 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004613 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004614
4615 // Build a new statement.
4616 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004617 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregorebe10102009-08-20 07:17:43 +00004620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004621StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004622TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004623 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004624 if (S->getThrowExpr()) {
4625 Operand = getDerived().TransformExpr(S->getThrowExpr());
4626 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004627 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004628 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004629
Douglas Gregor2900c162010-04-22 21:44:01 +00004630 if (!getDerived().AlwaysRebuild() &&
4631 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004632 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004633
John McCallb268a282010-08-23 23:25:46 +00004634 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004635}
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregorebe10102009-08-20 07:17:43 +00004637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004638StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004639TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004640 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004641 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004642 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004643 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004644 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004645
Douglas Gregor6148de72010-04-22 22:01:21 +00004646 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004647 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004648 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004649 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004650
Douglas Gregor6148de72010-04-22 22:01:21 +00004651 // If nothing change, just retain the current statement.
4652 if (!getDerived().AlwaysRebuild() &&
4653 Object.get() == S->getSynchExpr() &&
4654 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004655 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004656
4657 // Build a new statement.
4658 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004659 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004660}
4661
4662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004663StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004664TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004665 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004666 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004667 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004668 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004669 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004670
Douglas Gregorf68a5082010-04-22 23:10:45 +00004671 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004672 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004673 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004674 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004675
Douglas Gregorf68a5082010-04-22 23:10:45 +00004676 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004677 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004678 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004679 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004680
Douglas Gregorf68a5082010-04-22 23:10:45 +00004681 // If nothing changed, just retain this statement.
4682 if (!getDerived().AlwaysRebuild() &&
4683 Element.get() == S->getElement() &&
4684 Collection.get() == S->getCollection() &&
4685 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004686 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004687
Douglas Gregorf68a5082010-04-22 23:10:45 +00004688 // Build a new statement.
4689 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4690 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004691 Element.get(),
4692 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004693 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004694 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004695}
4696
4697
4698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004699StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004700TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4701 // Transform the exception declaration, if any.
4702 VarDecl *Var = 0;
4703 if (S->getExceptionDecl()) {
4704 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004705 TypeSourceInfo *T = getDerived().TransformType(
4706 ExceptionDecl->getTypeSourceInfo());
4707 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004708 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004710 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004712 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004713 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004714 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004715 }
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregorebe10102009-08-20 07:17:43 +00004717 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004718 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004719 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 if (!getDerived().AlwaysRebuild() &&
4723 !Var &&
4724 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004725 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004726
4727 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4728 Var,
John McCallb268a282010-08-23 23:25:46 +00004729 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004730}
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregorebe10102009-08-20 07:17:43 +00004732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004733StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004734TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4735 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00004736 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004737 = getDerived().TransformCompoundStmt(S->getTryBlock());
4738 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004739 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregorebe10102009-08-20 07:17:43 +00004741 // Transform the handlers.
4742 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004743 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00004744 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004745 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004746 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4747 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004748 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004749
Douglas Gregorebe10102009-08-20 07:17:43 +00004750 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4751 Handlers.push_back(Handler.takeAs<Stmt>());
4752 }
Mike Stump11289f42009-09-09 15:08:12 +00004753
Douglas Gregorebe10102009-08-20 07:17:43 +00004754 if (!getDerived().AlwaysRebuild() &&
4755 TryBlock.get() == S->getTryBlock() &&
4756 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00004757 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004758
John McCallb268a282010-08-23 23:25:46 +00004759 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00004760 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004761}
Mike Stump11289f42009-09-09 15:08:12 +00004762
Douglas Gregorebe10102009-08-20 07:17:43 +00004763//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004764// Expression transformation
4765//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004766template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004767ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004768TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00004769 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
4772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004774TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004775 NestedNameSpecifier *Qualifier = 0;
4776 if (E->getQualifier()) {
4777 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004778 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004779 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00004780 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004781 }
John McCallce546572009-12-08 09:08:17 +00004782
4783 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004784 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4785 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00004787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
John McCall815039a2010-08-17 21:27:17 +00004789 DeclarationNameInfo NameInfo = E->getNameInfo();
4790 if (NameInfo.getName()) {
4791 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
4792 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00004793 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00004794 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004795
4796 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004797 Qualifier == E->getQualifier() &&
4798 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004799 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00004800 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004801
4802 // Mark it referenced in the new context regardless.
4803 // FIXME: this is a bit instantiation-specific.
4804 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4805
John McCallc3007a22010-10-26 07:05:15 +00004806 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004807 }
John McCallce546572009-12-08 09:08:17 +00004808
4809 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00004810 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00004811 TemplateArgs = &TransArgs;
4812 TransArgs.setLAngleLoc(E->getLAngleLoc());
4813 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00004814 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
4815 E->getNumTemplateArgs(),
4816 TransArgs))
4817 return ExprError();
John McCallce546572009-12-08 09:08:17 +00004818 }
4819
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004820 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00004821 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004822}
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004825ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004826TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004827 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004828}
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004831ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004832TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004833 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004834}
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregora16548e2009-08-11 05:31:07 +00004836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004837ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004838TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004839 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004840}
Mike Stump11289f42009-09-09 15:08:12 +00004841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004843ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004844TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004845 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004846}
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregora16548e2009-08-11 05:31:07 +00004848template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004849ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004850TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00004851 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004852}
4853
4854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004856TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004857 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004858 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004859 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004862 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004863
John McCallb268a282010-08-23 23:25:46 +00004864 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 E->getRParen());
4866}
4867
Mike Stump11289f42009-09-09 15:08:12 +00004868template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004869ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004870TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00004871 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00004876 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregora16548e2009-08-11 05:31:07 +00004878 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4879 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00004880 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00004881}
Mike Stump11289f42009-09-09 15:08:12 +00004882
Douglas Gregora16548e2009-08-11 05:31:07 +00004883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004884ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004885TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4886 // Transform the type.
4887 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4888 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00004889 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004890
Douglas Gregor882211c2010-04-28 22:16:22 +00004891 // Transform all of the components into components similar to what the
4892 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004893 // FIXME: It would be slightly more efficient in the non-dependent case to
4894 // just map FieldDecls, rather than requiring the rebuilder to look for
4895 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004896 // template code that we don't care.
4897 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00004898 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00004899 typedef OffsetOfExpr::OffsetOfNode Node;
4900 llvm::SmallVector<Component, 4> Components;
4901 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4902 const Node &ON = E->getComponent(I);
4903 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004904 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004905 Comp.LocStart = ON.getRange().getBegin();
4906 Comp.LocEnd = ON.getRange().getEnd();
4907 switch (ON.getKind()) {
4908 case Node::Array: {
4909 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00004910 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00004911 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004912 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004913
Douglas Gregor882211c2010-04-28 22:16:22 +00004914 ExprChanged = ExprChanged || Index.get() != FromIndex;
4915 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00004916 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00004917 break;
4918 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004919
Douglas Gregor882211c2010-04-28 22:16:22 +00004920 case Node::Field:
4921 case Node::Identifier:
4922 Comp.isBrackets = false;
4923 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004924 if (!Comp.U.IdentInfo)
4925 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004926
Douglas Gregor882211c2010-04-28 22:16:22 +00004927 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004928
Douglas Gregord1702062010-04-29 00:18:15 +00004929 case Node::Base:
4930 // Will be recomputed during the rebuild.
4931 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004932 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004933
Douglas Gregor882211c2010-04-28 22:16:22 +00004934 Components.push_back(Comp);
4935 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004936
Douglas Gregor882211c2010-04-28 22:16:22 +00004937 // If nothing changed, retain the existing expression.
4938 if (!getDerived().AlwaysRebuild() &&
4939 Type == E->getTypeSourceInfo() &&
4940 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00004941 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004942
Douglas Gregor882211c2010-04-28 22:16:22 +00004943 // Build a new offsetof expression.
4944 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4945 Components.data(), Components.size(),
4946 E->getRParenLoc());
4947}
4948
4949template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004950ExprResult
John McCall8d69a212010-11-15 23:31:06 +00004951TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
4952 assert(getDerived().AlreadyTransformed(E->getType()) &&
4953 "opaque value expression requires transformation");
4954 return SemaRef.Owned(E);
4955}
4956
4957template<typename Derived>
4958ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004959TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004960 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004961 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004962
John McCallbcd03502009-12-07 02:54:59 +00004963 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004964 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00004965 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004966
John McCall4c98fd82009-11-04 07:28:41 +00004967 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00004968 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00004969
John McCall4c98fd82009-11-04 07:28:41 +00004970 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004971 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 E->getSourceRange());
4973 }
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCalldadc5752010-08-24 06:29:42 +00004975 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00004976 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 // C++0x [expr.sizeof]p1:
4978 // The operand is either an expression, which is an unevaluated operand
4979 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00004980 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4983 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004984 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00004987 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004988 }
Mike Stump11289f42009-09-09 15:08:12 +00004989
John McCallb268a282010-08-23 23:25:46 +00004990 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004991 E->isSizeOf(),
4992 E->getSourceRange());
4993}
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregora16548e2009-08-11 05:31:07 +00004995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004996ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004997TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00004998 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005000 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005001
John McCalldadc5752010-08-24 06:29:42 +00005002 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005004 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005005
5006
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 if (!getDerived().AlwaysRebuild() &&
5008 LHS.get() == E->getLHS() &&
5009 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005010 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCallb268a282010-08-23 23:25:46 +00005012 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005014 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 E->getRBracketLoc());
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>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005022 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005024 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005025
5026 // Transform arguments.
5027 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005028 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005029 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5030 &ArgChanged))
5031 return ExprError();
5032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033 if (!getDerived().AlwaysRebuild() &&
5034 Callee.get() == E->getCallee() &&
5035 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005036 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregora16548e2009-08-11 05:31:07 +00005038 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005039 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005041 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 E->getRParenLoc());
5044}
Mike Stump11289f42009-09-09 15:08:12 +00005045
5046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005047ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005048TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005049 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005052
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005053 NestedNameSpecifier *Qualifier = 0;
5054 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005055 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005056 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005057 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005058 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005059 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005060 }
Mike Stump11289f42009-09-09 15:08:12 +00005061
Eli Friedman2cfcef62009-12-04 06:40:45 +00005062 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005063 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5064 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005065 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005066 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005067
John McCall16df1e52010-03-30 21:47:33 +00005068 NamedDecl *FoundDecl = E->getFoundDecl();
5069 if (FoundDecl == E->getMemberDecl()) {
5070 FoundDecl = Member;
5071 } else {
5072 FoundDecl = cast_or_null<NamedDecl>(
5073 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5074 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005075 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005076 }
5077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 if (!getDerived().AlwaysRebuild() &&
5079 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005080 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005081 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005082 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005083 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005084
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005085 // Mark it referenced in the new context regardless.
5086 // FIXME: this is a bit instantiation-specific.
5087 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005088 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005089 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005090
John McCall6b51f282009-11-23 01:53:49 +00005091 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005092 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005093 TransArgs.setLAngleLoc(E->getLAngleLoc());
5094 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005095 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5096 E->getNumTemplateArgs(),
5097 TransArgs))
5098 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005099 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101 // FIXME: Bogus source location for the operator
5102 SourceLocation FakeOperatorLoc
5103 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5104
John McCall38836f02010-01-15 08:34:02 +00005105 // FIXME: to do this check properly, we will need to preserve the
5106 // first-qualifier-in-scope here, just in case we had a dependent
5107 // base (and therefore couldn't do the check) and a
5108 // nested-name-qualifier (and therefore could do the lookup).
5109 NamedDecl *FirstQualifierInScope = 0;
5110
John McCallb268a282010-08-23 23:25:46 +00005111 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005113 Qualifier,
5114 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005115 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005116 Member,
John McCall16df1e52010-03-30 21:47:33 +00005117 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005118 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005119 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005120 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005121}
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005124ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005126 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005127 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005128 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005129
John McCalldadc5752010-08-24 06:29:42 +00005130 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005133
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 if (!getDerived().AlwaysRebuild() &&
5135 LHS.get() == E->getLHS() &&
5136 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005137 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005140 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005141}
5142
Mike Stump11289f42009-09-09 15:08:12 +00005143template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005144ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005145TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005146 CompoundAssignOperator *E) {
5147 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005148}
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregora16548e2009-08-11 05:31:07 +00005150template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005151ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005152TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005153 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005155 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005156
John McCalldadc5752010-08-24 06:29:42 +00005157 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005159 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005160
John McCalldadc5752010-08-24 06:29:42 +00005161 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005163 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005164
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 if (!getDerived().AlwaysRebuild() &&
5166 Cond.get() == E->getCond() &&
5167 LHS.get() == E->getLHS() &&
5168 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005169 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005170
John McCallb268a282010-08-23 23:25:46 +00005171 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005172 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005173 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005174 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005175 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
5178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005180TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005181 // Implicit casts are eliminated during transformation, since they
5182 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005183 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005184}
Mike Stump11289f42009-09-09 15:08:12 +00005185
Douglas Gregora16548e2009-08-11 05:31:07 +00005186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005188TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005189 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5190 if (!Type)
5191 return ExprError();
5192
John McCalldadc5752010-08-24 06:29:42 +00005193 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005194 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005199 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005201 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005202
John McCall97513962010-01-15 18:39:57 +00005203 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005204 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005205 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005206 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005207}
Mike Stump11289f42009-09-09 15:08:12 +00005208
Douglas Gregora16548e2009-08-11 05:31:07 +00005209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005212 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5213 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5214 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
John McCalldadc5752010-08-24 06:29:42 +00005217 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005219 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregora16548e2009-08-11 05:31:07 +00005221 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005222 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005223 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005224 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005225
John McCall5d7aa7f2010-01-19 22:33:45 +00005226 // Note: the expression type doesn't necessarily match the
5227 // type-as-written, but that's okay, because it should always be
5228 // derivable from the initializer.
5229
John McCalle15bbff2010-01-18 19:35:47 +00005230 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005231 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005232 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005233}
Mike Stump11289f42009-09-09 15:08:12 +00005234
Douglas Gregora16548e2009-08-11 05:31:07 +00005235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005238 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005239 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 if (!getDerived().AlwaysRebuild() &&
5243 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005244 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005247 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005249 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 E->getAccessorLoc(),
5251 E->getAccessor());
5252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregora16548e2009-08-11 05:31:07 +00005254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005258
John McCall37ad5512010-08-23 06:44:23 +00005259 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005260 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5261 Inits, &InitChanged))
5262 return ExprError();
5263
Douglas Gregora16548e2009-08-11 05:31:07 +00005264 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005265 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005266
Douglas Gregora16548e2009-08-11 05:31:07 +00005267 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005268 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005269}
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregora16548e2009-08-11 05:31:07 +00005271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005273TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregorebe10102009-08-20 07:17:43 +00005276 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005277 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005280
Douglas Gregorebe10102009-08-20 07:17:43 +00005281 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005282 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005283 bool ExprChanged = false;
5284 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5285 DEnd = E->designators_end();
5286 D != DEnd; ++D) {
5287 if (D->isFieldDesignator()) {
5288 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5289 D->getDotLoc(),
5290 D->getFieldLoc()));
5291 continue;
5292 }
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005295 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005296 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005298
5299 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005300 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005301
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5303 ArrayExprs.push_back(Index.release());
5304 continue;
5305 }
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregora16548e2009-08-11 05:31:07 +00005307 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005308 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005309 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5310 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005312
John McCalldadc5752010-08-24 06:29:42 +00005313 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005314 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005316
5317 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005318 End.get(),
5319 D->getLBracketLoc(),
5320 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregora16548e2009-08-11 05:31:07 +00005322 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5323 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005324
Douglas Gregora16548e2009-08-11 05:31:07 +00005325 ArrayExprs.push_back(Start.release());
5326 ArrayExprs.push_back(End.release());
5327 }
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregora16548e2009-08-11 05:31:07 +00005329 if (!getDerived().AlwaysRebuild() &&
5330 Init.get() == E->getInit() &&
5331 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005332 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregora16548e2009-08-11 05:31:07 +00005334 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5335 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005336 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005337}
Mike Stump11289f42009-09-09 15:08:12 +00005338
Douglas Gregora16548e2009-08-11 05:31:07 +00005339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005340ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005341TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005342 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005343 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005344
Douglas Gregor3da3c062009-10-28 00:29:27 +00005345 // FIXME: Will we ever have proper type location here? Will we actually
5346 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005347 QualType T = getDerived().TransformType(E->getType());
5348 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005349 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005350
Douglas Gregora16548e2009-08-11 05:31:07 +00005351 if (!getDerived().AlwaysRebuild() &&
5352 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005353 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355 return getDerived().RebuildImplicitValueInitExpr(T);
5356}
Mike Stump11289f42009-09-09 15:08:12 +00005357
Douglas Gregora16548e2009-08-11 05:31:07 +00005358template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005359ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005360TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005361 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5362 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005363 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005364
John McCalldadc5752010-08-24 06:29:42 +00005365 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005370 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005372 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005373
John McCallb268a282010-08-23 23:25:46 +00005374 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005375 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005376}
5377
5378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005379ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005380TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005381 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005382 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005383 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5384 &ArgumentChanged))
5385 return ExprError();
5386
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5388 move_arg(Inits),
5389 E->getRParenLoc());
5390}
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregora16548e2009-08-11 05:31:07 +00005392/// \brief Transform an address-of-label expression.
5393///
5394/// By default, the transformation of an address-of-label expression always
5395/// rebuilds the expression, so that the label identifier can be resolved to
5396/// the corresponding label statement by semantic analysis.
5397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005398ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005399TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005400 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5401 E->getLabel());
5402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
5404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005405ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005406TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005407 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5409 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005411
Douglas Gregora16548e2009-08-11 05:31:07 +00005412 if (!getDerived().AlwaysRebuild() &&
5413 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005414 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005415
5416 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005417 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005418 E->getRParenLoc());
5419}
Mike Stump11289f42009-09-09 15:08:12 +00005420
Douglas Gregora16548e2009-08-11 05:31:07 +00005421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005422ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005423TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005424 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005425 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005427
John McCalldadc5752010-08-24 06:29:42 +00005428 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005429 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005430 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005431
John McCalldadc5752010-08-24 06:29:42 +00005432 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005433 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregora16548e2009-08-11 05:31:07 +00005436 if (!getDerived().AlwaysRebuild() &&
5437 Cond.get() == E->getCond() &&
5438 LHS.get() == E->getLHS() &&
5439 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005440 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregora16548e2009-08-11 05:31:07 +00005442 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005443 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 E->getRParenLoc());
5445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005448ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005449TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005450 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005451}
5452
5453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005454ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005455TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005456 switch (E->getOperator()) {
5457 case OO_New:
5458 case OO_Delete:
5459 case OO_Array_New:
5460 case OO_Array_Delete:
5461 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005462 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005463
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005464 case OO_Call: {
5465 // This is a call to an object's operator().
5466 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5467
5468 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005469 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005470 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005471 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005472
5473 // FIXME: Poor location information
5474 SourceLocation FakeLParenLoc
5475 = SemaRef.PP.getLocForEndOfToken(
5476 static_cast<Expr *>(Object.get())->getLocEnd());
5477
5478 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005479 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005480 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5481 Args))
5482 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005483
John McCallb268a282010-08-23 23:25:46 +00005484 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005485 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005486 E->getLocEnd());
5487 }
5488
5489#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5490 case OO_##Name:
5491#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5492#include "clang/Basic/OperatorKinds.def"
5493 case OO_Subscript:
5494 // Handled below.
5495 break;
5496
5497 case OO_Conditional:
5498 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005499 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005500
5501 case OO_None:
5502 case NUM_OVERLOADED_OPERATORS:
5503 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005504 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005505 }
5506
John McCalldadc5752010-08-24 06:29:42 +00005507 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005508 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005509 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005510
John McCalldadc5752010-08-24 06:29:42 +00005511 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005513 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005514
John McCalldadc5752010-08-24 06:29:42 +00005515 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 if (E->getNumArgs() == 2) {
5517 Second = getDerived().TransformExpr(E->getArg(1));
5518 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005519 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 }
Mike Stump11289f42009-09-09 15:08:12 +00005521
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 if (!getDerived().AlwaysRebuild() &&
5523 Callee.get() == E->getCallee() &&
5524 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005525 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005526 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005527
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5529 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005530 Callee.get(),
5531 First.get(),
5532 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005533}
Mike Stump11289f42009-09-09 15:08:12 +00005534
Douglas Gregora16548e2009-08-11 05:31:07 +00005535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005537TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5538 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005539}
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005544 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5545 if (!Type)
5546 return ExprError();
5547
John McCalldadc5752010-08-24 06:29:42 +00005548 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005549 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005551 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005552
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005554 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005556 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005559 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5561 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5562 SourceLocation FakeRParenLoc
5563 = SemaRef.PP.getLocForEndOfToken(
5564 E->getSubExpr()->getSourceRange().getEnd());
5565 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005566 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005567 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005568 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005569 FakeRAngleLoc,
5570 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005571 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 FakeRParenLoc);
5573}
Mike Stump11289f42009-09-09 15:08:12 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005577TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5578 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005579}
Mike Stump11289f42009-09-09 15:08:12 +00005580
5581template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005582ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005583TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5584 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005585}
5586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005588ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005589TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005590 CXXReinterpretCastExpr *E) {
5591 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005592}
Mike Stump11289f42009-09-09 15:08:12 +00005593
Douglas Gregora16548e2009-08-11 05:31:07 +00005594template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005595ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005596TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5597 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005598}
Mike Stump11289f42009-09-09 15:08:12 +00005599
Douglas Gregora16548e2009-08-11 05:31:07 +00005600template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005601ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005602TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005603 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005604 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5605 if (!Type)
5606 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCalldadc5752010-08-24 06:29:42 +00005608 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005609 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005610 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005611 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005612
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005614 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005616 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005618 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005620 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 E->getRParenLoc());
5622}
Mike Stump11289f42009-09-09 15:08:12 +00005623
Douglas Gregora16548e2009-08-11 05:31:07 +00005624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005625ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005626TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005628 TypeSourceInfo *TInfo
5629 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5630 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005631 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregora16548e2009-08-11 05:31:07 +00005633 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005634 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005635 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005636
Douglas Gregor9da64192010-04-26 22:37:10 +00005637 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5638 E->getLocStart(),
5639 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 E->getLocEnd());
5641 }
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 // We don't know whether the expression is potentially evaluated until
5644 // after we perform semantic analysis, so the expression is potentially
5645 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005646 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005647 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005648
John McCalldadc5752010-08-24 06:29:42 +00005649 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005651 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005652
Douglas Gregora16548e2009-08-11 05:31:07 +00005653 if (!getDerived().AlwaysRebuild() &&
5654 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005655 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005656
Douglas Gregor9da64192010-04-26 22:37:10 +00005657 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5658 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005659 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 E->getLocEnd());
5661}
5662
5663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005664ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005665TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5666 if (E->isTypeOperand()) {
5667 TypeSourceInfo *TInfo
5668 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5669 if (!TInfo)
5670 return ExprError();
5671
5672 if (!getDerived().AlwaysRebuild() &&
5673 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005674 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005675
5676 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5677 E->getLocStart(),
5678 TInfo,
5679 E->getLocEnd());
5680 }
5681
5682 // We don't know whether the expression is potentially evaluated until
5683 // after we perform semantic analysis, so the expression is potentially
5684 // potentially evaluated.
5685 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5686
5687 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5688 if (SubExpr.isInvalid())
5689 return ExprError();
5690
5691 if (!getDerived().AlwaysRebuild() &&
5692 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005693 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005694
5695 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5696 E->getLocStart(),
5697 SubExpr.get(),
5698 E->getLocEnd());
5699}
5700
5701template<typename Derived>
5702ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005703TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005704 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005705}
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005708ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005709TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005710 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005711 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005712}
Mike Stump11289f42009-09-09 15:08:12 +00005713
Douglas Gregora16548e2009-08-11 05:31:07 +00005714template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005715ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005716TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005717 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5718 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5719 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005721 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005722 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregorb15af892010-01-07 23:12:05 +00005724 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005725}
Mike Stump11289f42009-09-09 15:08:12 +00005726
Douglas Gregora16548e2009-08-11 05:31:07 +00005727template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005728ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005729TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005730 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005731 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 if (!getDerived().AlwaysRebuild() &&
5735 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005736 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005737
John McCallb268a282010-08-23 23:25:46 +00005738 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005739}
Mike Stump11289f42009-09-09 15:08:12 +00005740
Douglas Gregora16548e2009-08-11 05:31:07 +00005741template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005742ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005743TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005744 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005745 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5746 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00005748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005749
Chandler Carruth794da4c2010-02-08 06:42:49 +00005750 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00005752 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005753
Douglas Gregor033f6752009-12-23 23:03:06 +00005754 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005755}
Mike Stump11289f42009-09-09 15:08:12 +00005756
Douglas Gregora16548e2009-08-11 05:31:07 +00005757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005758ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00005759TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5760 CXXScalarValueInitExpr *E) {
5761 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5762 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005763 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00005764
Douglas Gregora16548e2009-08-11 05:31:07 +00005765 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00005766 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005767 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005768
Douglas Gregor2b88c112010-09-08 00:15:04 +00005769 return getDerived().RebuildCXXScalarValueInitExpr(T,
5770 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00005771 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005775ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005776TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005777 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00005778 TypeSourceInfo *AllocTypeInfo
5779 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
5780 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00005784 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00005785 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005786 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005787
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 // Transform the placement arguments (if any).
5789 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005790 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005791 if (getDerived().TransformExprs(E->getPlacementArgs(),
5792 E->getNumPlacementArgs(), true,
5793 PlacementArgs, &ArgumentChanged))
5794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005795
Douglas Gregorebe10102009-08-20 07:17:43 +00005796 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00005797 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005798 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
5799 ConstructorArgs, &ArgumentChanged))
5800 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005801
Douglas Gregord2d9da02010-02-26 00:38:10 +00005802 // Transform constructor, new operator, and delete operator.
5803 CXXConstructorDecl *Constructor = 0;
5804 if (E->getConstructor()) {
5805 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005806 getDerived().TransformDecl(E->getLocStart(),
5807 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005808 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00005809 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005810 }
5811
5812 FunctionDecl *OperatorNew = 0;
5813 if (E->getOperatorNew()) {
5814 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005815 getDerived().TransformDecl(E->getLocStart(),
5816 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005817 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00005818 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005819 }
5820
5821 FunctionDecl *OperatorDelete = 0;
5822 if (E->getOperatorDelete()) {
5823 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005824 getDerived().TransformDecl(E->getLocStart(),
5825 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005826 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005827 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005828 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005829
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00005831 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005832 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005833 Constructor == E->getConstructor() &&
5834 OperatorNew == E->getOperatorNew() &&
5835 OperatorDelete == E->getOperatorDelete() &&
5836 !ArgumentChanged) {
5837 // Mark any declarations we need as referenced.
5838 // FIXME: instantiation-specific.
5839 if (Constructor)
5840 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5841 if (OperatorNew)
5842 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5843 if (OperatorDelete)
5844 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00005845 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005846 }
Mike Stump11289f42009-09-09 15:08:12 +00005847
Douglas Gregor0744ef62010-09-07 21:49:58 +00005848 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005849 if (!ArraySize.get()) {
5850 // If no array size was specified, but the new expression was
5851 // instantiated with an array type (e.g., "new T" where T is
5852 // instantiated with "int[4]"), extract the outer bound from the
5853 // array type as our array size. We do this with constant and
5854 // dependently-sized array types.
5855 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5856 if (!ArrayT) {
5857 // Do nothing
5858 } else if (const ConstantArrayType *ConsArrayT
5859 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005860 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00005861 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
5862 ConsArrayT->getSize(),
5863 SemaRef.Context.getSizeType(),
5864 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005865 AllocType = ConsArrayT->getElementType();
5866 } else if (const DependentSizedArrayType *DepArrayT
5867 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5868 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00005869 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005870 AllocType = DepArrayT->getElementType();
5871 }
5872 }
5873 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00005874
Douglas Gregora16548e2009-08-11 05:31:07 +00005875 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5876 E->isGlobalNew(),
5877 /*FIXME:*/E->getLocStart(),
5878 move_arg(PlacementArgs),
5879 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00005880 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005881 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00005882 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00005883 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 /*FIXME:*/E->getLocStart(),
5885 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005886 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005887}
Mike Stump11289f42009-09-09 15:08:12 +00005888
Douglas Gregora16548e2009-08-11 05:31:07 +00005889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005891TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005892 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005895
Douglas Gregord2d9da02010-02-26 00:38:10 +00005896 // Transform the delete operator, if known.
5897 FunctionDecl *OperatorDelete = 0;
5898 if (E->getOperatorDelete()) {
5899 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005900 getDerived().TransformDecl(E->getLocStart(),
5901 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005902 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00005903 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00005904 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005905
Douglas Gregora16548e2009-08-11 05:31:07 +00005906 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005907 Operand.get() == E->getArgument() &&
5908 OperatorDelete == E->getOperatorDelete()) {
5909 // Mark any declarations we need as referenced.
5910 // FIXME: instantiation-specific.
5911 if (OperatorDelete)
5912 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00005913
5914 if (!E->getArgument()->isTypeDependent()) {
5915 QualType Destroyed = SemaRef.Context.getBaseElementType(
5916 E->getDestroyedType());
5917 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
5918 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
5919 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
5920 SemaRef.LookupDestructor(Record));
5921 }
5922 }
5923
John McCallc3007a22010-10-26 07:05:15 +00005924 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00005925 }
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregora16548e2009-08-11 05:31:07 +00005927 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5928 E->isGlobalDelete(),
5929 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00005930 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005931}
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregora16548e2009-08-11 05:31:07 +00005933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005934ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005935TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005936 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005937 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00005938 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005939 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005940
John McCallba7bf592010-08-24 05:47:05 +00005941 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00005942 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00005943 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005944 E->getOperatorLoc(),
5945 E->isArrow()? tok::arrow : tok::period,
5946 ObjectTypePtr,
5947 MayBePseudoDestructor);
5948 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005949 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005950
John McCallba7bf592010-08-24 05:47:05 +00005951 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00005952 NestedNameSpecifier *Qualifier = E->getQualifier();
5953 if (Qualifier) {
5954 Qualifier
5955 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5956 E->getQualifierRange(),
5957 ObjectType);
5958 if (!Qualifier)
5959 return ExprError();
5960 }
Mike Stump11289f42009-09-09 15:08:12 +00005961
Douglas Gregor678f90d2010-02-25 01:56:36 +00005962 PseudoDestructorTypeStorage Destroyed;
5963 if (E->getDestroyedTypeInfo()) {
5964 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00005965 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
5966 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00005967 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005968 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005969 Destroyed = DestroyedTypeInfo;
5970 } else if (ObjectType->isDependentType()) {
5971 // We aren't likely to be able to resolve the identifier down to a type
5972 // now anyway, so just retain the identifier.
5973 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5974 E->getDestroyedTypeLoc());
5975 } else {
5976 // Look for a destructor known with the given name.
5977 CXXScopeSpec SS;
5978 if (Qualifier) {
5979 SS.setScopeRep(Qualifier);
5980 SS.setRange(E->getQualifierRange());
5981 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005982
John McCallba7bf592010-08-24 05:47:05 +00005983 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005984 *E->getDestroyedTypeIdentifier(),
5985 E->getDestroyedTypeLoc(),
5986 /*Scope=*/0,
5987 SS, ObjectTypePtr,
5988 false);
5989 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005990 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005991
Douglas Gregor678f90d2010-02-25 01:56:36 +00005992 Destroyed
5993 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5994 E->getDestroyedTypeLoc());
5995 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005996
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005997 TypeSourceInfo *ScopeTypeInfo = 0;
5998 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00005999 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006000 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006001 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006002 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006003
John McCallb268a282010-08-23 23:25:46 +00006004 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006005 E->getOperatorLoc(),
6006 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006007 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006008 E->getQualifierRange(),
6009 ScopeTypeInfo,
6010 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006011 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006012 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006013}
Mike Stump11289f42009-09-09 15:08:12 +00006014
Douglas Gregorad8a3362009-09-04 17:36:40 +00006015template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006016ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006017TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006018 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006019 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6020
6021 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6022 Sema::LookupOrdinaryName);
6023
6024 // Transform all the decls.
6025 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6026 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006027 NamedDecl *InstD = static_cast<NamedDecl*>(
6028 getDerived().TransformDecl(Old->getNameLoc(),
6029 *I));
John McCall84d87672009-12-10 09:41:52 +00006030 if (!InstD) {
6031 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6032 // This can happen because of dependent hiding.
6033 if (isa<UsingShadowDecl>(*I))
6034 continue;
6035 else
John McCallfaf5fb42010-08-26 23:41:50 +00006036 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006037 }
John McCalle66edc12009-11-24 19:00:30 +00006038
6039 // Expand using declarations.
6040 if (isa<UsingDecl>(InstD)) {
6041 UsingDecl *UD = cast<UsingDecl>(InstD);
6042 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6043 E = UD->shadow_end(); I != E; ++I)
6044 R.addDecl(*I);
6045 continue;
6046 }
6047
6048 R.addDecl(InstD);
6049 }
6050
6051 // Resolve a kind, but don't do any further analysis. If it's
6052 // ambiguous, the callee needs to deal with it.
6053 R.resolveKind();
6054
6055 // Rebuild the nested-name qualifier, if present.
6056 CXXScopeSpec SS;
6057 NestedNameSpecifier *Qualifier = 0;
6058 if (Old->getQualifier()) {
6059 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006060 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006061 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006063
John McCalle66edc12009-11-24 19:00:30 +00006064 SS.setScopeRep(Qualifier);
6065 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006066 }
6067
Douglas Gregor9262f472010-04-27 18:19:34 +00006068 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006069 CXXRecordDecl *NamingClass
6070 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6071 Old->getNameLoc(),
6072 Old->getNamingClass()));
6073 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006074 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
Douglas Gregorda7be082010-04-27 16:10:10 +00006076 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006077 }
6078
6079 // If we have no template arguments, it's a normal declaration name.
6080 if (!Old->hasExplicitTemplateArgs())
6081 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6082
6083 // If we have template arguments, rebuild them, then rebuild the
6084 // templateid expression.
6085 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006086 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6087 Old->getNumTemplateArgs(),
6088 TransArgs))
6089 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006090
6091 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6092 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006093}
Mike Stump11289f42009-09-09 15:08:12 +00006094
Douglas Gregora16548e2009-08-11 05:31:07 +00006095template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006096ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006097TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006098 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6099 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006100 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006101
Douglas Gregora16548e2009-08-11 05:31:07 +00006102 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006103 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006104 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006105
Mike Stump11289f42009-09-09 15:08:12 +00006106 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006107 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 T,
6109 E->getLocEnd());
6110}
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregora16548e2009-08-11 05:31:07 +00006112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006113ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006114TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6115 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6116 if (!LhsT)
6117 return ExprError();
6118
6119 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6120 if (!RhsT)
6121 return ExprError();
6122
6123 if (!getDerived().AlwaysRebuild() &&
6124 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6125 return SemaRef.Owned(E);
6126
6127 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6128 E->getLocStart(),
6129 LhsT, RhsT,
6130 E->getLocEnd());
6131}
6132
6133template<typename Derived>
6134ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006135TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006136 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006138 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006139 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006141 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006142
John McCall31f82722010-11-12 08:19:04 +00006143 // TODO: If this is a conversion-function-id, verify that the
6144 // destination type name (if present) resolves the same way after
6145 // instantiation as it did in the local scope.
6146
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006147 DeclarationNameInfo NameInfo
6148 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6149 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006150 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006151
John McCalle66edc12009-11-24 19:00:30 +00006152 if (!E->hasExplicitTemplateArgs()) {
6153 if (!getDerived().AlwaysRebuild() &&
6154 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006155 // Note: it is sufficient to compare the Name component of NameInfo:
6156 // if name has not changed, DNLoc has not changed either.
6157 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006158 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006159
John McCalle66edc12009-11-24 19:00:30 +00006160 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6161 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006162 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006163 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006164 }
John McCall6b51f282009-11-23 01:53:49 +00006165
6166 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006167 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6168 E->getNumTemplateArgs(),
6169 TransArgs))
6170 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006171
John McCalle66edc12009-11-24 19:00:30 +00006172 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6173 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006174 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006175 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006176}
6177
6178template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006179ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006180TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006181 // CXXConstructExprs are always implicit, so when we have a
6182 // 1-argument construction we just transform that argument.
6183 if (E->getNumArgs() == 1 ||
6184 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6185 return getDerived().TransformExpr(E->getArg(0));
6186
Douglas Gregora16548e2009-08-11 05:31:07 +00006187 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6188
6189 QualType T = getDerived().TransformType(E->getType());
6190 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006192
6193 CXXConstructorDecl *Constructor
6194 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006195 getDerived().TransformDecl(E->getLocStart(),
6196 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006198 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006199
Douglas Gregora16548e2009-08-11 05:31:07 +00006200 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006201 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006202 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6203 &ArgumentChanged))
6204 return ExprError();
6205
Douglas Gregora16548e2009-08-11 05:31:07 +00006206 if (!getDerived().AlwaysRebuild() &&
6207 T == E->getType() &&
6208 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006209 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006210 // Mark the constructor as referenced.
6211 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006212 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006213 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006214 }
Mike Stump11289f42009-09-09 15:08:12 +00006215
Douglas Gregordb121ba2009-12-14 16:27:04 +00006216 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6217 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006218 move_arg(Args),
6219 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006220 E->getConstructionKind(),
6221 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006222}
Mike Stump11289f42009-09-09 15:08:12 +00006223
Douglas Gregora16548e2009-08-11 05:31:07 +00006224/// \brief Transform a C++ temporary-binding expression.
6225///
Douglas Gregor363b1512009-12-24 18:51:59 +00006226/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6227/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006229ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006230TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006231 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
John McCall5d413782010-12-06 08:20:24 +00006234/// \brief Transform a C++ expression that contains cleanups that should
6235/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006236///
John McCall5d413782010-12-06 08:20:24 +00006237/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006238/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006239template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006240ExprResult
John McCall5d413782010-12-06 08:20:24 +00006241TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006242 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006243}
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregora16548e2009-08-11 05:31:07 +00006245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006246ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006247TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006248 CXXTemporaryObjectExpr *E) {
6249 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6250 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregora16548e2009-08-11 05:31:07 +00006253 CXXConstructorDecl *Constructor
6254 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006255 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006256 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006261 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006262 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006263 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6264 &ArgumentChanged))
6265 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006268 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006269 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006270 !ArgumentChanged) {
6271 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006272 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006273 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006274 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006275
6276 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6277 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 E->getLocEnd());
6280}
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006283ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006284TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006285 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006286 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6287 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006288 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregora16548e2009-08-11 05:31:07 +00006290 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006291 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006292 Args.reserve(E->arg_size());
6293 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6294 &ArgumentChanged))
6295 return ExprError();
6296
Douglas Gregora16548e2009-08-11 05:31:07 +00006297 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006298 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006299 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006300 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregora16548e2009-08-11 05:31:07 +00006302 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006303 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006304 E->getLParenLoc(),
6305 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006306 E->getRParenLoc());
6307}
Mike Stump11289f42009-09-09 15:08:12 +00006308
Douglas Gregora16548e2009-08-11 05:31:07 +00006309template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006310ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006311TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006312 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006314 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006315 Expr *OldBase;
6316 QualType BaseType;
6317 QualType ObjectType;
6318 if (!E->isImplicitAccess()) {
6319 OldBase = E->getBase();
6320 Base = getDerived().TransformExpr(OldBase);
6321 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006322 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006323
John McCall2d74de92009-12-01 22:10:20 +00006324 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006325 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006326 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006327 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006328 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006329 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006330 ObjectTy,
6331 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006332 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006334
John McCallba7bf592010-08-24 05:47:05 +00006335 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006336 BaseType = ((Expr*) Base.get())->getType();
6337 } else {
6338 OldBase = 0;
6339 BaseType = getDerived().TransformType(E->getBaseType());
6340 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6341 }
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006343 // Transform the first part of the nested-name-specifier that qualifies
6344 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006345 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006346 = getDerived().TransformFirstQualifierInScope(
6347 E->getFirstQualifierFoundInScope(),
6348 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006349
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006350 NestedNameSpecifier *Qualifier = 0;
6351 if (E->getQualifier()) {
6352 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6353 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006354 ObjectType,
6355 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006356 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006357 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006358 }
Mike Stump11289f42009-09-09 15:08:12 +00006359
John McCall31f82722010-11-12 08:19:04 +00006360 // TODO: If this is a conversion-function-id, verify that the
6361 // destination type name (if present) resolves the same way after
6362 // instantiation as it did in the local scope.
6363
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006364 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006365 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006366 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006367 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006368
John McCall2d74de92009-12-01 22:10:20 +00006369 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006370 // This is a reference to a member without an explicitly-specified
6371 // template argument list. Optimize for this common case.
6372 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006373 Base.get() == OldBase &&
6374 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006375 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006376 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006377 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006378 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006379
John McCallb268a282010-08-23 23:25:46 +00006380 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006381 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006382 E->isArrow(),
6383 E->getOperatorLoc(),
6384 Qualifier,
6385 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006386 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006387 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006388 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006389 }
6390
John McCall6b51f282009-11-23 01:53:49 +00006391 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006392 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6393 E->getNumTemplateArgs(),
6394 TransArgs))
6395 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006396
John McCallb268a282010-08-23 23:25:46 +00006397 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006398 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006399 E->isArrow(),
6400 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006401 Qualifier,
6402 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006403 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006404 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006405 &TransArgs);
6406}
6407
6408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006411 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006412 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006413 QualType BaseType;
6414 if (!Old->isImplicitAccess()) {
6415 Base = getDerived().TransformExpr(Old->getBase());
6416 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006417 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006418 BaseType = ((Expr*) Base.get())->getType();
6419 } else {
6420 BaseType = getDerived().TransformType(Old->getBaseType());
6421 }
John McCall10eae182009-11-30 22:42:35 +00006422
6423 NestedNameSpecifier *Qualifier = 0;
6424 if (Old->getQualifier()) {
6425 Qualifier
6426 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006427 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006428 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006430 }
6431
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006432 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006433 Sema::LookupOrdinaryName);
6434
6435 // Transform all the decls.
6436 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6437 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006438 NamedDecl *InstD = static_cast<NamedDecl*>(
6439 getDerived().TransformDecl(Old->getMemberLoc(),
6440 *I));
John McCall84d87672009-12-10 09:41:52 +00006441 if (!InstD) {
6442 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6443 // This can happen because of dependent hiding.
6444 if (isa<UsingShadowDecl>(*I))
6445 continue;
6446 else
John McCallfaf5fb42010-08-26 23:41:50 +00006447 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006448 }
John McCall10eae182009-11-30 22:42:35 +00006449
6450 // Expand using declarations.
6451 if (isa<UsingDecl>(InstD)) {
6452 UsingDecl *UD = cast<UsingDecl>(InstD);
6453 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6454 E = UD->shadow_end(); I != E; ++I)
6455 R.addDecl(*I);
6456 continue;
6457 }
6458
6459 R.addDecl(InstD);
6460 }
6461
6462 R.resolveKind();
6463
Douglas Gregor9262f472010-04-27 18:19:34 +00006464 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006465 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006466 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006467 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006468 Old->getMemberLoc(),
6469 Old->getNamingClass()));
6470 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006471 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006472
Douglas Gregorda7be082010-04-27 16:10:10 +00006473 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006474 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006475
John McCall10eae182009-11-30 22:42:35 +00006476 TemplateArgumentListInfo TransArgs;
6477 if (Old->hasExplicitTemplateArgs()) {
6478 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6479 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006480 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6481 Old->getNumTemplateArgs(),
6482 TransArgs))
6483 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006484 }
John McCall38836f02010-01-15 08:34:02 +00006485
6486 // FIXME: to do this check properly, we will need to preserve the
6487 // first-qualifier-in-scope here, just in case we had a dependent
6488 // base (and therefore couldn't do the check) and a
6489 // nested-name-qualifier (and therefore could do the lookup).
6490 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006491
John McCallb268a282010-08-23 23:25:46 +00006492 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006493 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006494 Old->getOperatorLoc(),
6495 Old->isArrow(),
6496 Qualifier,
6497 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006498 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006499 R,
6500 (Old->hasExplicitTemplateArgs()
6501 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006502}
6503
6504template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006505ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006506TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6507 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6508 if (SubExpr.isInvalid())
6509 return ExprError();
6510
6511 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006512 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006513
6514 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6515}
6516
6517template<typename Derived>
6518ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006519TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6520 llvm_unreachable("pack expansion expression in unhandled context");
6521 return ExprError();
6522}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006523
6524template<typename Derived>
6525ExprResult
6526TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6527 // If E is not value-dependent, then nothing will change when we transform it.
6528 // Note: This is an instantiation-centric view.
6529 if (!E->isValueDependent())
6530 return SemaRef.Owned(E);
6531
6532 // Note: None of the implementations of TryExpandParameterPacks can ever
6533 // produce a diagnostic when given only a single unexpanded parameter pack,
6534 // so
6535 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6536 bool ShouldExpand = false;
6537 unsigned NumExpansions = 0;
6538 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6539 &Unexpanded, 1,
6540 ShouldExpand, NumExpansions))
6541 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006542
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006543 if (!ShouldExpand)
6544 return SemaRef.Owned(E);
6545
6546 // We now know the length of the parameter pack, so build a new expression
6547 // that stores that length.
6548 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6549 E->getPackLoc(), E->getRParenLoc(),
6550 NumExpansions);
6551}
6552
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006553template<typename Derived>
6554ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006555TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006556 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006557}
6558
Mike Stump11289f42009-09-09 15:08:12 +00006559template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006560ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006561TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006562 TypeSourceInfo *EncodedTypeInfo
6563 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6564 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006565 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006566
Douglas Gregora16548e2009-08-11 05:31:07 +00006567 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006568 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006569 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006570
6571 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006572 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006573 E->getRParenLoc());
6574}
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006578TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006579 // Transform arguments.
6580 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006581 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006582 Args.reserve(E->getNumArgs());
6583 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6584 &ArgChanged))
6585 return ExprError();
6586
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006587 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6588 // Class message: transform the receiver type.
6589 TypeSourceInfo *ReceiverTypeInfo
6590 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6591 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006593
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006594 // If nothing changed, just retain the existing message send.
6595 if (!getDerived().AlwaysRebuild() &&
6596 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006597 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006598
6599 // Build a new class message send.
6600 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6601 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006602 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006603 E->getMethodDecl(),
6604 E->getLeftLoc(),
6605 move_arg(Args),
6606 E->getRightLoc());
6607 }
6608
6609 // Instance message: transform the receiver
6610 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6611 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006612 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006613 = getDerived().TransformExpr(E->getInstanceReceiver());
6614 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006615 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006616
6617 // If nothing changed, just retain the existing message send.
6618 if (!getDerived().AlwaysRebuild() &&
6619 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006620 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006621
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006622 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006623 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006624 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006625 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006626 E->getMethodDecl(),
6627 E->getLeftLoc(),
6628 move_arg(Args),
6629 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006630}
6631
Mike Stump11289f42009-09-09 15:08:12 +00006632template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006633ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006634TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006635 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006636}
6637
Mike Stump11289f42009-09-09 15:08:12 +00006638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006640TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006641 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006642}
6643
Mike Stump11289f42009-09-09 15:08:12 +00006644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006646TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006647 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006648 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006649 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006650 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006651
6652 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006653
Douglas Gregord51d90d2010-04-26 20:11:03 +00006654 // If nothing changed, just retain the existing expression.
6655 if (!getDerived().AlwaysRebuild() &&
6656 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006657 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006658
John McCallb268a282010-08-23 23:25:46 +00006659 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006660 E->getLocation(),
6661 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006662}
6663
Mike Stump11289f42009-09-09 15:08:12 +00006664template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006665ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006666TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006667 // 'super' and types never change. Property never changes. Just
6668 // retain the existing expression.
6669 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006670 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006671
Douglas Gregor9faee212010-04-26 20:47:02 +00006672 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006673 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006674 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006675 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006676
Douglas Gregor9faee212010-04-26 20:47:02 +00006677 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006678
Douglas Gregor9faee212010-04-26 20:47:02 +00006679 // If nothing changed, just retain the existing expression.
6680 if (!getDerived().AlwaysRebuild() &&
6681 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006682 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006683
John McCallb7bd14f2010-12-02 01:19:52 +00006684 if (E->isExplicitProperty())
6685 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6686 E->getExplicitProperty(),
6687 E->getLocation());
6688
6689 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6690 E->getType(),
6691 E->getImplicitPropertyGetter(),
6692 E->getImplicitPropertySetter(),
6693 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006694}
6695
Mike Stump11289f42009-09-09 15:08:12 +00006696template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006697ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006698TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006699 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006700 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006701 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006702 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006703
Douglas Gregord51d90d2010-04-26 20:11:03 +00006704 // If nothing changed, just retain the existing expression.
6705 if (!getDerived().AlwaysRebuild() &&
6706 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006707 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006708
John McCallb268a282010-08-23 23:25:46 +00006709 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006710 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006711}
6712
Mike Stump11289f42009-09-09 15:08:12 +00006713template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006715TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006716 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006717 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006718 SubExprs.reserve(E->getNumSubExprs());
6719 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6720 SubExprs, &ArgumentChanged))
6721 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006722
Douglas Gregora16548e2009-08-11 05:31:07 +00006723 if (!getDerived().AlwaysRebuild() &&
6724 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006725 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6728 move_arg(SubExprs),
6729 E->getRParenLoc());
6730}
6731
Mike Stump11289f42009-09-09 15:08:12 +00006732template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006733ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006734TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006735 SourceLocation CaretLoc(E->getExprLoc());
6736
6737 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6738 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6739 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6740 llvm::SmallVector<ParmVarDecl*, 4> Params;
6741 llvm::SmallVector<QualType, 4> ParamTypes;
6742
6743 // Parameter substitution.
6744 const BlockDecl *BD = E->getBlockDecl();
6745 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6746 EN = BD->param_end(); P != EN; ++P) {
6747 ParmVarDecl *OldParm = (*P);
6748 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6749 QualType NewType = NewParm->getType();
6750 Params.push_back(NewParm);
6751 ParamTypes.push_back(NewParm->getType());
6752 }
6753
6754 const FunctionType *BExprFunctionType = E->getFunctionType();
6755 QualType BExprResultType = BExprFunctionType->getResultType();
6756 if (!BExprResultType.isNull()) {
6757 if (!BExprResultType->isDependentType())
6758 CurBlock->ReturnType = BExprResultType;
6759 else if (BExprResultType != SemaRef.Context.DependentTy)
6760 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6761 }
John McCall3882ace2011-01-05 12:14:39 +00006762
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006763 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6764 CurBlock->ReturnType,
6765 ParamTypes.data(),
6766 ParamTypes.size(),
6767 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006768 0,
6769 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006770 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00006771
6772 // Set the parameters on the block decl.
6773 if (!Params.empty())
6774 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6775
6776 // Transform the body
6777 StmtResult Body = getDerived().TransformStmt(E->getBody());
6778 if (Body.isInvalid())
6779 return ExprError();
6780
John McCallb268a282010-08-23 23:25:46 +00006781 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006782}
6783
Mike Stump11289f42009-09-09 15:08:12 +00006784template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006785ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006786TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006787 NestedNameSpecifier *Qualifier = 0;
6788
6789 ValueDecl *ND
6790 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6791 E->getDecl()));
6792 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00006793 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006794
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006795 if (!getDerived().AlwaysRebuild() &&
6796 ND == E->getDecl()) {
6797 // Mark it referenced in the new context regardless.
6798 // FIXME: this is a bit instantiation-specific.
6799 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6800
John McCallc3007a22010-10-26 07:05:15 +00006801 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006802 }
6803
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006804 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006805 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006806 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006807}
Mike Stump11289f42009-09-09 15:08:12 +00006808
Douglas Gregora16548e2009-08-11 05:31:07 +00006809//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006810// Type reconstruction
6811//===----------------------------------------------------------------------===//
6812
Mike Stump11289f42009-09-09 15:08:12 +00006813template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006814QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6815 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006816 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006817 getDerived().getBaseEntity());
6818}
6819
Mike Stump11289f42009-09-09 15:08:12 +00006820template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006821QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6822 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006823 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006824 getDerived().getBaseEntity());
6825}
6826
Mike Stump11289f42009-09-09 15:08:12 +00006827template<typename Derived>
6828QualType
John McCall70dd5f62009-10-30 00:06:24 +00006829TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6830 bool WrittenAsLValue,
6831 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006832 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006833 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006834}
6835
6836template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006837QualType
John McCall70dd5f62009-10-30 00:06:24 +00006838TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6839 QualType ClassType,
6840 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006841 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006842 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006843}
6844
6845template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006846QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006847TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6848 ArrayType::ArraySizeModifier SizeMod,
6849 const llvm::APInt *Size,
6850 Expr *SizeExpr,
6851 unsigned IndexTypeQuals,
6852 SourceRange BracketsRange) {
6853 if (SizeExpr || !Size)
6854 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6855 IndexTypeQuals, BracketsRange,
6856 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006857
6858 QualType Types[] = {
6859 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6860 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6861 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006862 };
6863 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6864 QualType SizeType;
6865 for (unsigned I = 0; I != NumTypes; ++I)
6866 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6867 SizeType = Types[I];
6868 break;
6869 }
Mike Stump11289f42009-09-09 15:08:12 +00006870
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006871 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
6872 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006873 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006874 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006875 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006876}
Mike Stump11289f42009-09-09 15:08:12 +00006877
Douglas Gregord6ff3322009-08-04 16:50:30 +00006878template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006879QualType
6880TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006881 ArrayType::ArraySizeModifier SizeMod,
6882 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006883 unsigned IndexTypeQuals,
6884 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006885 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006886 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006887}
6888
6889template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006890QualType
Mike Stump11289f42009-09-09 15:08:12 +00006891TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006892 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006893 unsigned IndexTypeQuals,
6894 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006895 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006896 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006897}
Mike Stump11289f42009-09-09 15:08:12 +00006898
Douglas Gregord6ff3322009-08-04 16:50:30 +00006899template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006900QualType
6901TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006902 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006903 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006904 unsigned IndexTypeQuals,
6905 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006906 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006907 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006908 IndexTypeQuals, BracketsRange);
6909}
6910
6911template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006912QualType
6913TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006914 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00006915 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006916 unsigned IndexTypeQuals,
6917 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006918 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00006919 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006920 IndexTypeQuals, BracketsRange);
6921}
6922
6923template<typename Derived>
6924QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00006925 unsigned NumElements,
6926 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006927 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00006928 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006929}
Mike Stump11289f42009-09-09 15:08:12 +00006930
Douglas Gregord6ff3322009-08-04 16:50:30 +00006931template<typename Derived>
6932QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6933 unsigned NumElements,
6934 SourceLocation AttributeLoc) {
6935 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6936 NumElements, true);
6937 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006938 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
6939 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00006940 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006941}
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregord6ff3322009-08-04 16:50:30 +00006943template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006944QualType
6945TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00006946 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006947 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00006948 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006949}
Mike Stump11289f42009-09-09 15:08:12 +00006950
Douglas Gregord6ff3322009-08-04 16:50:30 +00006951template<typename Derived>
6952QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006953 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006954 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006955 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00006956 unsigned Quals,
6957 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00006958 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006959 Quals,
6960 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00006961 getDerived().getBaseEntity(),
6962 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006963}
Mike Stump11289f42009-09-09 15:08:12 +00006964
Douglas Gregord6ff3322009-08-04 16:50:30 +00006965template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006966QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6967 return SemaRef.Context.getFunctionNoProtoType(T);
6968}
6969
6970template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006971QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6972 assert(D && "no decl found");
6973 if (D->isInvalidDecl()) return QualType();
6974
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006975 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006976 TypeDecl *Ty;
6977 if (isa<UsingDecl>(D)) {
6978 UsingDecl *Using = cast<UsingDecl>(D);
6979 assert(Using->isTypeName() &&
6980 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6981
6982 // A valid resolved using typename decl points to exactly one type decl.
6983 assert(++Using->shadow_begin() == Using->shadow_end());
6984 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006985
John McCallb96ec562009-12-04 22:46:56 +00006986 } else {
6987 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6988 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6989 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6990 }
6991
6992 return SemaRef.Context.getTypeDeclType(Ty);
6993}
6994
6995template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00006996QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
6997 SourceLocation Loc) {
6998 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006999}
7000
7001template<typename Derived>
7002QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7003 return SemaRef.Context.getTypeOfType(Underlying);
7004}
7005
7006template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007007QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7008 SourceLocation Loc) {
7009 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007010}
7011
7012template<typename Derived>
7013QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007014 TemplateName Template,
7015 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007016 const TemplateArgumentListInfo &TemplateArgs) {
7017 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007018}
Mike Stump11289f42009-09-09 15:08:12 +00007019
Douglas Gregor1135c352009-08-06 05:28:30 +00007020template<typename Derived>
7021NestedNameSpecifier *
7022TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7023 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007024 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007025 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007026 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007027 CXXScopeSpec SS;
7028 // FIXME: The source location information is all wrong.
7029 SS.setRange(Range);
7030 SS.setScopeRep(Prefix);
7031 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007032 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007033 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007034 ObjectType,
7035 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007036 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007037}
7038
7039template<typename Derived>
7040NestedNameSpecifier *
7041TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7042 SourceRange Range,
7043 NamespaceDecl *NS) {
7044 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7045}
7046
7047template<typename Derived>
7048NestedNameSpecifier *
7049TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7050 SourceRange Range,
7051 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007052 QualType T) {
7053 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007054 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007055 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007056 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7057 T.getTypePtr());
7058 }
Mike Stump11289f42009-09-09 15:08:12 +00007059
Douglas Gregor1135c352009-08-06 05:28:30 +00007060 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7061 return 0;
7062}
Mike Stump11289f42009-09-09 15:08:12 +00007063
Douglas Gregor71dc5092009-08-06 06:41:21 +00007064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007065TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007066TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7067 bool TemplateKW,
7068 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007069 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007070 Template);
7071}
7072
7073template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007074TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007075TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007076 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007077 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007078 QualType ObjectType,
7079 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007080 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007081 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007082 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007083 UnqualifiedId Name;
7084 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007085 Sema::TemplateTy Template;
7086 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7087 /*FIXME:*/getDerived().getBaseLocation(),
7088 SS,
7089 Name,
John McCallba7bf592010-08-24 05:47:05 +00007090 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007091 /*EnteringContext=*/false,
7092 Template);
John McCall31f82722010-11-12 08:19:04 +00007093 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007094}
Mike Stump11289f42009-09-09 15:08:12 +00007095
Douglas Gregora16548e2009-08-11 05:31:07 +00007096template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007097TemplateName
7098TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7099 OverloadedOperatorKind Operator,
7100 QualType ObjectType) {
7101 CXXScopeSpec SS;
7102 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7103 SS.setScopeRep(Qualifier);
7104 UnqualifiedId Name;
7105 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7106 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7107 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007108 Sema::TemplateTy Template;
7109 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007110 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007111 SS,
7112 Name,
John McCallba7bf592010-08-24 05:47:05 +00007113 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007114 /*EnteringContext=*/false,
7115 Template);
7116 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007117}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007118
Douglas Gregor71395fa2009-11-04 00:56:37 +00007119template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007120ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007121TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7122 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007123 Expr *OrigCallee,
7124 Expr *First,
7125 Expr *Second) {
7126 Expr *Callee = OrigCallee->IgnoreParenCasts();
7127 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007128
Douglas Gregora16548e2009-08-11 05:31:07 +00007129 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007130 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007131 if (!First->getType()->isOverloadableType() &&
7132 !Second->getType()->isOverloadableType())
7133 return getSema().CreateBuiltinArraySubscriptExpr(First,
7134 Callee->getLocStart(),
7135 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007136 } else if (Op == OO_Arrow) {
7137 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007138 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7139 } else if (Second == 0 || isPostIncDec) {
7140 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007141 // The argument is not of overloadable type, so try to create a
7142 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007143 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007144 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007145
John McCallb268a282010-08-23 23:25:46 +00007146 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007147 }
7148 } else {
John McCallb268a282010-08-23 23:25:46 +00007149 if (!First->getType()->isOverloadableType() &&
7150 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007151 // Neither of the arguments is an overloadable type, so try to
7152 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007153 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007154 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007155 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007156 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007157 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007158
Douglas Gregora16548e2009-08-11 05:31:07 +00007159 return move(Result);
7160 }
7161 }
Mike Stump11289f42009-09-09 15:08:12 +00007162
7163 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007164 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007165 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007166
John McCallb268a282010-08-23 23:25:46 +00007167 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007168 assert(ULE->requiresADL());
7169
7170 // FIXME: Do we have to check
7171 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007172 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007173 } else {
John McCallb268a282010-08-23 23:25:46 +00007174 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007175 }
Mike Stump11289f42009-09-09 15:08:12 +00007176
Douglas Gregora16548e2009-08-11 05:31:07 +00007177 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007178 Expr *Args[2] = { First, Second };
7179 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007180
Douglas Gregora16548e2009-08-11 05:31:07 +00007181 // Create the overloaded operator invocation for unary operators.
7182 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007183 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007184 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007185 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007186 }
Mike Stump11289f42009-09-09 15:08:12 +00007187
Sebastian Redladba46e2009-10-29 20:17:01 +00007188 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007189 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007190 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007191 First,
7192 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007193
Douglas Gregora16548e2009-08-11 05:31:07 +00007194 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007195 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007196 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007197 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7198 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007200
Mike Stump11289f42009-09-09 15:08:12 +00007201 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007202}
Mike Stump11289f42009-09-09 15:08:12 +00007203
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007204template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007205ExprResult
John McCallb268a282010-08-23 23:25:46 +00007206TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007207 SourceLocation OperatorLoc,
7208 bool isArrow,
7209 NestedNameSpecifier *Qualifier,
7210 SourceRange QualifierRange,
7211 TypeSourceInfo *ScopeType,
7212 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007213 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007214 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007215 CXXScopeSpec SS;
7216 if (Qualifier) {
7217 SS.setRange(QualifierRange);
7218 SS.setScopeRep(Qualifier);
7219 }
7220
John McCallb268a282010-08-23 23:25:46 +00007221 QualType BaseType = Base->getType();
7222 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007223 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007224 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007225 !BaseType->getAs<PointerType>()->getPointeeType()
7226 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007227 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007228 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007229 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007230 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007231 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007232 /*FIXME?*/true);
7233 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007234
Douglas Gregor678f90d2010-02-25 01:56:36 +00007235 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007236 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7237 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7238 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7239 NameInfo.setNamedTypeInfo(DestroyedType);
7240
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007241 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007242
John McCallb268a282010-08-23 23:25:46 +00007243 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007244 OperatorLoc, isArrow,
7245 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007246 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007247 /*TemplateArgs*/ 0);
7248}
7249
Douglas Gregord6ff3322009-08-04 16:50:30 +00007250} // end namespace clang
7251
7252#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H