blob: 587c93d1ad5fc5753aa9b6ccc7497eee318a1292 [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
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
194 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
John McCallbcd03502009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000278
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000280 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall70dd5f62009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregorc59e5612009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000323
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000325
Douglas Gregorebe10102009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000332
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump11289f42009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000344
John McCall70dd5f62009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000346 ///
John McCall70dd5f62009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 ///
John McCall70dd5f62009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000356
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000364
John McCall550e0c22009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000368
Douglas Gregord6ff3322009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000382
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403
Mike Stump11289f42009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000432
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000458
John McCall550e0c22009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCallb96ec562009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregord6ff3322009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCallfcc33b02009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump11289f42009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000491
Mike Stump11289f42009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump11289f42009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000519 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
527 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000532 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533
534 /// \brief Build a new typename type that refers to an identifier.
535 ///
536 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Douglas Gregor1135c352009-08-06 05:28:30 +0000545 /// \brief Build a new nested-name-specifier given the prefix and an
546 /// identifier that names the next step in the nested-name-specifier.
547 ///
548 /// By default, performs semantic analysis when building the new
549 /// nested-name-specifier. Subclasses may override this routine to provide
550 /// different behavior.
551 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
552 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// namespace named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 NamespaceDecl *NS);
566
567 /// \brief Build a new nested-name-specifier given the prefix and the
568 /// type named in the next step in the nested-name-specifier.
569 ///
570 /// By default, performs semantic analysis when building the new
571 /// nested-name-specifier. Subclasses may override this routine to provide
572 /// different behavior.
573 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
574 SourceRange Range,
575 bool TemplateKW,
576 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000577
578 /// \brief Build a new template name given a nested name specifier, a flag
579 /// indicating whether the "template" keyword was provided, and the template
580 /// that the template name refers to.
581 ///
582 /// By default, builds the new template name directly. Subclasses may override
583 /// this routine to provide different behavior.
584 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
585 bool TemplateKW,
586 TemplateDecl *Template);
587
Douglas Gregor71dc5092009-08-06 06:41:21 +0000588 /// \brief Build a new template name given a nested name specifier and the
589 /// name that is referred to as a template.
590 ///
591 /// By default, performs semantic analysis to determine whether the name can
592 /// be resolved to a specific template, then builds the appropriate kind of
593 /// template name. Subclasses may override this routine to provide different
594 /// behavior.
595 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000598
Douglas Gregor71395fa2009-11-04 00:56:37 +0000599 /// \brief Build a new template name given a nested name specifier and the
600 /// overloaded operator name that is referred to as a template.
601 ///
602 /// By default, performs semantic analysis to determine whether the name can
603 /// be resolved to a specific template, then builds the appropriate kind of
604 /// template name. Subclasses may override this routine to provide different
605 /// behavior.
606 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
607 OverloadedOperatorKind Operator,
608 QualType ObjectType);
609
Douglas Gregorebe10102009-08-20 07:17:43 +0000610 /// \brief Build a new compound statement.
611 ///
612 /// By default, performs semantic analysis to build the new statement.
613 /// Subclasses may override this routine to provide different behavior.
614 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
615 MultiStmtArg Statements,
616 SourceLocation RBraceLoc,
617 bool IsStmtExpr) {
618 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
619 IsStmtExpr);
620 }
621
622 /// \brief Build a new case statement.
623 ///
624 /// By default, performs semantic analysis to build the new statement.
625 /// Subclasses may override this routine to provide different behavior.
626 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
627 ExprArg LHS,
628 SourceLocation EllipsisLoc,
629 ExprArg RHS,
630 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump11289f42009-09-09 15:08:12 +0000634
Douglas Gregorebe10102009-08-20 07:17:43 +0000635 /// \brief Attach the body to a new case statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
640 getSema().ActOnCaseStmtBody(S.get(), move(Body));
641 return move(S);
642 }
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregorebe10102009-08-20 07:17:43 +0000644 /// \brief Build a new default statement.
645 ///
646 /// By default, performs semantic analysis to build the new statement.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump11289f42009-09-09 15:08:12 +0000654
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 /// \brief Build a new label statement.
656 ///
657 /// By default, performs semantic analysis to build the new statement.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000660 IdentifierInfo *Id,
661 SourceLocation ColonLoc,
662 StmtArg SubStmt) {
663 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
664 }
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregorebe10102009-08-20 07:17:43 +0000666 /// \brief Build a new "if" statement.
667 ///
668 /// By default, performs semantic analysis to build the new statement.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000671 VarDecl *CondVar, StmtArg Then,
672 SourceLocation ElseLoc, StmtArg Else) {
673 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
674 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000675 }
Mike Stump11289f42009-09-09 15:08:12 +0000676
Douglas Gregorebe10102009-08-20 07:17:43 +0000677 /// \brief Start building a new switch statement.
678 ///
679 /// By default, performs semantic analysis to build the new statement.
680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 }
Mike Stump11289f42009-09-09 15:08:12 +0000685
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 /// \brief Attach the body to the switch statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 StmtArg Switch, StmtArg Body) {
692 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
693 move(Body));
694 }
695
696 /// \brief Build a new while statement.
697 ///
698 /// By default, performs semantic analysis to build the new statement.
699 /// Subclasses may override this routine to provide different behavior.
700 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
701 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 }
Mike Stump11289f42009-09-09 15:08:12 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new do-while statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
713 SourceLocation WhileLoc,
714 SourceLocation LParenLoc,
715 ExprArg Cond,
716 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 move(Cond), RParenLoc);
719 }
720
721 /// \brief Build a new for statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000784 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregora16548e2009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000818 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
819 LookupResult &R,
820 bool RequiresADL) {
821 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
822 }
823
824
825 /// \brief Build a new expression that references a declaration.
826 ///
827 /// By default, performs semantic analysis to build the new expression.
828 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000829 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
830 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000831 ValueDecl *VD, SourceLocation Loc,
832 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000833 CXXScopeSpec SS;
834 SS.setScopeRep(Qualifier);
835 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000836
837 // FIXME: loses template args.
838
839 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 }
Mike Stump11289f42009-09-09 15:08:12 +0000841
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
847 SourceLocation RParen) {
848 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
849 }
850
Douglas Gregorad8a3362009-09-04 17:36:40 +0000851 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000852 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
856 SourceLocation OperatorLoc,
857 bool isArrow,
858 SourceLocation DestroyedTypeLoc,
859 QualType DestroyedType,
860 NestedNameSpecifier *Qualifier,
861 SourceRange QualifierRange) {
862 CXXScopeSpec SS;
863 if (Qualifier) {
864 SS.setRange(QualifierRange);
865 SS.setScopeRep(Qualifier);
866 }
867
John McCall2d74de92009-12-01 22:10:20 +0000868 QualType BaseType = ((Expr*) Base.get())->getType();
869
Mike Stump11289f42009-09-09 15:08:12 +0000870 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000871 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
872 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000873
John McCall2d74de92009-12-01 22:10:20 +0000874 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
875 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000876 SS, /*FIXME: FirstQualifier*/ 0,
877 Name, DestroyedTypeLoc,
878 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000879 }
880
Douglas Gregora16548e2009-08-11 05:31:07 +0000881 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
885 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
886 UnaryOperator::Opcode Opc,
887 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000888 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 }
Mike Stump11289f42009-09-09 15:08:12 +0000890
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000895 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000896 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000897 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000898 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 }
900
Mike Stump11289f42009-09-09 15:08:12 +0000901 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000902 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 /// By default, performs semantic analysis to build the new expression.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
907 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000908 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
910 OpLoc, isSizeOf, R);
911 if (Result.isInvalid())
912 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000913
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 SubExpr.release();
915 return move(Result);
916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000922 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 SourceLocation LBracketLoc,
924 ExprArg RHS,
925 SourceLocation RBracketLoc) {
926 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000927 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 RBracketLoc);
929 }
930
931 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000932 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
935 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
936 MultiExprArg Args,
937 SourceLocation *CommaLocs,
938 SourceLocation RParenLoc) {
939 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
940 move(Args), CommaLocs, RParenLoc);
941 }
942
943 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000944 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000948 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000949 NestedNameSpecifier *Qualifier,
950 SourceRange QualifierRange,
951 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000952 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000953 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000954 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000955 if (!Member->getDeclName()) {
956 // We have a reference to an unnamed field.
957 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000958
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000959 Expr *BaseExpr = Base.takeAs<Expr>();
960 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
961 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000962
Mike Stump11289f42009-09-09 15:08:12 +0000963 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000964 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000965 Member, MemberLoc,
966 cast<FieldDecl>(Member)->getType());
967 return getSema().Owned(ME);
968 }
Mike Stump11289f42009-09-09 15:08:12 +0000969
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000970 CXXScopeSpec SS;
971 if (Qualifier) {
972 SS.setRange(QualifierRange);
973 SS.setScopeRep(Qualifier);
974 }
975
John McCall2d74de92009-12-01 22:10:20 +0000976 QualType BaseType = ((Expr*) Base.get())->getType();
977
John McCall38836f02010-01-15 08:34:02 +0000978 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
979 Sema::LookupMemberName);
980 R.addDecl(Member);
981 R.resolveKind();
982
John McCall2d74de92009-12-01 22:10:20 +0000983 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
984 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000985 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +0000986 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregora16548e2009-08-11 05:31:07 +0000989 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000990 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000991 /// By default, performs semantic analysis to build the new expression.
992 /// Subclasses may override this routine to provide different behavior.
993 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
994 BinaryOperator::Opcode Opc,
995 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000996 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
997 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000998 }
999
1000 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001001 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001002 /// By default, performs semantic analysis to build the new expression.
1003 /// Subclasses may override this routine to provide different behavior.
1004 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1005 SourceLocation QuestionLoc,
1006 ExprArg LHS,
1007 SourceLocation ColonLoc,
1008 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001009 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 move(LHS), move(RHS));
1011 }
1012
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001014 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001017 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1018 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001019 SourceLocation RParenLoc,
1020 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001021 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1022 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001030 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 SourceLocation RParenLoc,
1032 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001033 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1034 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001041 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 SourceLocation OpLoc,
1043 SourceLocation AccessorLoc,
1044 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001045
John McCall10eae182009-11-30 22:42:35 +00001046 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001047 QualType BaseType = ((Expr*) Base.get())->getType();
1048 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001049 OpLoc, /*IsArrow*/ false,
1050 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001051 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001052 AccessorLoc,
1053 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001057 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1061 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001062 SourceLocation RBraceLoc,
1063 QualType ResultTy) {
1064 OwningExprResult Result
1065 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1066 if (Result.isInvalid() || ResultTy->isDependentType())
1067 return move(Result);
1068
1069 // Patch in the result type we were given, which may have been computed
1070 // when the initial InitListExpr was built.
1071 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1072 ILE->setType(ResultTy);
1073 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
1080 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1081 MultiExprArg ArrayExprs,
1082 SourceLocation EqualOrColonLoc,
1083 bool GNUSyntax,
1084 ExprArg Init) {
1085 OwningExprResult Result
1086 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1087 move(Init));
1088 if (Result.isInvalid())
1089 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 ArrayExprs.release();
1092 return move(Result);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001096 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// By default, builds the implicit value initialization without performing
1098 /// any semantic analysis. Subclasses may override this routine to provide
1099 /// different behavior.
1100 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1101 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001105 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
1108 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1109 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001110 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 RParenLoc);
1112 }
1113
1114 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// By default, performs semantic analysis to build the new expression.
1117 /// Subclasses may override this routine to provide different behavior.
1118 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1119 MultiExprArg SubExprs,
1120 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001121 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1122 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
1127 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// rather than attempting to map the label statement itself.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1131 SourceLocation LabelLoc,
1132 LabelStmt *Label) {
1133 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1141 StmtArg SubStmt,
1142 SourceLocation RParenLoc) {
1143 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 /// \brief Build a new __builtin_types_compatible_p expression.
1147 ///
1148 /// By default, performs semantic analysis to build the new expression.
1149 /// Subclasses may override this routine to provide different behavior.
1150 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1151 QualType T1, QualType T2,
1152 SourceLocation RParenLoc) {
1153 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1154 T1.getAsOpaquePtr(),
1155 T2.getAsOpaquePtr(),
1156 RParenLoc);
1157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregora16548e2009-08-11 05:31:07 +00001159 /// \brief Build a new __builtin_choose_expr expression.
1160 ///
1161 /// By default, performs semantic analysis to build the new expression.
1162 /// Subclasses may override this routine to provide different behavior.
1163 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1164 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1165 SourceLocation RParenLoc) {
1166 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1167 move(Cond), move(LHS), move(RHS),
1168 RParenLoc);
1169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// \brief Build a new overloaded operator call expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// The semantic analysis provides the behavior of template instantiation,
1175 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001176 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001177 /// argument-dependent lookup, etc. Subclasses may override this routine to
1178 /// provide different behavior.
1179 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1180 SourceLocation OpLoc,
1181 ExprArg Callee,
1182 ExprArg First,
1183 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001184
1185 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// reinterpret_cast.
1187 ///
1188 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001189 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001190 /// Subclasses may override this routine to provide different behavior.
1191 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1192 Stmt::StmtClass Class,
1193 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001194 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 SourceLocation RAngleLoc,
1196 SourceLocation LParenLoc,
1197 ExprArg SubExpr,
1198 SourceLocation RParenLoc) {
1199 switch (Class) {
1200 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001201 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001202 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 move(SubExpr), RParenLoc);
1204
1205 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001206 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001207 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001211 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001212 RAngleLoc, LParenLoc,
1213 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001215
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001217 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001218 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 default:
1222 assert(false && "Invalid C++ named cast");
1223 break;
1224 }
Mike Stump11289f42009-09-09 15:08:12 +00001225
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 return getSema().ExprError();
1227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new C++ static_cast expression.
1230 ///
1231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
1233 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1234 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001235 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 SourceLocation RAngleLoc,
1237 SourceLocation LParenLoc,
1238 ExprArg SubExpr,
1239 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001240 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1241 TInfo, move(SubExpr),
1242 SourceRange(LAngleLoc, RAngleLoc),
1243 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 }
1245
1246 /// \brief Build a new C++ dynamic_cast expression.
1247 ///
1248 /// By default, performs semantic analysis to build the new expression.
1249 /// Subclasses may override this routine to provide different behavior.
1250 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1251 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001252 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 SourceLocation RAngleLoc,
1254 SourceLocation LParenLoc,
1255 ExprArg SubExpr,
1256 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001257 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1258 TInfo, move(SubExpr),
1259 SourceRange(LAngleLoc, RAngleLoc),
1260 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 }
1262
1263 /// \brief Build a new C++ reinterpret_cast expression.
1264 ///
1265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1268 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001269 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 SourceLocation RAngleLoc,
1271 SourceLocation LParenLoc,
1272 ExprArg SubExpr,
1273 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001274 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1275 TInfo, move(SubExpr),
1276 SourceRange(LAngleLoc, RAngleLoc),
1277 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 }
1279
1280 /// \brief Build a new C++ const_cast expression.
1281 ///
1282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
1284 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1285 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001286 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 SourceLocation RAngleLoc,
1288 SourceLocation LParenLoc,
1289 ExprArg SubExpr,
1290 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001291 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1292 TInfo, move(SubExpr),
1293 SourceRange(LAngleLoc, RAngleLoc),
1294 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 }
Mike Stump11289f42009-09-09 15:08:12 +00001296
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// \brief Build a new C++ functional-style cast expression.
1298 ///
1299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001302 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 SourceLocation LParenLoc,
1304 ExprArg SubExpr,
1305 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001306 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001308 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001310 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001311 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 RParenLoc);
1313 }
Mike Stump11289f42009-09-09 15:08:12 +00001314
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// \brief Build a new C++ typeid(type) expression.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1320 SourceLocation LParenLoc,
1321 QualType T,
1322 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001323 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 T.getAsOpaquePtr(), RParenLoc);
1325 }
Mike Stump11289f42009-09-09 15:08:12 +00001326
Douglas Gregora16548e2009-08-11 05:31:07 +00001327 /// \brief Build a new C++ typeid(expr) expression.
1328 ///
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1332 SourceLocation LParenLoc,
1333 ExprArg Operand,
1334 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001335 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1337 RParenLoc);
1338 if (Result.isInvalid())
1339 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1342 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001343 }
1344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// \brief Build a new C++ "this" expression.
1346 ///
1347 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001348 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001350 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001351 QualType ThisType,
1352 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001354 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1355 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 }
1357
1358 /// \brief Build a new C++ throw expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
1362 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1363 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1364 }
1365
1366 /// \brief Build a new C++ default-argument expression.
1367 ///
1368 /// By default, builds a new default-argument expression, which does not
1369 /// require any semantic analysis. Subclasses may override this routine to
1370 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001371 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1372 ParmVarDecl *Param) {
1373 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1374 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 }
1376
1377 /// \brief Build a new C++ zero-initialization expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001381 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 SourceLocation LParenLoc,
1383 QualType T,
1384 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001385 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1386 T.getAsOpaquePtr(), LParenLoc,
1387 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001388 0, RParenLoc);
1389 }
Mike Stump11289f42009-09-09 15:08:12 +00001390
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 /// \brief Build a new C++ "new" expression.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001395 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001396 bool UseGlobal,
1397 SourceLocation PlacementLParen,
1398 MultiExprArg PlacementArgs,
1399 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001400 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 QualType AllocType,
1402 SourceLocation TypeLoc,
1403 SourceRange TypeRange,
1404 ExprArg ArraySize,
1405 SourceLocation ConstructorLParen,
1406 MultiExprArg ConstructorArgs,
1407 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001408 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 PlacementLParen,
1410 move(PlacementArgs),
1411 PlacementRParen,
1412 ParenTypeId,
1413 AllocType,
1414 TypeLoc,
1415 TypeRange,
1416 move(ArraySize),
1417 ConstructorLParen,
1418 move(ConstructorArgs),
1419 ConstructorRParen);
1420 }
Mike Stump11289f42009-09-09 15:08:12 +00001421
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 /// \brief Build a new C++ "delete" expression.
1423 ///
1424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
1426 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1427 bool IsGlobalDelete,
1428 bool IsArrayForm,
1429 ExprArg Operand) {
1430 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1431 move(Operand));
1432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new unary type trait expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1439 SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 QualType T,
1442 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001443 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 T.getAsOpaquePtr(), RParenLoc);
1445 }
1446
Mike Stump11289f42009-09-09 15:08:12 +00001447 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// expression.
1449 ///
1450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001452 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 SourceRange QualifierRange,
1454 DeclarationName Name,
1455 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001456 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 CXXScopeSpec SS;
1458 SS.setRange(QualifierRange);
1459 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001460
1461 if (TemplateArgs)
1462 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1463 *TemplateArgs);
1464
1465 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new template-id expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001472 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1473 LookupResult &R,
1474 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001475 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001476 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new object-construction expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
1483 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001484 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001485 CXXConstructorDecl *Constructor,
1486 bool IsElidable,
1487 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001488 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1489 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1490 ConvertedArgs))
1491 return getSema().ExprError();
1492
1493 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1494 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
1496
1497 /// \brief Build a new object-construction expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1502 QualType T,
1503 SourceLocation LParenLoc,
1504 MultiExprArg Args,
1505 SourceLocation *Commas,
1506 SourceLocation RParenLoc) {
1507 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1508 T.getAsOpaquePtr(),
1509 LParenLoc,
1510 move(Args),
1511 Commas,
1512 RParenLoc);
1513 }
1514
1515 /// \brief Build a new object-construction expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
1519 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1520 QualType T,
1521 SourceLocation LParenLoc,
1522 MultiExprArg Args,
1523 SourceLocation *Commas,
1524 SourceLocation RParenLoc) {
1525 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1526 /*FIXME*/LParenLoc),
1527 T.getAsOpaquePtr(),
1528 LParenLoc,
1529 move(Args),
1530 Commas,
1531 RParenLoc);
1532 }
Mike Stump11289f42009-09-09 15:08:12 +00001533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new member reference expression.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001538 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001539 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 bool IsArrow,
1541 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001542 NestedNameSpecifier *Qualifier,
1543 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001544 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001546 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001547 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001549 SS.setRange(QualifierRange);
1550 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001551
John McCall2d74de92009-12-01 22:10:20 +00001552 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1553 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001554 SS, FirstQualifierInScope,
1555 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 }
1557
John McCall10eae182009-11-30 22:42:35 +00001558 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001562 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001563 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001564 SourceLocation OperatorLoc,
1565 bool IsArrow,
1566 NestedNameSpecifier *Qualifier,
1567 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001568 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001569 LookupResult &R,
1570 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001571 CXXScopeSpec SS;
1572 SS.setRange(QualifierRange);
1573 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001574
John McCall2d74de92009-12-01 22:10:20 +00001575 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1576 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001577 SS, FirstQualifierInScope,
1578 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001579 }
Mike Stump11289f42009-09-09 15:08:12 +00001580
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// \brief Build a new Objective-C @encode expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
1585 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1586 QualType T,
1587 SourceLocation RParenLoc) {
1588 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1589 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001590 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001591
1592 /// \brief Build a new Objective-C protocol expression.
1593 ///
1594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
1596 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1597 SourceLocation AtLoc,
1598 SourceLocation ProtoLoc,
1599 SourceLocation LParenLoc,
1600 SourceLocation RParenLoc) {
1601 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1602 Protocol->getIdentifier(),
1603 AtLoc,
1604 ProtoLoc,
1605 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001606 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 shuffle vector expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
1613 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1614 MultiExprArg SubExprs,
1615 SourceLocation RParenLoc) {
1616 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001617 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1619 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1620 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1621 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001622
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 // Build a reference to the __builtin_shufflevector builtin
1624 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001625 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001627 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001629
1630 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 unsigned NumSubExprs = SubExprs.size();
1632 Expr **Subs = (Expr **)SubExprs.release();
1633 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1634 Subs, NumSubExprs,
1635 Builtin->getResultType(),
1636 RParenLoc);
1637 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 // Type-check the __builtin_shufflevector expression.
1640 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1641 if (Result.isInvalid())
1642 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001643
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001645 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001646 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001647};
Douglas Gregora16548e2009-08-11 05:31:07 +00001648
Douglas Gregorebe10102009-08-20 07:17:43 +00001649template<typename Derived>
1650Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1651 if (!S)
1652 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregorebe10102009-08-20 07:17:43 +00001654 switch (S->getStmtClass()) {
1655 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregorebe10102009-08-20 07:17:43 +00001657 // Transform individual statement nodes
1658#define STMT(Node, Parent) \
1659 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1660#define EXPR(Node, Parent)
1661#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001662
Douglas Gregorebe10102009-08-20 07:17:43 +00001663 // Transform expressions by calling TransformExpr.
1664#define STMT(Node, Parent)
1665#define EXPR(Node, Parent) case Stmt::Node##Class:
1666#include "clang/AST/StmtNodes.def"
1667 {
1668 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1669 if (E.isInvalid())
1670 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001671
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001672 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 }
Mike Stump11289f42009-09-09 15:08:12 +00001674 }
1675
Douglas Gregorebe10102009-08-20 07:17:43 +00001676 return SemaRef.Owned(S->Retain());
1677}
Mike Stump11289f42009-09-09 15:08:12 +00001678
1679
Douglas Gregore922c772009-08-04 22:27:00 +00001680template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001681Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 if (!E)
1683 return SemaRef.Owned(E);
1684
1685 switch (E->getStmtClass()) {
1686 case Stmt::NoStmtClass: break;
1687#define STMT(Node, Parent) case Stmt::Node##Class: break;
1688#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001689 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001690#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001691 }
1692
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001694}
1695
1696template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001697NestedNameSpecifier *
1698TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001699 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001700 QualType ObjectType,
1701 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001702 if (!NNS)
1703 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregorebe10102009-08-20 07:17:43 +00001705 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001706 NestedNameSpecifier *Prefix = NNS->getPrefix();
1707 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001708 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001709 ObjectType,
1710 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001711 if (!Prefix)
1712 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001713
1714 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001715 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001716 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001717 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001718 }
Mike Stump11289f42009-09-09 15:08:12 +00001719
Douglas Gregor1135c352009-08-06 05:28:30 +00001720 switch (NNS->getKind()) {
1721 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001722 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001723 "Identifier nested-name-specifier with no prefix or object type");
1724 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1725 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001726 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001727
1728 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001729 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001730 ObjectType,
1731 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregor1135c352009-08-06 05:28:30 +00001733 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001734 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001735 = cast_or_null<NamespaceDecl>(
1736 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001737 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001738 Prefix == NNS->getPrefix() &&
1739 NS == NNS->getAsNamespace())
1740 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1743 }
Mike Stump11289f42009-09-09 15:08:12 +00001744
Douglas Gregor1135c352009-08-06 05:28:30 +00001745 case NestedNameSpecifier::Global:
1746 // There is no meaningful transformation that one could perform on the
1747 // global scope.
1748 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregor1135c352009-08-06 05:28:30 +00001750 case NestedNameSpecifier::TypeSpecWithTemplate:
1751 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001752 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001754 if (T.isNull())
1755 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 if (!getDerived().AlwaysRebuild() &&
1758 Prefix == NNS->getPrefix() &&
1759 T == QualType(NNS->getAsType(), 0))
1760 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001761
1762 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1763 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001764 T);
1765 }
1766 }
Mike Stump11289f42009-09-09 15:08:12 +00001767
Douglas Gregor1135c352009-08-06 05:28:30 +00001768 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001769 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001770}
1771
1772template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001773DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001774TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001775 SourceLocation Loc,
1776 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001777 if (!Name)
1778 return Name;
1779
1780 switch (Name.getNameKind()) {
1781 case DeclarationName::Identifier:
1782 case DeclarationName::ObjCZeroArgSelector:
1783 case DeclarationName::ObjCOneArgSelector:
1784 case DeclarationName::ObjCMultiArgSelector:
1785 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001786 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001787 case DeclarationName::CXXUsingDirective:
1788 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790 case DeclarationName::CXXConstructorName:
1791 case DeclarationName::CXXDestructorName:
1792 case DeclarationName::CXXConversionFunctionName: {
1793 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001794 QualType T;
1795 if (!ObjectType.isNull() &&
1796 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1797 TemplateSpecializationType *SpecType
1798 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1799 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1800 } else
1801 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001802 if (T.isNull())
1803 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregorf816bd72009-09-03 22:13:48 +00001805 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001806 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001807 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001808 }
Mike Stump11289f42009-09-09 15:08:12 +00001809 }
1810
Douglas Gregorf816bd72009-09-03 22:13:48 +00001811 return DeclarationName();
1812}
1813
1814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001815TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001816TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1817 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001819 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001820 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1821 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1822 if (!NNS)
1823 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregor71dc5092009-08-06 06:41:21 +00001825 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001826 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001827 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1828 if (!TransTemplate)
1829 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001830
Douglas Gregor71dc5092009-08-06 06:41:21 +00001831 if (!getDerived().AlwaysRebuild() &&
1832 NNS == QTN->getQualifier() &&
1833 TransTemplate == Template)
1834 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregor71dc5092009-08-06 06:41:21 +00001836 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1837 TransTemplate);
1838 }
Mike Stump11289f42009-09-09 15:08:12 +00001839
John McCalle66edc12009-11-24 19:00:30 +00001840 // These should be getting filtered out before they make it into the AST.
1841 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregor71dc5092009-08-06 06:41:21 +00001844 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001845 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1847 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001848 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001852 NNS == DTN->getQualifier() &&
1853 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001854 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71395fa2009-11-04 00:56:37 +00001856 if (DTN->isIdentifier())
1857 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1858 ObjectType);
1859
1860 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1861 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001862 }
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001865 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1867 if (!TransTemplate)
1868 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001869
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 if (!getDerived().AlwaysRebuild() &&
1871 TransTemplate == Template)
1872 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 return TemplateName(TransTemplate);
1875 }
Mike Stump11289f42009-09-09 15:08:12 +00001876
John McCalle66edc12009-11-24 19:00:30 +00001877 // These should be getting filtered out before they reach the AST.
1878 assert(false && "overloaded function decl survived to here");
1879 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001880}
1881
1882template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001883void TreeTransform<Derived>::InventTemplateArgumentLoc(
1884 const TemplateArgument &Arg,
1885 TemplateArgumentLoc &Output) {
1886 SourceLocation Loc = getDerived().getBaseLocation();
1887 switch (Arg.getKind()) {
1888 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001889 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001890 break;
1891
1892 case TemplateArgument::Type:
1893 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001894 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001895
1896 break;
1897
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001898 case TemplateArgument::Template:
1899 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1900 break;
1901
John McCall0ad16662009-10-29 08:12:44 +00001902 case TemplateArgument::Expression:
1903 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1904 break;
1905
1906 case TemplateArgument::Declaration:
1907 case TemplateArgument::Integral:
1908 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001909 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001910 break;
1911 }
1912}
1913
1914template<typename Derived>
1915bool TreeTransform<Derived>::TransformTemplateArgument(
1916 const TemplateArgumentLoc &Input,
1917 TemplateArgumentLoc &Output) {
1918 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001919 switch (Arg.getKind()) {
1920 case TemplateArgument::Null:
1921 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001922 Output = Input;
1923 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregore922c772009-08-04 22:27:00 +00001925 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001926 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001927 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001928 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001929
1930 DI = getDerived().TransformType(DI);
1931 if (!DI) return true;
1932
1933 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1934 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001935 }
Mike Stump11289f42009-09-09 15:08:12 +00001936
Douglas Gregore922c772009-08-04 22:27:00 +00001937 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001938 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001939 DeclarationName Name;
1940 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1941 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001942 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001943 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001944 if (!D) return true;
1945
John McCall0d07eb32009-10-29 18:45:58 +00001946 Expr *SourceExpr = Input.getSourceDeclExpression();
1947 if (SourceExpr) {
1948 EnterExpressionEvaluationContext Unevaluated(getSema(),
1949 Action::Unevaluated);
1950 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1951 if (E.isInvalid())
1952 SourceExpr = NULL;
1953 else {
1954 SourceExpr = E.takeAs<Expr>();
1955 SourceExpr->Retain();
1956 }
1957 }
1958
1959 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001960 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001963 case TemplateArgument::Template: {
1964 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1965 TemplateName Template
1966 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1967 if (Template.isNull())
1968 return true;
1969
1970 Output = TemplateArgumentLoc(TemplateArgument(Template),
1971 Input.getTemplateQualifierRange(),
1972 Input.getTemplateNameLoc());
1973 return false;
1974 }
1975
Douglas Gregore922c772009-08-04 22:27:00 +00001976 case TemplateArgument::Expression: {
1977 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001978 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001979 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001980
John McCall0ad16662009-10-29 08:12:44 +00001981 Expr *InputExpr = Input.getSourceExpression();
1982 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1983
1984 Sema::OwningExprResult E
1985 = getDerived().TransformExpr(InputExpr);
1986 if (E.isInvalid()) return true;
1987
1988 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001989 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001990 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1991 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001992 }
Mike Stump11289f42009-09-09 15:08:12 +00001993
Douglas Gregore922c772009-08-04 22:27:00 +00001994 case TemplateArgument::Pack: {
1995 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1996 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001997 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001998 AEnd = Arg.pack_end();
1999 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002000
John McCall0ad16662009-10-29 08:12:44 +00002001 // FIXME: preserve source information here when we start
2002 // caring about parameter packs.
2003
John McCall0d07eb32009-10-29 18:45:58 +00002004 TemplateArgumentLoc InputArg;
2005 TemplateArgumentLoc OutputArg;
2006 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2007 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002008 return true;
2009
John McCall0d07eb32009-10-29 18:45:58 +00002010 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002011 }
2012 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002013 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002014 true);
John McCall0d07eb32009-10-29 18:45:58 +00002015 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002016 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002017 }
2018 }
Mike Stump11289f42009-09-09 15:08:12 +00002019
Douglas Gregore922c772009-08-04 22:27:00 +00002020 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002021 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002022}
2023
Douglas Gregord6ff3322009-08-04 16:50:30 +00002024//===----------------------------------------------------------------------===//
2025// Type transformation
2026//===----------------------------------------------------------------------===//
2027
2028template<typename Derived>
2029QualType TreeTransform<Derived>::TransformType(QualType T) {
2030 if (getDerived().AlreadyTransformed(T))
2031 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002032
John McCall550e0c22009-10-21 00:40:46 +00002033 // Temporary workaround. All of these transformations should
2034 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002035 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002036 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002037
John McCallbcd03502009-12-07 02:54:59 +00002038 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002039
John McCall550e0c22009-10-21 00:40:46 +00002040 if (!NewDI)
2041 return QualType();
2042
2043 return NewDI->getType();
2044}
2045
2046template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002047TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002048 if (getDerived().AlreadyTransformed(DI->getType()))
2049 return DI;
2050
2051 TypeLocBuilder TLB;
2052
2053 TypeLoc TL = DI->getTypeLoc();
2054 TLB.reserve(TL.getFullDataSize());
2055
2056 QualType Result = getDerived().TransformType(TLB, TL);
2057 if (Result.isNull())
2058 return 0;
2059
John McCallbcd03502009-12-07 02:54:59 +00002060 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002061}
2062
2063template<typename Derived>
2064QualType
2065TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2066 switch (T.getTypeLocClass()) {
2067#define ABSTRACT_TYPELOC(CLASS, PARENT)
2068#define TYPELOC(CLASS, PARENT) \
2069 case TypeLoc::CLASS: \
2070 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2071#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002072 }
Mike Stump11289f42009-09-09 15:08:12 +00002073
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002074 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002075 return QualType();
2076}
2077
2078/// FIXME: By default, this routine adds type qualifiers only to types
2079/// that can have qualifiers, and silently suppresses those qualifiers
2080/// that are not permitted (e.g., qualifiers on reference or function
2081/// types). This is the right thing for template instantiation, but
2082/// probably not for other clients.
2083template<typename Derived>
2084QualType
2085TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2086 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002087 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002088
2089 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2090 if (Result.isNull())
2091 return QualType();
2092
2093 // Silently suppress qualifiers if the result type can't be qualified.
2094 // FIXME: this is the right thing for template instantiation, but
2095 // probably not for other clients.
2096 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002097 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002098
John McCall550e0c22009-10-21 00:40:46 +00002099 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2100
2101 TLB.push<QualifiedTypeLoc>(Result);
2102
2103 // No location information to preserve.
2104
2105 return Result;
2106}
2107
2108template <class TyLoc> static inline
2109QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2110 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2111 NewT.setNameLoc(T.getNameLoc());
2112 return T.getType();
2113}
2114
2115// Ugly metaprogramming macros because I couldn't be bothered to make
2116// the equivalent template version work.
2117#define TransformPointerLikeType(TypeClass) do { \
2118 QualType PointeeType \
2119 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2120 if (PointeeType.isNull()) \
2121 return QualType(); \
2122 \
2123 QualType Result = TL.getType(); \
2124 if (getDerived().AlwaysRebuild() || \
2125 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002126 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2127 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002128 if (Result.isNull()) \
2129 return QualType(); \
2130 } \
2131 \
2132 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2133 NewT.setSigilLoc(TL.getSigilLoc()); \
2134 \
2135 return Result; \
2136} while(0)
2137
John McCall550e0c22009-10-21 00:40:46 +00002138template<typename Derived>
2139QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2140 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002141 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2142 NewT.setBuiltinLoc(T.getBuiltinLoc());
2143 if (T.needsExtraLocalData())
2144 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2145 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002146}
Mike Stump11289f42009-09-09 15:08:12 +00002147
Douglas Gregord6ff3322009-08-04 16:50:30 +00002148template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002149QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2150 ComplexTypeLoc T) {
2151 // FIXME: recurse?
2152 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002153}
Mike Stump11289f42009-09-09 15:08:12 +00002154
Douglas Gregord6ff3322009-08-04 16:50:30 +00002155template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002156QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2157 PointerTypeLoc TL) {
2158 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002159}
Mike Stump11289f42009-09-09 15:08:12 +00002160
2161template<typename Derived>
2162QualType
John McCall550e0c22009-10-21 00:40:46 +00002163TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2164 BlockPointerTypeLoc TL) {
2165 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002166}
2167
John McCall70dd5f62009-10-30 00:06:24 +00002168/// Transforms a reference type. Note that somewhat paradoxically we
2169/// don't care whether the type itself is an l-value type or an r-value
2170/// type; we only care if the type was *written* as an l-value type
2171/// or an r-value type.
2172template<typename Derived>
2173QualType
2174TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2175 ReferenceTypeLoc TL) {
2176 const ReferenceType *T = TL.getTypePtr();
2177
2178 // Note that this works with the pointee-as-written.
2179 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2180 if (PointeeType.isNull())
2181 return QualType();
2182
2183 QualType Result = TL.getType();
2184 if (getDerived().AlwaysRebuild() ||
2185 PointeeType != T->getPointeeTypeAsWritten()) {
2186 Result = getDerived().RebuildReferenceType(PointeeType,
2187 T->isSpelledAsLValue(),
2188 TL.getSigilLoc());
2189 if (Result.isNull())
2190 return QualType();
2191 }
2192
2193 // r-value references can be rebuilt as l-value references.
2194 ReferenceTypeLoc NewTL;
2195 if (isa<LValueReferenceType>(Result))
2196 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2197 else
2198 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2199 NewTL.setSigilLoc(TL.getSigilLoc());
2200
2201 return Result;
2202}
2203
Mike Stump11289f42009-09-09 15:08:12 +00002204template<typename Derived>
2205QualType
John McCall550e0c22009-10-21 00:40:46 +00002206TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2207 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002208 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002209}
2210
Mike Stump11289f42009-09-09 15:08:12 +00002211template<typename Derived>
2212QualType
John McCall550e0c22009-10-21 00:40:46 +00002213TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2214 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002215 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002216}
Mike Stump11289f42009-09-09 15:08:12 +00002217
Douglas Gregord6ff3322009-08-04 16:50:30 +00002218template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002219QualType
John McCall550e0c22009-10-21 00:40:46 +00002220TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2221 MemberPointerTypeLoc TL) {
2222 MemberPointerType *T = TL.getTypePtr();
2223
2224 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002225 if (PointeeType.isNull())
2226 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002227
John McCall550e0c22009-10-21 00:40:46 +00002228 // TODO: preserve source information for this.
2229 QualType ClassType
2230 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002231 if (ClassType.isNull())
2232 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002233
John McCall550e0c22009-10-21 00:40:46 +00002234 QualType Result = TL.getType();
2235 if (getDerived().AlwaysRebuild() ||
2236 PointeeType != T->getPointeeType() ||
2237 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002238 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2239 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002240 if (Result.isNull())
2241 return QualType();
2242 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002243
John McCall550e0c22009-10-21 00:40:46 +00002244 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2245 NewTL.setSigilLoc(TL.getSigilLoc());
2246
2247 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002248}
2249
Mike Stump11289f42009-09-09 15:08:12 +00002250template<typename Derived>
2251QualType
John McCall550e0c22009-10-21 00:40:46 +00002252TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2253 ConstantArrayTypeLoc TL) {
2254 ConstantArrayType *T = TL.getTypePtr();
2255 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256 if (ElementType.isNull())
2257 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002258
John McCall550e0c22009-10-21 00:40:46 +00002259 QualType Result = TL.getType();
2260 if (getDerived().AlwaysRebuild() ||
2261 ElementType != T->getElementType()) {
2262 Result = getDerived().RebuildConstantArrayType(ElementType,
2263 T->getSizeModifier(),
2264 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002265 T->getIndexTypeCVRQualifiers(),
2266 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002267 if (Result.isNull())
2268 return QualType();
2269 }
2270
2271 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2272 NewTL.setLBracketLoc(TL.getLBracketLoc());
2273 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002274
John McCall550e0c22009-10-21 00:40:46 +00002275 Expr *Size = TL.getSizeExpr();
2276 if (Size) {
2277 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2278 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2279 }
2280 NewTL.setSizeExpr(Size);
2281
2282 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002283}
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregord6ff3322009-08-04 16:50:30 +00002285template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002286QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002287 TypeLocBuilder &TLB,
2288 IncompleteArrayTypeLoc TL) {
2289 IncompleteArrayType *T = TL.getTypePtr();
2290 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002291 if (ElementType.isNull())
2292 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002293
John McCall550e0c22009-10-21 00:40:46 +00002294 QualType Result = TL.getType();
2295 if (getDerived().AlwaysRebuild() ||
2296 ElementType != T->getElementType()) {
2297 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002298 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002299 T->getIndexTypeCVRQualifiers(),
2300 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002301 if (Result.isNull())
2302 return QualType();
2303 }
2304
2305 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2306 NewTL.setLBracketLoc(TL.getLBracketLoc());
2307 NewTL.setRBracketLoc(TL.getRBracketLoc());
2308 NewTL.setSizeExpr(0);
2309
2310 return Result;
2311}
2312
2313template<typename Derived>
2314QualType
2315TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2316 VariableArrayTypeLoc TL) {
2317 VariableArrayType *T = TL.getTypePtr();
2318 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2319 if (ElementType.isNull())
2320 return QualType();
2321
2322 // Array bounds are not potentially evaluated contexts
2323 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2324
2325 Sema::OwningExprResult SizeResult
2326 = getDerived().TransformExpr(T->getSizeExpr());
2327 if (SizeResult.isInvalid())
2328 return QualType();
2329
2330 Expr *Size = static_cast<Expr*>(SizeResult.get());
2331
2332 QualType Result = TL.getType();
2333 if (getDerived().AlwaysRebuild() ||
2334 ElementType != T->getElementType() ||
2335 Size != T->getSizeExpr()) {
2336 Result = getDerived().RebuildVariableArrayType(ElementType,
2337 T->getSizeModifier(),
2338 move(SizeResult),
2339 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002340 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002341 if (Result.isNull())
2342 return QualType();
2343 }
2344 else SizeResult.take();
2345
2346 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2347 NewTL.setLBracketLoc(TL.getLBracketLoc());
2348 NewTL.setRBracketLoc(TL.getRBracketLoc());
2349 NewTL.setSizeExpr(Size);
2350
2351 return Result;
2352}
2353
2354template<typename Derived>
2355QualType
2356TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2357 DependentSizedArrayTypeLoc TL) {
2358 DependentSizedArrayType *T = TL.getTypePtr();
2359 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2360 if (ElementType.isNull())
2361 return QualType();
2362
2363 // Array bounds are not potentially evaluated contexts
2364 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2365
2366 Sema::OwningExprResult SizeResult
2367 = getDerived().TransformExpr(T->getSizeExpr());
2368 if (SizeResult.isInvalid())
2369 return QualType();
2370
2371 Expr *Size = static_cast<Expr*>(SizeResult.get());
2372
2373 QualType Result = TL.getType();
2374 if (getDerived().AlwaysRebuild() ||
2375 ElementType != T->getElementType() ||
2376 Size != T->getSizeExpr()) {
2377 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2378 T->getSizeModifier(),
2379 move(SizeResult),
2380 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002381 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002382 if (Result.isNull())
2383 return QualType();
2384 }
2385 else SizeResult.take();
2386
2387 // We might have any sort of array type now, but fortunately they
2388 // all have the same location layout.
2389 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2390 NewTL.setLBracketLoc(TL.getLBracketLoc());
2391 NewTL.setRBracketLoc(TL.getRBracketLoc());
2392 NewTL.setSizeExpr(Size);
2393
2394 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002395}
Mike Stump11289f42009-09-09 15:08:12 +00002396
2397template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002398QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002399 TypeLocBuilder &TLB,
2400 DependentSizedExtVectorTypeLoc TL) {
2401 DependentSizedExtVectorType *T = TL.getTypePtr();
2402
2403 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002404 QualType ElementType = getDerived().TransformType(T->getElementType());
2405 if (ElementType.isNull())
2406 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002407
Douglas Gregore922c772009-08-04 22:27:00 +00002408 // Vector sizes are not potentially evaluated contexts
2409 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2410
Douglas Gregord6ff3322009-08-04 16:50:30 +00002411 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2412 if (Size.isInvalid())
2413 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002414
John McCall550e0c22009-10-21 00:40:46 +00002415 QualType Result = TL.getType();
2416 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002417 ElementType != T->getElementType() ||
2418 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002419 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420 move(Size),
2421 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002422 if (Result.isNull())
2423 return QualType();
2424 }
2425 else Size.take();
2426
2427 // Result might be dependent or not.
2428 if (isa<DependentSizedExtVectorType>(Result)) {
2429 DependentSizedExtVectorTypeLoc NewTL
2430 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2431 NewTL.setNameLoc(TL.getNameLoc());
2432 } else {
2433 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2434 NewTL.setNameLoc(TL.getNameLoc());
2435 }
2436
2437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438}
Mike Stump11289f42009-09-09 15:08:12 +00002439
2440template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002441QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2442 VectorTypeLoc TL) {
2443 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002444 QualType ElementType = getDerived().TransformType(T->getElementType());
2445 if (ElementType.isNull())
2446 return QualType();
2447
John McCall550e0c22009-10-21 00:40:46 +00002448 QualType Result = TL.getType();
2449 if (getDerived().AlwaysRebuild() ||
2450 ElementType != T->getElementType()) {
2451 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2452 if (Result.isNull())
2453 return QualType();
2454 }
2455
2456 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2457 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002458
John McCall550e0c22009-10-21 00:40:46 +00002459 return Result;
2460}
2461
2462template<typename Derived>
2463QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2464 ExtVectorTypeLoc TL) {
2465 VectorType *T = TL.getTypePtr();
2466 QualType ElementType = getDerived().TransformType(T->getElementType());
2467 if (ElementType.isNull())
2468 return QualType();
2469
2470 QualType Result = TL.getType();
2471 if (getDerived().AlwaysRebuild() ||
2472 ElementType != T->getElementType()) {
2473 Result = getDerived().RebuildExtVectorType(ElementType,
2474 T->getNumElements(),
2475 /*FIXME*/ SourceLocation());
2476 if (Result.isNull())
2477 return QualType();
2478 }
2479
2480 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2481 NewTL.setNameLoc(TL.getNameLoc());
2482
2483 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484}
Mike Stump11289f42009-09-09 15:08:12 +00002485
2486template<typename Derived>
2487QualType
John McCall550e0c22009-10-21 00:40:46 +00002488TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2489 FunctionProtoTypeLoc TL) {
2490 FunctionProtoType *T = TL.getTypePtr();
2491 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002492 if (ResultType.isNull())
2493 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002494
John McCall550e0c22009-10-21 00:40:46 +00002495 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002496 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002497 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2498 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2499 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002500
John McCall550e0c22009-10-21 00:40:46 +00002501 QualType NewType;
2502 ParmVarDecl *NewParm;
2503
2504 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002505 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002506 assert(OldDI->getType() == T->getArgType(i));
2507
John McCallbcd03502009-12-07 02:54:59 +00002508 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002509 if (!NewDI)
2510 return QualType();
2511
2512 if (NewDI == OldDI)
2513 NewParm = OldParm;
2514 else
2515 NewParm = ParmVarDecl::Create(SemaRef.Context,
2516 OldParm->getDeclContext(),
2517 OldParm->getLocation(),
2518 OldParm->getIdentifier(),
2519 NewDI->getType(),
2520 NewDI,
2521 OldParm->getStorageClass(),
2522 /* DefArg */ NULL);
2523 NewType = NewParm->getType();
2524
2525 // Deal with the possibility that we don't have a parameter
2526 // declaration for this parameter.
2527 } else {
2528 NewParm = 0;
2529
2530 QualType OldType = T->getArgType(i);
2531 NewType = getDerived().TransformType(OldType);
2532 if (NewType.isNull())
2533 return QualType();
2534 }
2535
2536 ParamTypes.push_back(NewType);
2537 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002538 }
Mike Stump11289f42009-09-09 15:08:12 +00002539
John McCall550e0c22009-10-21 00:40:46 +00002540 QualType Result = TL.getType();
2541 if (getDerived().AlwaysRebuild() ||
2542 ResultType != T->getResultType() ||
2543 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2544 Result = getDerived().RebuildFunctionProtoType(ResultType,
2545 ParamTypes.data(),
2546 ParamTypes.size(),
2547 T->isVariadic(),
2548 T->getTypeQuals());
2549 if (Result.isNull())
2550 return QualType();
2551 }
Mike Stump11289f42009-09-09 15:08:12 +00002552
John McCall550e0c22009-10-21 00:40:46 +00002553 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2554 NewTL.setLParenLoc(TL.getLParenLoc());
2555 NewTL.setRParenLoc(TL.getRParenLoc());
2556 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2557 NewTL.setArg(i, ParamDecls[i]);
2558
2559 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002560}
Mike Stump11289f42009-09-09 15:08:12 +00002561
Douglas Gregord6ff3322009-08-04 16:50:30 +00002562template<typename Derived>
2563QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002564 TypeLocBuilder &TLB,
2565 FunctionNoProtoTypeLoc TL) {
2566 FunctionNoProtoType *T = TL.getTypePtr();
2567 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2568 if (ResultType.isNull())
2569 return QualType();
2570
2571 QualType Result = TL.getType();
2572 if (getDerived().AlwaysRebuild() ||
2573 ResultType != T->getResultType())
2574 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2575
2576 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2577 NewTL.setLParenLoc(TL.getLParenLoc());
2578 NewTL.setRParenLoc(TL.getRParenLoc());
2579
2580 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581}
Mike Stump11289f42009-09-09 15:08:12 +00002582
John McCallb96ec562009-12-04 22:46:56 +00002583template<typename Derived> QualType
2584TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2585 UnresolvedUsingTypeLoc TL) {
2586 UnresolvedUsingType *T = TL.getTypePtr();
2587 Decl *D = getDerived().TransformDecl(T->getDecl());
2588 if (!D)
2589 return QualType();
2590
2591 QualType Result = TL.getType();
2592 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2593 Result = getDerived().RebuildUnresolvedUsingType(D);
2594 if (Result.isNull())
2595 return QualType();
2596 }
2597
2598 // We might get an arbitrary type spec type back. We should at
2599 // least always get a type spec type, though.
2600 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2601 NewTL.setNameLoc(TL.getNameLoc());
2602
2603 return Result;
2604}
2605
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002607QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2608 TypedefTypeLoc TL) {
2609 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610 TypedefDecl *Typedef
2611 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2612 if (!Typedef)
2613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 Typedef != T->getDecl()) {
2618 Result = getDerived().RebuildTypedefType(Typedef);
2619 if (Result.isNull())
2620 return QualType();
2621 }
Mike Stump11289f42009-09-09 15:08:12 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2624 NewTL.setNameLoc(TL.getNameLoc());
2625
2626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627}
Mike Stump11289f42009-09-09 15:08:12 +00002628
Douglas Gregord6ff3322009-08-04 16:50:30 +00002629template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002630QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2631 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00002632 // typeof expressions are not potentially evaluated contexts
2633 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002634
John McCalle8595032010-01-13 20:03:27 +00002635 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002636 if (E.isInvalid())
2637 return QualType();
2638
John McCall550e0c22009-10-21 00:40:46 +00002639 QualType Result = TL.getType();
2640 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002641 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002642 Result = getDerived().RebuildTypeOfExprType(move(E));
2643 if (Result.isNull())
2644 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 }
John McCall550e0c22009-10-21 00:40:46 +00002646 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002647
John McCall550e0c22009-10-21 00:40:46 +00002648 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002649 NewTL.setTypeofLoc(TL.getTypeofLoc());
2650 NewTL.setLParenLoc(TL.getLParenLoc());
2651 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002652
2653 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002654}
Mike Stump11289f42009-09-09 15:08:12 +00002655
2656template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002657QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2658 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002659 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2660 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2661 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002663
John McCall550e0c22009-10-21 00:40:46 +00002664 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002665 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2666 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002667 if (Result.isNull())
2668 return QualType();
2669 }
Mike Stump11289f42009-09-09 15:08:12 +00002670
John McCall550e0c22009-10-21 00:40:46 +00002671 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002672 NewTL.setTypeofLoc(TL.getTypeofLoc());
2673 NewTL.setLParenLoc(TL.getLParenLoc());
2674 NewTL.setRParenLoc(TL.getRParenLoc());
2675 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002676
2677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678}
Mike Stump11289f42009-09-09 15:08:12 +00002679
2680template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002681QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2682 DecltypeTypeLoc TL) {
2683 DecltypeType *T = TL.getTypePtr();
2684
Douglas Gregore922c772009-08-04 22:27:00 +00002685 // decltype expressions are not potentially evaluated contexts
2686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002687
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2689 if (E.isInvalid())
2690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002691
John McCall550e0c22009-10-21 00:40:46 +00002692 QualType Result = TL.getType();
2693 if (getDerived().AlwaysRebuild() ||
2694 E.get() != T->getUnderlyingExpr()) {
2695 Result = getDerived().RebuildDecltypeType(move(E));
2696 if (Result.isNull())
2697 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002698 }
John McCall550e0c22009-10-21 00:40:46 +00002699 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002700
John McCall550e0c22009-10-21 00:40:46 +00002701 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2702 NewTL.setNameLoc(TL.getNameLoc());
2703
2704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002705}
2706
2707template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002708QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2709 RecordTypeLoc TL) {
2710 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002711 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002712 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002713 if (!Record)
2714 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002715
John McCall550e0c22009-10-21 00:40:46 +00002716 QualType Result = TL.getType();
2717 if (getDerived().AlwaysRebuild() ||
2718 Record != T->getDecl()) {
2719 Result = getDerived().RebuildRecordType(Record);
2720 if (Result.isNull())
2721 return QualType();
2722 }
Mike Stump11289f42009-09-09 15:08:12 +00002723
John McCall550e0c22009-10-21 00:40:46 +00002724 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2725 NewTL.setNameLoc(TL.getNameLoc());
2726
2727 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002728}
Mike Stump11289f42009-09-09 15:08:12 +00002729
2730template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002731QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2732 EnumTypeLoc TL) {
2733 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002735 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736 if (!Enum)
2737 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002738
John McCall550e0c22009-10-21 00:40:46 +00002739 QualType Result = TL.getType();
2740 if (getDerived().AlwaysRebuild() ||
2741 Enum != T->getDecl()) {
2742 Result = getDerived().RebuildEnumType(Enum);
2743 if (Result.isNull())
2744 return QualType();
2745 }
Mike Stump11289f42009-09-09 15:08:12 +00002746
John McCall550e0c22009-10-21 00:40:46 +00002747 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2748 NewTL.setNameLoc(TL.getNameLoc());
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
John McCallfcc33b02009-09-05 00:15:47 +00002752
2753template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002754QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2755 ElaboratedTypeLoc TL) {
2756 ElaboratedType *T = TL.getTypePtr();
2757
2758 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002759 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2760 if (Underlying.isNull())
2761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall550e0c22009-10-21 00:40:46 +00002763 QualType Result = TL.getType();
2764 if (getDerived().AlwaysRebuild() ||
2765 Underlying != T->getUnderlyingType()) {
2766 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2767 if (Result.isNull())
2768 return QualType();
2769 }
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2772 NewTL.setNameLoc(TL.getNameLoc());
2773
2774 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002775}
Mike Stump11289f42009-09-09 15:08:12 +00002776
2777
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778template<typename Derived>
2779QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002780 TypeLocBuilder &TLB,
2781 TemplateTypeParmTypeLoc TL) {
2782 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002783}
2784
Mike Stump11289f42009-09-09 15:08:12 +00002785template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002786QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002787 TypeLocBuilder &TLB,
2788 SubstTemplateTypeParmTypeLoc TL) {
2789 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002790}
2791
2792template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002793inline QualType
2794TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002795 TypeLocBuilder &TLB,
2796 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002797 return TransformTemplateSpecializationType(TLB, TL, QualType());
2798}
John McCall550e0c22009-10-21 00:40:46 +00002799
John McCall0ad16662009-10-29 08:12:44 +00002800template<typename Derived>
2801QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2802 const TemplateSpecializationType *TST,
2803 QualType ObjectType) {
2804 // FIXME: this entire method is a temporary workaround; callers
2805 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002806
John McCall0ad16662009-10-29 08:12:44 +00002807 // Fake up a TemplateSpecializationTypeLoc.
2808 TypeLocBuilder TLB;
2809 TemplateSpecializationTypeLoc TL
2810 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2811
John McCall0d07eb32009-10-29 18:45:58 +00002812 SourceLocation BaseLoc = getDerived().getBaseLocation();
2813
2814 TL.setTemplateNameLoc(BaseLoc);
2815 TL.setLAngleLoc(BaseLoc);
2816 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002817 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2818 const TemplateArgument &TA = TST->getArg(i);
2819 TemplateArgumentLoc TAL;
2820 getDerived().InventTemplateArgumentLoc(TA, TAL);
2821 TL.setArgLocInfo(i, TAL.getLocInfo());
2822 }
2823
2824 TypeLocBuilder IgnoredTLB;
2825 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002826}
2827
2828template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002829QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002830 TypeLocBuilder &TLB,
2831 TemplateSpecializationTypeLoc TL,
2832 QualType ObjectType) {
2833 const TemplateSpecializationType *T = TL.getTypePtr();
2834
Mike Stump11289f42009-09-09 15:08:12 +00002835 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002836 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 if (Template.isNull())
2838 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002839
John McCall6b51f282009-11-23 01:53:49 +00002840 TemplateArgumentListInfo NewTemplateArgs;
2841 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2842 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2843
2844 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2845 TemplateArgumentLoc Loc;
2846 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002847 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002848 NewTemplateArgs.addArgument(Loc);
2849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
John McCall0ad16662009-10-29 08:12:44 +00002851 // FIXME: maybe don't rebuild if all the template arguments are the same.
2852
2853 QualType Result =
2854 getDerived().RebuildTemplateSpecializationType(Template,
2855 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002856 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002857
2858 if (!Result.isNull()) {
2859 TemplateSpecializationTypeLoc NewTL
2860 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2861 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2862 NewTL.setLAngleLoc(TL.getLAngleLoc());
2863 NewTL.setRAngleLoc(TL.getRAngleLoc());
2864 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2865 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002866 }
Mike Stump11289f42009-09-09 15:08:12 +00002867
John McCall0ad16662009-10-29 08:12:44 +00002868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869}
Mike Stump11289f42009-09-09 15:08:12 +00002870
2871template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002872QualType
2873TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2874 QualifiedNameTypeLoc TL) {
2875 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002876 NestedNameSpecifier *NNS
2877 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2878 SourceRange());
2879 if (!NNS)
2880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002881
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882 QualType Named = getDerived().TransformType(T->getNamedType());
2883 if (Named.isNull())
2884 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002885
John McCall550e0c22009-10-21 00:40:46 +00002886 QualType Result = TL.getType();
2887 if (getDerived().AlwaysRebuild() ||
2888 NNS != T->getQualifier() ||
2889 Named != T->getNamedType()) {
2890 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2891 if (Result.isNull())
2892 return QualType();
2893 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002894
John McCall550e0c22009-10-21 00:40:46 +00002895 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2896 NewTL.setNameLoc(TL.getNameLoc());
2897
2898 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899}
Mike Stump11289f42009-09-09 15:08:12 +00002900
2901template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002902QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2903 TypenameTypeLoc TL) {
2904 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002905
2906 /* FIXME: preserve source information better than this */
2907 SourceRange SR(TL.getNameLoc());
2908
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002910 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 if (!NNS)
2912 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002913
John McCall550e0c22009-10-21 00:40:46 +00002914 QualType Result;
2915
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002917 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918 = getDerived().TransformType(QualType(TemplateId, 0));
2919 if (NewTemplateId.isNull())
2920 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002921
Douglas Gregord6ff3322009-08-04 16:50:30 +00002922 if (!getDerived().AlwaysRebuild() &&
2923 NNS == T->getQualifier() &&
2924 NewTemplateId == QualType(TemplateId, 0))
2925 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002926
John McCall550e0c22009-10-21 00:40:46 +00002927 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2928 } else {
John McCall0ad16662009-10-29 08:12:44 +00002929 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930 }
John McCall550e0c22009-10-21 00:40:46 +00002931 if (Result.isNull())
2932 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2935 NewTL.setNameLoc(TL.getNameLoc());
2936
2937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938}
Mike Stump11289f42009-09-09 15:08:12 +00002939
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002941QualType
2942TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2943 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002944 assert(false && "TransformObjCInterfaceType unimplemented");
2945 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946}
Mike Stump11289f42009-09-09 15:08:12 +00002947
2948template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002949QualType
2950TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2951 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002952 assert(false && "TransformObjCObjectPointerType unimplemented");
2953 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002954}
2955
Douglas Gregord6ff3322009-08-04 16:50:30 +00002956//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002957// Statement transformation
2958//===----------------------------------------------------------------------===//
2959template<typename Derived>
2960Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002961TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2962 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002963}
2964
2965template<typename Derived>
2966Sema::OwningStmtResult
2967TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2968 return getDerived().TransformCompoundStmt(S, false);
2969}
2970
2971template<typename Derived>
2972Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002973TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002974 bool IsStmtExpr) {
2975 bool SubStmtChanged = false;
2976 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2977 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2978 B != BEnd; ++B) {
2979 OwningStmtResult Result = getDerived().TransformStmt(*B);
2980 if (Result.isInvalid())
2981 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregorebe10102009-08-20 07:17:43 +00002983 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2984 Statements.push_back(Result.takeAs<Stmt>());
2985 }
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregorebe10102009-08-20 07:17:43 +00002987 if (!getDerived().AlwaysRebuild() &&
2988 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002989 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002990
2991 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2992 move_arg(Statements),
2993 S->getRBracLoc(),
2994 IsStmtExpr);
2995}
Mike Stump11289f42009-09-09 15:08:12 +00002996
Douglas Gregorebe10102009-08-20 07:17:43 +00002997template<typename Derived>
2998Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002999TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003000 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3001 {
3002 // The case value expressions are not potentially evaluated.
3003 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003004
Eli Friedman06577382009-11-19 03:14:00 +00003005 // Transform the left-hand case value.
3006 LHS = getDerived().TransformExpr(S->getLHS());
3007 if (LHS.isInvalid())
3008 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003009
Eli Friedman06577382009-11-19 03:14:00 +00003010 // Transform the right-hand case value (for the GNU case-range extension).
3011 RHS = getDerived().TransformExpr(S->getRHS());
3012 if (RHS.isInvalid())
3013 return SemaRef.StmtError();
3014 }
Mike Stump11289f42009-09-09 15:08:12 +00003015
Douglas Gregorebe10102009-08-20 07:17:43 +00003016 // Build the case statement.
3017 // Case statements are always rebuilt so that they will attached to their
3018 // transformed switch statement.
3019 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3020 move(LHS),
3021 S->getEllipsisLoc(),
3022 move(RHS),
3023 S->getColonLoc());
3024 if (Case.isInvalid())
3025 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003026
Douglas Gregorebe10102009-08-20 07:17:43 +00003027 // Transform the statement following the case
3028 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3029 if (SubStmt.isInvalid())
3030 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003031
Douglas Gregorebe10102009-08-20 07:17:43 +00003032 // Attach the body to the case statement
3033 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3034}
3035
3036template<typename Derived>
3037Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003038TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003039 // Transform the statement following the default case
3040 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3041 if (SubStmt.isInvalid())
3042 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003043
Douglas Gregorebe10102009-08-20 07:17:43 +00003044 // Default statements are always rebuilt
3045 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3046 move(SubStmt));
3047}
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregorebe10102009-08-20 07:17:43 +00003049template<typename Derived>
3050Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003051TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003052 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3053 if (SubStmt.isInvalid())
3054 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregorebe10102009-08-20 07:17:43 +00003056 // FIXME: Pass the real colon location in.
3057 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3058 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3059 move(SubStmt));
3060}
Mike Stump11289f42009-09-09 15:08:12 +00003061
Douglas Gregorebe10102009-08-20 07:17:43 +00003062template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003063Sema::OwningStmtResult
3064TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003065 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003066 OwningExprResult Cond(SemaRef);
3067 VarDecl *ConditionVar = 0;
3068 if (S->getConditionVariable()) {
3069 ConditionVar
3070 = cast_or_null<VarDecl>(
3071 getDerived().TransformDefinition(S->getConditionVariable()));
3072 if (!ConditionVar)
3073 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003074 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003075 Cond = getDerived().TransformExpr(S->getCond());
3076
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003077 if (Cond.isInvalid())
3078 return SemaRef.StmtError();
3079 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003080
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003081 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083 // Transform the "then" branch.
3084 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3085 if (Then.isInvalid())
3086 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003087
Douglas Gregorebe10102009-08-20 07:17:43 +00003088 // Transform the "else" branch.
3089 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3090 if (Else.isInvalid())
3091 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003092
Douglas Gregorebe10102009-08-20 07:17:43 +00003093 if (!getDerived().AlwaysRebuild() &&
3094 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003095 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003096 Then.get() == S->getThen() &&
3097 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003098 return SemaRef.Owned(S->Retain());
3099
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003100 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3101 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003102 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003103}
3104
3105template<typename Derived>
3106Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003107TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003108 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003109 OwningExprResult Cond(SemaRef);
3110 VarDecl *ConditionVar = 0;
3111 if (S->getConditionVariable()) {
3112 ConditionVar
3113 = cast_or_null<VarDecl>(
3114 getDerived().TransformDefinition(S->getConditionVariable()));
3115 if (!ConditionVar)
3116 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003117 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003118 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003119
3120 if (Cond.isInvalid())
3121 return SemaRef.StmtError();
3122 }
Mike Stump11289f42009-09-09 15:08:12 +00003123
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003124 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003125
Douglas Gregorebe10102009-08-20 07:17:43 +00003126 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003127 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3128 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003129 if (Switch.isInvalid())
3130 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Transform the body of the switch statement.
3133 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3134 if (Body.isInvalid())
3135 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003136
Douglas Gregorebe10102009-08-20 07:17:43 +00003137 // Complete the switch statement.
3138 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3139 move(Body));
3140}
Mike Stump11289f42009-09-09 15:08:12 +00003141
Douglas Gregorebe10102009-08-20 07:17:43 +00003142template<typename Derived>
3143Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003144TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003145 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003146 OwningExprResult Cond(SemaRef);
3147 VarDecl *ConditionVar = 0;
3148 if (S->getConditionVariable()) {
3149 ConditionVar
3150 = cast_or_null<VarDecl>(
3151 getDerived().TransformDefinition(S->getConditionVariable()));
3152 if (!ConditionVar)
3153 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003154 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003155 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003156
3157 if (Cond.isInvalid())
3158 return SemaRef.StmtError();
3159 }
Mike Stump11289f42009-09-09 15:08:12 +00003160
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003161 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003162
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 // Transform the body
3164 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3165 if (Body.isInvalid())
3166 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003167
Douglas Gregorebe10102009-08-20 07:17:43 +00003168 if (!getDerived().AlwaysRebuild() &&
3169 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003170 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003171 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003172 return SemaRef.Owned(S->Retain());
3173
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003174 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3175 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003176}
Mike Stump11289f42009-09-09 15:08:12 +00003177
Douglas Gregorebe10102009-08-20 07:17:43 +00003178template<typename Derived>
3179Sema::OwningStmtResult
3180TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3181 // Transform the condition
3182 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3183 if (Cond.isInvalid())
3184 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003185
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 // Transform the body
3187 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3188 if (Body.isInvalid())
3189 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003190
Douglas Gregorebe10102009-08-20 07:17:43 +00003191 if (!getDerived().AlwaysRebuild() &&
3192 Cond.get() == S->getCond() &&
3193 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003194 return SemaRef.Owned(S->Retain());
3195
Douglas Gregorebe10102009-08-20 07:17:43 +00003196 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3197 /*FIXME:*/S->getWhileLoc(), move(Cond),
3198 S->getRParenLoc());
3199}
Mike Stump11289f42009-09-09 15:08:12 +00003200
Douglas Gregorebe10102009-08-20 07:17:43 +00003201template<typename Derived>
3202Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003203TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003204 // Transform the initialization statement
3205 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3206 if (Init.isInvalid())
3207 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregorebe10102009-08-20 07:17:43 +00003209 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003210 OwningExprResult Cond(SemaRef);
3211 VarDecl *ConditionVar = 0;
3212 if (S->getConditionVariable()) {
3213 ConditionVar
3214 = cast_or_null<VarDecl>(
3215 getDerived().TransformDefinition(S->getConditionVariable()));
3216 if (!ConditionVar)
3217 return SemaRef.StmtError();
3218 } else {
3219 Cond = getDerived().TransformExpr(S->getCond());
3220
3221 if (Cond.isInvalid())
3222 return SemaRef.StmtError();
3223 }
Mike Stump11289f42009-09-09 15:08:12 +00003224
Douglas Gregorebe10102009-08-20 07:17:43 +00003225 // Transform the increment
3226 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3227 if (Inc.isInvalid())
3228 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003229
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 // Transform the body
3231 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3232 if (Body.isInvalid())
3233 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 if (!getDerived().AlwaysRebuild() &&
3236 Init.get() == S->getInit() &&
3237 Cond.get() == S->getCond() &&
3238 Inc.get() == S->getInc() &&
3239 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003240 return SemaRef.Owned(S->Retain());
3241
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003243 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003244 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003245 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003246 S->getRParenLoc(), move(Body));
3247}
3248
3249template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003250Sema::OwningStmtResult
3251TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003252 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003253 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 S->getLabel());
3255}
3256
3257template<typename Derived>
3258Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003259TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003260 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3261 if (Target.isInvalid())
3262 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264 if (!getDerived().AlwaysRebuild() &&
3265 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003266 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003267
3268 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3269 move(Target));
3270}
3271
3272template<typename Derived>
3273Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003274TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3275 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003276}
Mike Stump11289f42009-09-09 15:08:12 +00003277
Douglas Gregorebe10102009-08-20 07:17:43 +00003278template<typename Derived>
3279Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003280TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3281 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003282}
Mike Stump11289f42009-09-09 15:08:12 +00003283
Douglas Gregorebe10102009-08-20 07:17:43 +00003284template<typename Derived>
3285Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003286TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3288 if (Result.isInvalid())
3289 return SemaRef.StmtError();
3290
Mike Stump11289f42009-09-09 15:08:12 +00003291 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 // to tell whether the return type of the function has changed.
3293 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3294}
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296template<typename Derived>
3297Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003298TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003299 bool DeclChanged = false;
3300 llvm::SmallVector<Decl *, 4> Decls;
3301 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3302 D != DEnd; ++D) {
3303 Decl *Transformed = getDerived().TransformDefinition(*D);
3304 if (!Transformed)
3305 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003306
Douglas Gregorebe10102009-08-20 07:17:43 +00003307 if (Transformed != *D)
3308 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregorebe10102009-08-20 07:17:43 +00003310 Decls.push_back(Transformed);
3311 }
Mike Stump11289f42009-09-09 15:08:12 +00003312
Douglas Gregorebe10102009-08-20 07:17:43 +00003313 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003314 return SemaRef.Owned(S->Retain());
3315
3316 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 S->getStartLoc(), S->getEndLoc());
3318}
Mike Stump11289f42009-09-09 15:08:12 +00003319
Douglas Gregorebe10102009-08-20 07:17:43 +00003320template<typename Derived>
3321Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003322TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003323 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003324 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003325}
3326
3327template<typename Derived>
3328Sema::OwningStmtResult
3329TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3330 // FIXME: Implement!
3331 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003332 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003333}
3334
3335
3336template<typename Derived>
3337Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003338TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003339 // FIXME: Implement this
3340 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003341 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003342}
Mike Stump11289f42009-09-09 15:08:12 +00003343
Douglas Gregorebe10102009-08-20 07:17:43 +00003344template<typename Derived>
3345Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003346TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003347 // FIXME: Implement this
3348 assert(false && "Cannot transform an Objective-C @catch statement");
3349 return SemaRef.Owned(S->Retain());
3350}
Mike Stump11289f42009-09-09 15:08:12 +00003351
Douglas Gregorebe10102009-08-20 07:17:43 +00003352template<typename Derived>
3353Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003354TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003355 // FIXME: Implement this
3356 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003357 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003358}
Mike Stump11289f42009-09-09 15:08:12 +00003359
Douglas Gregorebe10102009-08-20 07:17:43 +00003360template<typename Derived>
3361Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003362TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 // FIXME: Implement this
3364 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003365 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003366}
Mike Stump11289f42009-09-09 15:08:12 +00003367
Douglas Gregorebe10102009-08-20 07:17:43 +00003368template<typename Derived>
3369Sema::OwningStmtResult
3370TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003371 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003372 // FIXME: Implement this
3373 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003374 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003375}
3376
3377template<typename Derived>
3378Sema::OwningStmtResult
3379TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003380 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003381 // FIXME: Implement this
3382 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003383 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003384}
3385
3386
3387template<typename Derived>
3388Sema::OwningStmtResult
3389TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3390 // Transform the exception declaration, if any.
3391 VarDecl *Var = 0;
3392 if (S->getExceptionDecl()) {
3393 VarDecl *ExceptionDecl = S->getExceptionDecl();
3394 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3395 ExceptionDecl->getDeclName());
3396
3397 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3398 if (T.isNull())
3399 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003400
Douglas Gregorebe10102009-08-20 07:17:43 +00003401 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3402 T,
John McCallbcd03502009-12-07 02:54:59 +00003403 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003404 ExceptionDecl->getIdentifier(),
3405 ExceptionDecl->getLocation(),
3406 /*FIXME: Inaccurate*/
3407 SourceRange(ExceptionDecl->getLocation()));
3408 if (!Var || Var->isInvalidDecl()) {
3409 if (Var)
3410 Var->Destroy(SemaRef.Context);
3411 return SemaRef.StmtError();
3412 }
3413 }
Mike Stump11289f42009-09-09 15:08:12 +00003414
Douglas Gregorebe10102009-08-20 07:17:43 +00003415 // Transform the actual exception handler.
3416 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3417 if (Handler.isInvalid()) {
3418 if (Var)
3419 Var->Destroy(SemaRef.Context);
3420 return SemaRef.StmtError();
3421 }
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 if (!getDerived().AlwaysRebuild() &&
3424 !Var &&
3425 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003426 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003427
3428 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3429 Var,
3430 move(Handler));
3431}
Mike Stump11289f42009-09-09 15:08:12 +00003432
Douglas Gregorebe10102009-08-20 07:17:43 +00003433template<typename Derived>
3434Sema::OwningStmtResult
3435TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3436 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003437 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 = getDerived().TransformCompoundStmt(S->getTryBlock());
3439 if (TryBlock.isInvalid())
3440 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003441
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 // Transform the handlers.
3443 bool HandlerChanged = false;
3444 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3445 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003446 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003447 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3448 if (Handler.isInvalid())
3449 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003450
Douglas Gregorebe10102009-08-20 07:17:43 +00003451 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3452 Handlers.push_back(Handler.takeAs<Stmt>());
3453 }
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregorebe10102009-08-20 07:17:43 +00003455 if (!getDerived().AlwaysRebuild() &&
3456 TryBlock.get() == S->getTryBlock() &&
3457 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003458 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003459
3460 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003461 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003462}
Mike Stump11289f42009-09-09 15:08:12 +00003463
Douglas Gregorebe10102009-08-20 07:17:43 +00003464//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003465// Expression transformation
3466//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003467template<typename Derived>
3468Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003469TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003470 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003471}
Mike Stump11289f42009-09-09 15:08:12 +00003472
3473template<typename Derived>
3474Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003475TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003476 NestedNameSpecifier *Qualifier = 0;
3477 if (E->getQualifier()) {
3478 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3479 E->getQualifierRange());
3480 if (!Qualifier)
3481 return SemaRef.ExprError();
3482 }
John McCallce546572009-12-08 09:08:17 +00003483
3484 ValueDecl *ND
3485 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003486 if (!ND)
3487 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003489 if (!getDerived().AlwaysRebuild() &&
3490 Qualifier == E->getQualifier() &&
3491 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003492 !E->hasExplicitTemplateArgumentList()) {
3493
3494 // Mark it referenced in the new context regardless.
3495 // FIXME: this is a bit instantiation-specific.
3496 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3497
Mike Stump11289f42009-09-09 15:08:12 +00003498 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003499 }
John McCallce546572009-12-08 09:08:17 +00003500
3501 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3502 if (E->hasExplicitTemplateArgumentList()) {
3503 TemplateArgs = &TransArgs;
3504 TransArgs.setLAngleLoc(E->getLAngleLoc());
3505 TransArgs.setRAngleLoc(E->getRAngleLoc());
3506 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3507 TemplateArgumentLoc Loc;
3508 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3509 return SemaRef.ExprError();
3510 TransArgs.addArgument(Loc);
3511 }
3512 }
3513
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003514 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003515 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregora16548e2009-08-11 05:31:07 +00003518template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003520TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003521 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003522}
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregora16548e2009-08-11 05:31:07 +00003524template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003525Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003526TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003527 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003528}
Mike Stump11289f42009-09-09 15:08:12 +00003529
Douglas Gregora16548e2009-08-11 05:31:07 +00003530template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003531Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003532TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003533 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003534}
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregora16548e2009-08-11 05:31:07 +00003536template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003537Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003538TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003539 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003540}
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregora16548e2009-08-11 05:31:07 +00003542template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003543Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003544TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003545 return SemaRef.Owned(E->Retain());
3546}
3547
3548template<typename Derived>
3549Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003550TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003551 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3552 if (SubExpr.isInvalid())
3553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregora16548e2009-08-11 05:31:07 +00003555 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003556 return SemaRef.Owned(E->Retain());
3557
3558 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003559 E->getRParen());
3560}
3561
Mike Stump11289f42009-09-09 15:08:12 +00003562template<typename Derived>
3563Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003564TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3565 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003566 if (SubExpr.isInvalid())
3567 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003568
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003570 return SemaRef.Owned(E->Retain());
3571
Douglas Gregora16548e2009-08-11 05:31:07 +00003572 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3573 E->getOpcode(),
3574 move(SubExpr));
3575}
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregora16548e2009-08-11 05:31:07 +00003577template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003578Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003579TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003580 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003581 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003582
John McCallbcd03502009-12-07 02:54:59 +00003583 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003584 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003585 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003586
John McCall4c98fd82009-11-04 07:28:41 +00003587 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003588 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003589
John McCall4c98fd82009-11-04 07:28:41 +00003590 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003591 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003592 E->getSourceRange());
3593 }
Mike Stump11289f42009-09-09 15:08:12 +00003594
Douglas Gregora16548e2009-08-11 05:31:07 +00003595 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003596 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003597 // C++0x [expr.sizeof]p1:
3598 // The operand is either an expression, which is an unevaluated operand
3599 // [...]
3600 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003601
Douglas Gregora16548e2009-08-11 05:31:07 +00003602 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3603 if (SubExpr.isInvalid())
3604 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregora16548e2009-08-11 05:31:07 +00003606 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3607 return SemaRef.Owned(E->Retain());
3608 }
Mike Stump11289f42009-09-09 15:08:12 +00003609
Douglas Gregora16548e2009-08-11 05:31:07 +00003610 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3611 E->isSizeOf(),
3612 E->getSourceRange());
3613}
Mike Stump11289f42009-09-09 15:08:12 +00003614
Douglas Gregora16548e2009-08-11 05:31:07 +00003615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003616Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003617TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003618 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3619 if (LHS.isInvalid())
3620 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003621
Douglas Gregora16548e2009-08-11 05:31:07 +00003622 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3623 if (RHS.isInvalid())
3624 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003625
3626
Douglas Gregora16548e2009-08-11 05:31:07 +00003627 if (!getDerived().AlwaysRebuild() &&
3628 LHS.get() == E->getLHS() &&
3629 RHS.get() == E->getRHS())
3630 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003631
Douglas Gregora16548e2009-08-11 05:31:07 +00003632 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3633 /*FIXME:*/E->getLHS()->getLocStart(),
3634 move(RHS),
3635 E->getRBracketLoc());
3636}
Mike Stump11289f42009-09-09 15:08:12 +00003637
3638template<typename Derived>
3639Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003640TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 // Transform the callee.
3642 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3643 if (Callee.isInvalid())
3644 return SemaRef.ExprError();
3645
3646 // Transform arguments.
3647 bool ArgChanged = false;
3648 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3649 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3650 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3651 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3652 if (Arg.isInvalid())
3653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregora16548e2009-08-11 05:31:07 +00003655 // FIXME: Wrong source location information for the ','.
3656 FakeCommaLocs.push_back(
3657 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003658
3659 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003660 Args.push_back(Arg.takeAs<Expr>());
3661 }
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregora16548e2009-08-11 05:31:07 +00003663 if (!getDerived().AlwaysRebuild() &&
3664 Callee.get() == E->getCallee() &&
3665 !ArgChanged)
3666 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003669 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3671 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3672 move_arg(Args),
3673 FakeCommaLocs.data(),
3674 E->getRParenLoc());
3675}
Mike Stump11289f42009-09-09 15:08:12 +00003676
3677template<typename Derived>
3678Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003679TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003680 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3681 if (Base.isInvalid())
3682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003684 NestedNameSpecifier *Qualifier = 0;
3685 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003686 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003687 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3688 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003689 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003690 return SemaRef.ExprError();
3691 }
Mike Stump11289f42009-09-09 15:08:12 +00003692
Eli Friedman2cfcef62009-12-04 06:40:45 +00003693 ValueDecl *Member
3694 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003695 if (!Member)
3696 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003697
Douglas Gregora16548e2009-08-11 05:31:07 +00003698 if (!getDerived().AlwaysRebuild() &&
3699 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003700 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003701 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003702 !E->hasExplicitTemplateArgumentList()) {
3703
3704 // Mark it referenced in the new context regardless.
3705 // FIXME: this is a bit instantiation-specific.
3706 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003707 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003708 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003709
John McCall6b51f282009-11-23 01:53:49 +00003710 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003711 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003712 TransArgs.setLAngleLoc(E->getLAngleLoc());
3713 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003714 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003715 TemplateArgumentLoc Loc;
3716 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003717 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003718 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003719 }
3720 }
3721
Douglas Gregora16548e2009-08-11 05:31:07 +00003722 // FIXME: Bogus source location for the operator
3723 SourceLocation FakeOperatorLoc
3724 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3725
John McCall38836f02010-01-15 08:34:02 +00003726 // FIXME: to do this check properly, we will need to preserve the
3727 // first-qualifier-in-scope here, just in case we had a dependent
3728 // base (and therefore couldn't do the check) and a
3729 // nested-name-qualifier (and therefore could do the lookup).
3730 NamedDecl *FirstQualifierInScope = 0;
3731
Douglas Gregora16548e2009-08-11 05:31:07 +00003732 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3733 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003734 Qualifier,
3735 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003736 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003737 Member,
John McCall6b51f282009-11-23 01:53:49 +00003738 (E->hasExplicitTemplateArgumentList()
3739 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003740 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003741}
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003744Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003745TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003746 assert(false && "Cannot transform abstract class");
3747 return SemaRef.Owned(E->Retain());
3748}
3749
3750template<typename Derived>
3751Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003752TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003753 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3754 if (LHS.isInvalid())
3755 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3758 if (RHS.isInvalid())
3759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 if (!getDerived().AlwaysRebuild() &&
3762 LHS.get() == E->getLHS() &&
3763 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003764 return SemaRef.Owned(E->Retain());
3765
Douglas Gregora16548e2009-08-11 05:31:07 +00003766 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3767 move(LHS), move(RHS));
3768}
3769
Mike Stump11289f42009-09-09 15:08:12 +00003770template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003771Sema::OwningExprResult
3772TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003773 CompoundAssignOperator *E) {
3774 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003775}
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003778Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003779TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003780 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3781 if (Cond.isInvalid())
3782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003783
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3785 if (LHS.isInvalid())
3786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregora16548e2009-08-11 05:31:07 +00003788 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3789 if (RHS.isInvalid())
3790 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 if (!getDerived().AlwaysRebuild() &&
3793 Cond.get() == E->getCond() &&
3794 LHS.get() == E->getLHS() &&
3795 RHS.get() == E->getRHS())
3796 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003797
3798 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003799 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003800 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003801 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003802 move(RHS));
3803}
Mike Stump11289f42009-09-09 15:08:12 +00003804
3805template<typename Derived>
3806Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003807TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003808 // Implicit casts are eliminated during transformation, since they
3809 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003810 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003811}
Mike Stump11289f42009-09-09 15:08:12 +00003812
Douglas Gregora16548e2009-08-11 05:31:07 +00003813template<typename Derived>
3814Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003815TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003816 assert(false && "Cannot transform abstract class");
3817 return SemaRef.Owned(E->Retain());
3818}
3819
3820template<typename Derived>
3821Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003822TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003823 TypeSourceInfo *OldT;
3824 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003825 {
3826 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003827 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003828 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3829 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003830
John McCall97513962010-01-15 18:39:57 +00003831 OldT = E->getTypeInfoAsWritten();
3832 NewT = getDerived().TransformType(OldT);
3833 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 return SemaRef.ExprError();
3835 }
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregor6131b442009-12-12 18:16:41 +00003837 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003838 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003839 if (SubExpr.isInvalid())
3840 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003841
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003843 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003845 return SemaRef.Owned(E->Retain());
3846
John McCall97513962010-01-15 18:39:57 +00003847 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3848 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 E->getRParenLoc(),
3850 move(SubExpr));
3851}
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003854Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003855TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003856 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3857 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3858 if (!NewT)
3859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003860
Douglas Gregora16548e2009-08-11 05:31:07 +00003861 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3862 if (Init.isInvalid())
3863 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregora16548e2009-08-11 05:31:07 +00003865 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003866 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003868 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003869
John McCalle15bbff2010-01-18 19:35:47 +00003870 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003871 /*FIXME:*/E->getInitializer()->getLocEnd(),
3872 move(Init));
3873}
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregora16548e2009-08-11 05:31:07 +00003875template<typename Derived>
3876Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003877TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003878 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3879 if (Base.isInvalid())
3880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregora16548e2009-08-11 05:31:07 +00003882 if (!getDerived().AlwaysRebuild() &&
3883 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003884 return SemaRef.Owned(E->Retain());
3885
Douglas Gregora16548e2009-08-11 05:31:07 +00003886 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003887 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003888 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3889 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3890 E->getAccessorLoc(),
3891 E->getAccessor());
3892}
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003895Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003896TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003897 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregora16548e2009-08-11 05:31:07 +00003899 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3900 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3901 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3902 if (Init.isInvalid())
3903 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 InitChanged = InitChanged || Init.get() != E->getInit(I);
3906 Inits.push_back(Init.takeAs<Expr>());
3907 }
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003910 return SemaRef.Owned(E->Retain());
3911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003913 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003914}
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregora16548e2009-08-11 05:31:07 +00003916template<typename Derived>
3917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003918TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003920
Douglas Gregorebe10102009-08-20 07:17:43 +00003921 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003922 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3923 if (Init.isInvalid())
3924 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003925
Douglas Gregorebe10102009-08-20 07:17:43 +00003926 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003927 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3928 bool ExprChanged = false;
3929 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3930 DEnd = E->designators_end();
3931 D != DEnd; ++D) {
3932 if (D->isFieldDesignator()) {
3933 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3934 D->getDotLoc(),
3935 D->getFieldLoc()));
3936 continue;
3937 }
Mike Stump11289f42009-09-09 15:08:12 +00003938
Douglas Gregora16548e2009-08-11 05:31:07 +00003939 if (D->isArrayDesignator()) {
3940 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3941 if (Index.isInvalid())
3942 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003943
3944 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3948 ArrayExprs.push_back(Index.release());
3949 continue;
3950 }
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003953 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3955 if (Start.isInvalid())
3956 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3959 if (End.isInvalid())
3960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003961
3962 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 End.get(),
3964 D->getLBracketLoc(),
3965 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3968 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003969
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 ArrayExprs.push_back(Start.release());
3971 ArrayExprs.push_back(End.release());
3972 }
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 if (!getDerived().AlwaysRebuild() &&
3975 Init.get() == E->getInit() &&
3976 !ExprChanged)
3977 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003978
Douglas Gregora16548e2009-08-11 05:31:07 +00003979 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3980 E->getEqualOrColonLoc(),
3981 E->usesGNUSyntax(), move(Init));
3982}
Mike Stump11289f42009-09-09 15:08:12 +00003983
Douglas Gregora16548e2009-08-11 05:31:07 +00003984template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003985Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003986TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003987 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003988 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3989
3990 // FIXME: Will we ever have proper type location here? Will we actually
3991 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003992 QualType T = getDerived().TransformType(E->getType());
3993 if (T.isNull())
3994 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003995
Douglas Gregora16548e2009-08-11 05:31:07 +00003996 if (!getDerived().AlwaysRebuild() &&
3997 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003998 return SemaRef.Owned(E->Retain());
3999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 return getDerived().RebuildImplicitValueInitExpr(T);
4001}
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004004Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004005TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 // FIXME: Do we want the type as written?
4007 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004008
Douglas Gregora16548e2009-08-11 05:31:07 +00004009 {
4010 // FIXME: Source location isn't quite accurate.
4011 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4012 T = getDerived().TransformType(E->getType());
4013 if (T.isNull())
4014 return SemaRef.ExprError();
4015 }
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4018 if (SubExpr.isInvalid())
4019 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004020
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 if (!getDerived().AlwaysRebuild() &&
4022 T == E->getType() &&
4023 SubExpr.get() == E->getSubExpr())
4024 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4027 T, E->getRParenLoc());
4028}
4029
4030template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004031Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004032TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 bool ArgumentChanged = false;
4034 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4035 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4036 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4037 if (Init.isInvalid())
4038 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4041 Inits.push_back(Init.takeAs<Expr>());
4042 }
Mike Stump11289f42009-09-09 15:08:12 +00004043
Douglas Gregora16548e2009-08-11 05:31:07 +00004044 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4045 move_arg(Inits),
4046 E->getRParenLoc());
4047}
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049/// \brief Transform an address-of-label expression.
4050///
4051/// By default, the transformation of an address-of-label expression always
4052/// rebuilds the expression, so that the label identifier can be resolved to
4053/// the corresponding label statement by semantic analysis.
4054template<typename Derived>
4055Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004056TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4058 E->getLabel());
4059}
Mike Stump11289f42009-09-09 15:08:12 +00004060
4061template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004062Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004063TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004064 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004065 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4066 if (SubStmt.isInvalid())
4067 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004068
Douglas Gregora16548e2009-08-11 05:31:07 +00004069 if (!getDerived().AlwaysRebuild() &&
4070 SubStmt.get() == E->getSubStmt())
4071 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004072
4073 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 move(SubStmt),
4075 E->getRParenLoc());
4076}
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregora16548e2009-08-11 05:31:07 +00004078template<typename Derived>
4079Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004080TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 QualType T1, T2;
4082 {
4083 // FIXME: Source location isn't quite accurate.
4084 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 T1 = getDerived().TransformType(E->getArgType1());
4087 if (T1.isNull())
4088 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregora16548e2009-08-11 05:31:07 +00004090 T2 = getDerived().TransformType(E->getArgType2());
4091 if (T2.isNull())
4092 return SemaRef.ExprError();
4093 }
4094
4095 if (!getDerived().AlwaysRebuild() &&
4096 T1 == E->getArgType1() &&
4097 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004098 return SemaRef.Owned(E->Retain());
4099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4101 T1, T2, E->getRParenLoc());
4102}
Mike Stump11289f42009-09-09 15:08:12 +00004103
Douglas Gregora16548e2009-08-11 05:31:07 +00004104template<typename Derived>
4105Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004106TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4108 if (Cond.isInvalid())
4109 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregora16548e2009-08-11 05:31:07 +00004111 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4112 if (LHS.isInvalid())
4113 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004114
Douglas Gregora16548e2009-08-11 05:31:07 +00004115 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4116 if (RHS.isInvalid())
4117 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregora16548e2009-08-11 05:31:07 +00004119 if (!getDerived().AlwaysRebuild() &&
4120 Cond.get() == E->getCond() &&
4121 LHS.get() == E->getLHS() &&
4122 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004123 return SemaRef.Owned(E->Retain());
4124
Douglas Gregora16548e2009-08-11 05:31:07 +00004125 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4126 move(Cond), move(LHS), move(RHS),
4127 E->getRParenLoc());
4128}
Mike Stump11289f42009-09-09 15:08:12 +00004129
Douglas Gregora16548e2009-08-11 05:31:07 +00004130template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004131Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004132TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004133 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004134}
4135
4136template<typename Derived>
4137Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004138TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004139 switch (E->getOperator()) {
4140 case OO_New:
4141 case OO_Delete:
4142 case OO_Array_New:
4143 case OO_Array_Delete:
4144 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4145 return SemaRef.ExprError();
4146
4147 case OO_Call: {
4148 // This is a call to an object's operator().
4149 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4150
4151 // Transform the object itself.
4152 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4153 if (Object.isInvalid())
4154 return SemaRef.ExprError();
4155
4156 // FIXME: Poor location information
4157 SourceLocation FakeLParenLoc
4158 = SemaRef.PP.getLocForEndOfToken(
4159 static_cast<Expr *>(Object.get())->getLocEnd());
4160
4161 // Transform the call arguments.
4162 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4163 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4164 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004165 if (getDerived().DropCallArgument(E->getArg(I)))
4166 break;
4167
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004168 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4169 if (Arg.isInvalid())
4170 return SemaRef.ExprError();
4171
4172 // FIXME: Poor source location information.
4173 SourceLocation FakeCommaLoc
4174 = SemaRef.PP.getLocForEndOfToken(
4175 static_cast<Expr *>(Arg.get())->getLocEnd());
4176 FakeCommaLocs.push_back(FakeCommaLoc);
4177 Args.push_back(Arg.release());
4178 }
4179
4180 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4181 move_arg(Args),
4182 FakeCommaLocs.data(),
4183 E->getLocEnd());
4184 }
4185
4186#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4187 case OO_##Name:
4188#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4189#include "clang/Basic/OperatorKinds.def"
4190 case OO_Subscript:
4191 // Handled below.
4192 break;
4193
4194 case OO_Conditional:
4195 llvm_unreachable("conditional operator is not actually overloadable");
4196 return SemaRef.ExprError();
4197
4198 case OO_None:
4199 case NUM_OVERLOADED_OPERATORS:
4200 llvm_unreachable("not an overloaded operator?");
4201 return SemaRef.ExprError();
4202 }
4203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4205 if (Callee.isInvalid())
4206 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004207
John McCall47f29ea2009-12-08 09:21:05 +00004208 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004209 if (First.isInvalid())
4210 return SemaRef.ExprError();
4211
4212 OwningExprResult Second(SemaRef);
4213 if (E->getNumArgs() == 2) {
4214 Second = getDerived().TransformExpr(E->getArg(1));
4215 if (Second.isInvalid())
4216 return SemaRef.ExprError();
4217 }
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 if (!getDerived().AlwaysRebuild() &&
4220 Callee.get() == E->getCallee() &&
4221 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004222 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4223 return SemaRef.Owned(E->Retain());
4224
Douglas Gregora16548e2009-08-11 05:31:07 +00004225 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4226 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004227 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004228 move(First),
4229 move(Second));
4230}
Mike Stump11289f42009-09-09 15:08:12 +00004231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232template<typename Derived>
4233Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004234TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4235 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004236}
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregora16548e2009-08-11 05:31:07 +00004238template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004239Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004240TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004241 TypeSourceInfo *OldT;
4242 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004243 {
4244 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004245 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4247 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004248
John McCall97513962010-01-15 18:39:57 +00004249 OldT = E->getTypeInfoAsWritten();
4250 NewT = getDerived().TransformType(OldT);
4251 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004252 return SemaRef.ExprError();
4253 }
Mike Stump11289f42009-09-09 15:08:12 +00004254
Douglas Gregor6131b442009-12-12 18:16:41 +00004255 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004256 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004257 if (SubExpr.isInvalid())
4258 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004259
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004261 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004262 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004263 return SemaRef.Owned(E->Retain());
4264
Douglas Gregora16548e2009-08-11 05:31:07 +00004265 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004266 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4268 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4269 SourceLocation FakeRParenLoc
4270 = SemaRef.PP.getLocForEndOfToken(
4271 E->getSubExpr()->getSourceRange().getEnd());
4272 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004273 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004275 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 FakeRAngleLoc,
4277 FakeRAngleLoc,
4278 move(SubExpr),
4279 FakeRParenLoc);
4280}
Mike Stump11289f42009-09-09 15:08:12 +00004281
Douglas Gregora16548e2009-08-11 05:31:07 +00004282template<typename Derived>
4283Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004284TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4285 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004286}
Mike Stump11289f42009-09-09 15:08:12 +00004287
4288template<typename Derived>
4289Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004290TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4291 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004292}
4293
Douglas Gregora16548e2009-08-11 05:31:07 +00004294template<typename Derived>
4295Sema::OwningExprResult
4296TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004297 CXXReinterpretCastExpr *E) {
4298 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004299}
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301template<typename Derived>
4302Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004303TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4304 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004305}
Mike Stump11289f42009-09-09 15:08:12 +00004306
Douglas Gregora16548e2009-08-11 05:31:07 +00004307template<typename Derived>
4308Sema::OwningExprResult
4309TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004310 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004311 TypeSourceInfo *OldT;
4312 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 {
4314 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004315
John McCall97513962010-01-15 18:39:57 +00004316 OldT = E->getTypeInfoAsWritten();
4317 NewT = getDerived().TransformType(OldT);
4318 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 return SemaRef.ExprError();
4320 }
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregor6131b442009-12-12 18:16:41 +00004322 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004323 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004324 if (SubExpr.isInvalid())
4325 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004326
Douglas Gregora16548e2009-08-11 05:31:07 +00004327 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004328 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004330 return SemaRef.Owned(E->Retain());
4331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332 // FIXME: The end of the type's source range is wrong
4333 return getDerived().RebuildCXXFunctionalCastExpr(
4334 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004335 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 /*FIXME:*/E->getSubExpr()->getLocStart(),
4337 move(SubExpr),
4338 E->getRParenLoc());
4339}
Mike Stump11289f42009-09-09 15:08:12 +00004340
Douglas Gregora16548e2009-08-11 05:31:07 +00004341template<typename Derived>
4342Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004343TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 if (E->isTypeOperand()) {
4345 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004346
Douglas Gregora16548e2009-08-11 05:31:07 +00004347 QualType T = getDerived().TransformType(E->getTypeOperand());
4348 if (T.isNull())
4349 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 if (!getDerived().AlwaysRebuild() &&
4352 T == E->getTypeOperand())
4353 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4356 /*FIXME:*/E->getLocStart(),
4357 T,
4358 E->getLocEnd());
4359 }
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 // We don't know whether the expression is potentially evaluated until
4362 // after we perform semantic analysis, so the expression is potentially
4363 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004364 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4368 if (SubExpr.isInvalid())
4369 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371 if (!getDerived().AlwaysRebuild() &&
4372 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004373 return SemaRef.Owned(E->Retain());
4374
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4376 /*FIXME:*/E->getLocStart(),
4377 move(SubExpr),
4378 E->getLocEnd());
4379}
4380
4381template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004382Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004383TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004384 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004385}
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregora16548e2009-08-11 05:31:07 +00004387template<typename Derived>
4388Sema::OwningExprResult
4389TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004390 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004391 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004392}
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394template<typename Derived>
4395Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004396TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004398
Douglas Gregora16548e2009-08-11 05:31:07 +00004399 QualType T = getDerived().TransformType(E->getType());
4400 if (T.isNull())
4401 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004402
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 if (!getDerived().AlwaysRebuild() &&
4404 T == E->getType())
4405 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregorb15af892010-01-07 23:12:05 +00004407 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004408}
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410template<typename Derived>
4411Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004412TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004413 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4414 if (SubExpr.isInvalid())
4415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 if (!getDerived().AlwaysRebuild() &&
4418 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004419 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004420
4421 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregora16548e2009-08-11 05:31:07 +00004424template<typename Derived>
4425Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004426TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004427 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4429 if (!Param)
4430 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 if (getDerived().AlwaysRebuild() &&
4433 Param == E->getParam())
4434 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregor033f6752009-12-23 23:03:06 +00004436 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004437}
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439template<typename Derived>
4440Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004441TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4443
4444 QualType T = getDerived().TransformType(E->getType());
4445 if (T.isNull())
4446 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (!getDerived().AlwaysRebuild() &&
4449 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004450 return SemaRef.Owned(E->Retain());
4451
4452 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 /*FIXME:*/E->getTypeBeginLoc(),
4454 T,
4455 E->getRParenLoc());
4456}
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458template<typename Derived>
4459Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004460TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 // Transform the type that we're allocating
4462 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4463 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4464 if (AllocType.isNull())
4465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 // Transform the size of the array we're allocating (if any).
4468 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4469 if (ArraySize.isInvalid())
4470 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregora16548e2009-08-11 05:31:07 +00004472 // Transform the placement arguments (if any).
4473 bool ArgumentChanged = false;
4474 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4475 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4476 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4477 if (Arg.isInvalid())
4478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4481 PlacementArgs.push_back(Arg.take());
4482 }
Mike Stump11289f42009-09-09 15:08:12 +00004483
Douglas Gregorebe10102009-08-20 07:17:43 +00004484 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004485 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4486 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4487 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4488 if (Arg.isInvalid())
4489 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4492 ConstructorArgs.push_back(Arg.take());
4493 }
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 if (!getDerived().AlwaysRebuild() &&
4496 AllocType == E->getAllocatedType() &&
4497 ArraySize.get() == E->getArraySize() &&
4498 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004499 return SemaRef.Owned(E->Retain());
4500
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004501 if (!ArraySize.get()) {
4502 // If no array size was specified, but the new expression was
4503 // instantiated with an array type (e.g., "new T" where T is
4504 // instantiated with "int[4]"), extract the outer bound from the
4505 // array type as our array size. We do this with constant and
4506 // dependently-sized array types.
4507 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4508 if (!ArrayT) {
4509 // Do nothing
4510 } else if (const ConstantArrayType *ConsArrayT
4511 = dyn_cast<ConstantArrayType>(ArrayT)) {
4512 ArraySize
4513 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4514 ConsArrayT->getSize(),
4515 SemaRef.Context.getSizeType(),
4516 /*FIXME:*/E->getLocStart()));
4517 AllocType = ConsArrayT->getElementType();
4518 } else if (const DependentSizedArrayType *DepArrayT
4519 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4520 if (DepArrayT->getSizeExpr()) {
4521 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4522 AllocType = DepArrayT->getElementType();
4523 }
4524 }
4525 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4527 E->isGlobalNew(),
4528 /*FIXME:*/E->getLocStart(),
4529 move_arg(PlacementArgs),
4530 /*FIXME:*/E->getLocStart(),
4531 E->isParenTypeId(),
4532 AllocType,
4533 /*FIXME:*/E->getLocStart(),
4534 /*FIXME:*/SourceRange(),
4535 move(ArraySize),
4536 /*FIXME:*/E->getLocStart(),
4537 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004538 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541template<typename Derived>
4542Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004543TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4545 if (Operand.isInvalid())
4546 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004549 Operand.get() == E->getArgument())
4550 return SemaRef.Owned(E->Retain());
4551
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4553 E->isGlobalDelete(),
4554 E->isArrayForm(),
4555 move(Operand));
4556}
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558template<typename Derived>
4559Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004560TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004561 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004562 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4563 if (Base.isInvalid())
4564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregorad8a3362009-09-04 17:36:40 +00004566 NestedNameSpecifier *Qualifier
4567 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4568 E->getQualifierRange());
4569 if (E->getQualifier() && !Qualifier)
4570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregorad8a3362009-09-04 17:36:40 +00004572 QualType DestroyedType;
4573 {
4574 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4575 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4576 if (DestroyedType.isNull())
4577 return SemaRef.ExprError();
4578 }
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregorad8a3362009-09-04 17:36:40 +00004580 if (!getDerived().AlwaysRebuild() &&
4581 Base.get() == E->getBase() &&
4582 Qualifier == E->getQualifier() &&
4583 DestroyedType == E->getDestroyedType())
4584 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004585
Douglas Gregorad8a3362009-09-04 17:36:40 +00004586 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4587 E->getOperatorLoc(),
4588 E->isArrow(),
4589 E->getDestroyedTypeLoc(),
4590 DestroyedType,
4591 Qualifier,
4592 E->getQualifierRange());
4593}
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregorad8a3362009-09-04 17:36:40 +00004595template<typename Derived>
4596Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004597TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004598 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004599 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4600
4601 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4602 Sema::LookupOrdinaryName);
4603
4604 // Transform all the decls.
4605 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4606 E = Old->decls_end(); I != E; ++I) {
4607 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004608 if (!InstD) {
4609 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4610 // This can happen because of dependent hiding.
4611 if (isa<UsingShadowDecl>(*I))
4612 continue;
4613 else
4614 return SemaRef.ExprError();
4615 }
John McCalle66edc12009-11-24 19:00:30 +00004616
4617 // Expand using declarations.
4618 if (isa<UsingDecl>(InstD)) {
4619 UsingDecl *UD = cast<UsingDecl>(InstD);
4620 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4621 E = UD->shadow_end(); I != E; ++I)
4622 R.addDecl(*I);
4623 continue;
4624 }
4625
4626 R.addDecl(InstD);
4627 }
4628
4629 // Resolve a kind, but don't do any further analysis. If it's
4630 // ambiguous, the callee needs to deal with it.
4631 R.resolveKind();
4632
4633 // Rebuild the nested-name qualifier, if present.
4634 CXXScopeSpec SS;
4635 NestedNameSpecifier *Qualifier = 0;
4636 if (Old->getQualifier()) {
4637 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4638 Old->getQualifierRange());
4639 if (!Qualifier)
4640 return SemaRef.ExprError();
4641
4642 SS.setScopeRep(Qualifier);
4643 SS.setRange(Old->getQualifierRange());
4644 }
4645
4646 // If we have no template arguments, it's a normal declaration name.
4647 if (!Old->hasExplicitTemplateArgs())
4648 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4649
4650 // If we have template arguments, rebuild them, then rebuild the
4651 // templateid expression.
4652 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4653 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4654 TemplateArgumentLoc Loc;
4655 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4656 return SemaRef.ExprError();
4657 TransArgs.addArgument(Loc);
4658 }
4659
4660 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4661 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004662}
Mike Stump11289f42009-09-09 15:08:12 +00004663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664template<typename Derived>
4665Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004666TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004668
Douglas Gregora16548e2009-08-11 05:31:07 +00004669 QualType T = getDerived().TransformType(E->getQueriedType());
4670 if (T.isNull())
4671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004672
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 if (!getDerived().AlwaysRebuild() &&
4674 T == E->getQueriedType())
4675 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 // FIXME: Bad location information
4678 SourceLocation FakeLParenLoc
4679 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004680
4681 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 E->getLocStart(),
4683 /*FIXME:*/FakeLParenLoc,
4684 T,
4685 E->getLocEnd());
4686}
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688template<typename Derived>
4689Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004690TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004691 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004693 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4694 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004695 if (!NNS)
4696 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004697
4698 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004699 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4700 if (!Name)
4701 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004702
John McCalle66edc12009-11-24 19:00:30 +00004703 if (!E->hasExplicitTemplateArgs()) {
4704 if (!getDerived().AlwaysRebuild() &&
4705 NNS == E->getQualifier() &&
4706 Name == E->getDeclName())
4707 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004708
John McCalle66edc12009-11-24 19:00:30 +00004709 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4710 E->getQualifierRange(),
4711 Name, E->getLocation(),
4712 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004713 }
John McCall6b51f282009-11-23 01:53:49 +00004714
4715 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004717 TemplateArgumentLoc Loc;
4718 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004719 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004720 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 }
4722
John McCalle66edc12009-11-24 19:00:30 +00004723 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4724 E->getQualifierRange(),
4725 Name, E->getLocation(),
4726 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004727}
4728
4729template<typename Derived>
4730Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004731TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4733
4734 QualType T = getDerived().TransformType(E->getType());
4735 if (T.isNull())
4736 return SemaRef.ExprError();
4737
4738 CXXConstructorDecl *Constructor
4739 = cast_or_null<CXXConstructorDecl>(
4740 getDerived().TransformDecl(E->getConstructor()));
4741 if (!Constructor)
4742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 bool ArgumentChanged = false;
4745 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004746 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004747 ArgEnd = E->arg_end();
4748 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004749 if (getDerived().DropCallArgument(*Arg)) {
4750 ArgumentChanged = true;
4751 break;
4752 }
4753
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4755 if (TransArg.isInvalid())
4756 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004757
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4759 Args.push_back(TransArg.takeAs<Expr>());
4760 }
4761
4762 if (!getDerived().AlwaysRebuild() &&
4763 T == E->getType() &&
4764 Constructor == E->getConstructor() &&
4765 !ArgumentChanged)
4766 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregordb121ba2009-12-14 16:27:04 +00004768 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4769 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 move_arg(Args));
4771}
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773/// \brief Transform a C++ temporary-binding expression.
4774///
Douglas Gregor363b1512009-12-24 18:51:59 +00004775/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4776/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004777template<typename Derived>
4778Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004779TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004780 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004781}
Mike Stump11289f42009-09-09 15:08:12 +00004782
4783/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004784/// be destroyed after the expression is evaluated.
4785///
Douglas Gregor363b1512009-12-24 18:51:59 +00004786/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4787/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004788template<typename Derived>
4789Sema::OwningExprResult
4790TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004791 CXXExprWithTemporaries *E) {
4792 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004793}
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795template<typename Derived>
4796Sema::OwningExprResult
4797TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004798 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4800 QualType T = getDerived().TransformType(E->getType());
4801 if (T.isNull())
4802 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 CXXConstructorDecl *Constructor
4805 = cast_or_null<CXXConstructorDecl>(
4806 getDerived().TransformDecl(E->getConstructor()));
4807 if (!Constructor)
4808 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 bool ArgumentChanged = false;
4811 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4812 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004813 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 ArgEnd = E->arg_end();
4815 Arg != ArgEnd; ++Arg) {
4816 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4817 if (TransArg.isInvalid())
4818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4821 Args.push_back((Expr *)TransArg.release());
4822 }
Mike Stump11289f42009-09-09 15:08:12 +00004823
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 if (!getDerived().AlwaysRebuild() &&
4825 T == E->getType() &&
4826 Constructor == E->getConstructor() &&
4827 !ArgumentChanged)
4828 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 // FIXME: Bogus location information
4831 SourceLocation CommaLoc;
4832 if (Args.size() > 1) {
4833 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004834 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4836 }
4837 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4838 T,
4839 /*FIXME:*/E->getTypeBeginLoc(),
4840 move_arg(Args),
4841 &CommaLoc,
4842 E->getLocEnd());
4843}
Mike Stump11289f42009-09-09 15:08:12 +00004844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845template<typename Derived>
4846Sema::OwningExprResult
4847TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004848 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4850 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4851 if (T.isNull())
4852 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 bool ArgumentChanged = false;
4855 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4856 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4857 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4858 ArgEnd = E->arg_end();
4859 Arg != ArgEnd; ++Arg) {
4860 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4861 if (TransArg.isInvalid())
4862 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004863
Douglas Gregora16548e2009-08-11 05:31:07 +00004864 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4865 FakeCommaLocs.push_back(
4866 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4867 Args.push_back(TransArg.takeAs<Expr>());
4868 }
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregora16548e2009-08-11 05:31:07 +00004870 if (!getDerived().AlwaysRebuild() &&
4871 T == E->getTypeAsWritten() &&
4872 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004873 return SemaRef.Owned(E->Retain());
4874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 // FIXME: we're faking the locations of the commas
4876 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4877 T,
4878 E->getLParenLoc(),
4879 move_arg(Args),
4880 FakeCommaLocs.data(),
4881 E->getRParenLoc());
4882}
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregora16548e2009-08-11 05:31:07 +00004884template<typename Derived>
4885Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004886TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004887 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004889 OwningExprResult Base(SemaRef, (Expr*) 0);
4890 Expr *OldBase;
4891 QualType BaseType;
4892 QualType ObjectType;
4893 if (!E->isImplicitAccess()) {
4894 OldBase = E->getBase();
4895 Base = getDerived().TransformExpr(OldBase);
4896 if (Base.isInvalid())
4897 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
John McCall2d74de92009-12-01 22:10:20 +00004899 // Start the member reference and compute the object's type.
4900 Sema::TypeTy *ObjectTy = 0;
4901 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4902 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004903 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004904 ObjectTy);
4905 if (Base.isInvalid())
4906 return SemaRef.ExprError();
4907
4908 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4909 BaseType = ((Expr*) Base.get())->getType();
4910 } else {
4911 OldBase = 0;
4912 BaseType = getDerived().TransformType(E->getBaseType());
4913 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4914 }
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004916 // Transform the first part of the nested-name-specifier that qualifies
4917 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004918 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004919 = getDerived().TransformFirstQualifierInScope(
4920 E->getFirstQualifierFoundInScope(),
4921 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004923 NestedNameSpecifier *Qualifier = 0;
4924 if (E->getQualifier()) {
4925 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4926 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004927 ObjectType,
4928 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004929 if (!Qualifier)
4930 return SemaRef.ExprError();
4931 }
Mike Stump11289f42009-09-09 15:08:12 +00004932
4933 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004934 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004935 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004936 if (!Name)
4937 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCall2d74de92009-12-01 22:10:20 +00004939 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004940 // This is a reference to a member without an explicitly-specified
4941 // template argument list. Optimize for this common case.
4942 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004943 Base.get() == OldBase &&
4944 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004945 Qualifier == E->getQualifier() &&
4946 Name == E->getMember() &&
4947 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004948 return SemaRef.Owned(E->Retain());
4949
John McCall8cd78132009-11-19 22:55:06 +00004950 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004951 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004952 E->isArrow(),
4953 E->getOperatorLoc(),
4954 Qualifier,
4955 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004956 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004957 Name,
4958 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004959 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004960 }
4961
John McCall6b51f282009-11-23 01:53:49 +00004962 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004963 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004964 TemplateArgumentLoc Loc;
4965 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004966 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004967 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004968 }
Mike Stump11289f42009-09-09 15:08:12 +00004969
John McCall8cd78132009-11-19 22:55:06 +00004970 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004971 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 E->isArrow(),
4973 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004974 Qualifier,
4975 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004976 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004977 Name,
4978 E->getMemberLoc(),
4979 &TransArgs);
4980}
4981
4982template<typename Derived>
4983Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004984TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004985 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004986 OwningExprResult Base(SemaRef, (Expr*) 0);
4987 QualType BaseType;
4988 if (!Old->isImplicitAccess()) {
4989 Base = getDerived().TransformExpr(Old->getBase());
4990 if (Base.isInvalid())
4991 return SemaRef.ExprError();
4992 BaseType = ((Expr*) Base.get())->getType();
4993 } else {
4994 BaseType = getDerived().TransformType(Old->getBaseType());
4995 }
John McCall10eae182009-11-30 22:42:35 +00004996
4997 NestedNameSpecifier *Qualifier = 0;
4998 if (Old->getQualifier()) {
4999 Qualifier
5000 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5001 Old->getQualifierRange());
5002 if (Qualifier == 0)
5003 return SemaRef.ExprError();
5004 }
5005
5006 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5007 Sema::LookupOrdinaryName);
5008
5009 // Transform all the decls.
5010 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5011 E = Old->decls_end(); I != E; ++I) {
5012 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005013 if (!InstD) {
5014 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5015 // This can happen because of dependent hiding.
5016 if (isa<UsingShadowDecl>(*I))
5017 continue;
5018 else
5019 return SemaRef.ExprError();
5020 }
John McCall10eae182009-11-30 22:42:35 +00005021
5022 // Expand using declarations.
5023 if (isa<UsingDecl>(InstD)) {
5024 UsingDecl *UD = cast<UsingDecl>(InstD);
5025 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5026 E = UD->shadow_end(); I != E; ++I)
5027 R.addDecl(*I);
5028 continue;
5029 }
5030
5031 R.addDecl(InstD);
5032 }
5033
5034 R.resolveKind();
5035
5036 TemplateArgumentListInfo TransArgs;
5037 if (Old->hasExplicitTemplateArgs()) {
5038 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5039 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5040 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5041 TemplateArgumentLoc Loc;
5042 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5043 Loc))
5044 return SemaRef.ExprError();
5045 TransArgs.addArgument(Loc);
5046 }
5047 }
John McCall38836f02010-01-15 08:34:02 +00005048
5049 // FIXME: to do this check properly, we will need to preserve the
5050 // first-qualifier-in-scope here, just in case we had a dependent
5051 // base (and therefore couldn't do the check) and a
5052 // nested-name-qualifier (and therefore could do the lookup).
5053 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005054
5055 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005056 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005057 Old->getOperatorLoc(),
5058 Old->isArrow(),
5059 Qualifier,
5060 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005061 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005062 R,
5063 (Old->hasExplicitTemplateArgs()
5064 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005065}
5066
5067template<typename Derived>
5068Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005070 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005071}
5072
Mike Stump11289f42009-09-09 15:08:12 +00005073template<typename Derived>
5074Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005075TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 // FIXME: poor source location
5077 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5078 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5079 if (EncodedType.isNull())
5080 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 if (!getDerived().AlwaysRebuild() &&
5083 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005084 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005085
5086 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5087 EncodedType,
5088 E->getRParenLoc());
5089}
Mike Stump11289f42009-09-09 15:08:12 +00005090
Douglas Gregora16548e2009-08-11 05:31:07 +00005091template<typename Derived>
5092Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005093TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 // FIXME: Implement this!
5095 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005096 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005097}
5098
Mike Stump11289f42009-09-09 15:08:12 +00005099template<typename Derived>
5100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005101TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005102 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103}
5104
Mike Stump11289f42009-09-09 15:08:12 +00005105template<typename Derived>
5106Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005107TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005108 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 = cast_or_null<ObjCProtocolDecl>(
5110 getDerived().TransformDecl(E->getProtocol()));
5111 if (!Protocol)
5112 return SemaRef.ExprError();
5113
5114 if (!getDerived().AlwaysRebuild() &&
5115 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005116 return SemaRef.Owned(E->Retain());
5117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 return getDerived().RebuildObjCProtocolExpr(Protocol,
5119 E->getAtLoc(),
5120 /*FIXME:*/E->getAtLoc(),
5121 /*FIXME:*/E->getAtLoc(),
5122 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregora16548e2009-08-11 05:31:07 +00005124}
5125
Mike Stump11289f42009-09-09 15:08:12 +00005126template<typename Derived>
5127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005128TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 // FIXME: Implement this!
5130 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005131 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005132}
5133
Mike Stump11289f42009-09-09 15:08:12 +00005134template<typename Derived>
5135Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005136TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 // FIXME: Implement this!
5138 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005139 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005140}
5141
Mike Stump11289f42009-09-09 15:08:12 +00005142template<typename Derived>
5143Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005144TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005145 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005146 // FIXME: Implement this!
5147 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005148 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005149}
5150
Mike Stump11289f42009-09-09 15:08:12 +00005151template<typename Derived>
5152Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005153TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 // FIXME: Implement this!
5155 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005156 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005157}
5158
Mike Stump11289f42009-09-09 15:08:12 +00005159template<typename Derived>
5160Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005161TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 // FIXME: Implement this!
5163 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005164 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005165}
5166
Mike Stump11289f42009-09-09 15:08:12 +00005167template<typename Derived>
5168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005169TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 bool ArgumentChanged = false;
5171 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5172 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5173 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5174 if (SubExpr.isInvalid())
5175 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005176
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5178 SubExprs.push_back(SubExpr.takeAs<Expr>());
5179 }
Mike Stump11289f42009-09-09 15:08:12 +00005180
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 if (!getDerived().AlwaysRebuild() &&
5182 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005183 return SemaRef.Owned(E->Retain());
5184
Douglas Gregora16548e2009-08-11 05:31:07 +00005185 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5186 move_arg(SubExprs),
5187 E->getRParenLoc());
5188}
5189
Mike Stump11289f42009-09-09 15:08:12 +00005190template<typename Derived>
5191Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005192TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005193 // FIXME: Implement this!
5194 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005195 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005196}
5197
Mike Stump11289f42009-09-09 15:08:12 +00005198template<typename Derived>
5199Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005200TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 // FIXME: Implement this!
5202 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005203 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
Mike Stump11289f42009-09-09 15:08:12 +00005205
Douglas Gregora16548e2009-08-11 05:31:07 +00005206//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005207// Type reconstruction
5208//===----------------------------------------------------------------------===//
5209
Mike Stump11289f42009-09-09 15:08:12 +00005210template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005211QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5212 SourceLocation Star) {
5213 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214 getDerived().getBaseEntity());
5215}
5216
Mike Stump11289f42009-09-09 15:08:12 +00005217template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005218QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5219 SourceLocation Star) {
5220 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221 getDerived().getBaseEntity());
5222}
5223
Mike Stump11289f42009-09-09 15:08:12 +00005224template<typename Derived>
5225QualType
John McCall70dd5f62009-10-30 00:06:24 +00005226TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5227 bool WrittenAsLValue,
5228 SourceLocation Sigil) {
5229 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5230 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005231}
5232
5233template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005234QualType
John McCall70dd5f62009-10-30 00:06:24 +00005235TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5236 QualType ClassType,
5237 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005238 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005239 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240}
5241
5242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005243QualType
John McCall70dd5f62009-10-30 00:06:24 +00005244TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5245 SourceLocation Sigil) {
5246 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005247 getDerived().getBaseEntity());
5248}
5249
5250template<typename Derived>
5251QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005252TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5253 ArrayType::ArraySizeModifier SizeMod,
5254 const llvm::APInt *Size,
5255 Expr *SizeExpr,
5256 unsigned IndexTypeQuals,
5257 SourceRange BracketsRange) {
5258 if (SizeExpr || !Size)
5259 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5260 IndexTypeQuals, BracketsRange,
5261 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005262
5263 QualType Types[] = {
5264 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5265 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5266 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005267 };
5268 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5269 QualType SizeType;
5270 for (unsigned I = 0; I != NumTypes; ++I)
5271 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5272 SizeType = Types[I];
5273 break;
5274 }
Mike Stump11289f42009-09-09 15:08:12 +00005275
Douglas Gregord6ff3322009-08-04 16:50:30 +00005276 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005277 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005278 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005279 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280}
Mike Stump11289f42009-09-09 15:08:12 +00005281
Douglas Gregord6ff3322009-08-04 16:50:30 +00005282template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005283QualType
5284TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285 ArrayType::ArraySizeModifier SizeMod,
5286 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005287 unsigned IndexTypeQuals,
5288 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005289 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005290 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005291}
5292
5293template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005294QualType
Mike Stump11289f42009-09-09 15:08:12 +00005295TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005297 unsigned IndexTypeQuals,
5298 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005299 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005300 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005301}
Mike Stump11289f42009-09-09 15:08:12 +00005302
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005304QualType
5305TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005306 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005307 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005308 unsigned IndexTypeQuals,
5309 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005310 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005311 SizeExpr.takeAs<Expr>(),
5312 IndexTypeQuals, BracketsRange);
5313}
5314
5315template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005316QualType
5317TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005318 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005319 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320 unsigned IndexTypeQuals,
5321 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005322 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005323 SizeExpr.takeAs<Expr>(),
5324 IndexTypeQuals, BracketsRange);
5325}
5326
5327template<typename Derived>
5328QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5329 unsigned NumElements) {
5330 // FIXME: semantic checking!
5331 return SemaRef.Context.getVectorType(ElementType, NumElements);
5332}
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregord6ff3322009-08-04 16:50:30 +00005334template<typename Derived>
5335QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5336 unsigned NumElements,
5337 SourceLocation AttributeLoc) {
5338 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5339 NumElements, true);
5340 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005341 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005342 AttributeLoc);
5343 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5344 AttributeLoc);
5345}
Mike Stump11289f42009-09-09 15:08:12 +00005346
Douglas Gregord6ff3322009-08-04 16:50:30 +00005347template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005348QualType
5349TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005350 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005351 SourceLocation AttributeLoc) {
5352 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregord6ff3322009-08-04 16:50:30 +00005355template<typename Derived>
5356QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005357 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005358 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005359 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005360 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005361 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362 Quals,
5363 getDerived().getBaseLocation(),
5364 getDerived().getBaseEntity());
5365}
Mike Stump11289f42009-09-09 15:08:12 +00005366
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005368QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5369 return SemaRef.Context.getFunctionNoProtoType(T);
5370}
5371
5372template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005373QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5374 assert(D && "no decl found");
5375 if (D->isInvalidDecl()) return QualType();
5376
5377 TypeDecl *Ty;
5378 if (isa<UsingDecl>(D)) {
5379 UsingDecl *Using = cast<UsingDecl>(D);
5380 assert(Using->isTypeName() &&
5381 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5382
5383 // A valid resolved using typename decl points to exactly one type decl.
5384 assert(++Using->shadow_begin() == Using->shadow_end());
5385 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5386
5387 } else {
5388 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5389 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5390 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5391 }
5392
5393 return SemaRef.Context.getTypeDeclType(Ty);
5394}
5395
5396template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005397QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005398 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5399}
5400
5401template<typename Derived>
5402QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5403 return SemaRef.Context.getTypeOfType(Underlying);
5404}
5405
5406template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005407QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005408 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5409}
5410
5411template<typename Derived>
5412QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005413 TemplateName Template,
5414 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005415 const TemplateArgumentListInfo &TemplateArgs) {
5416 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005417}
Mike Stump11289f42009-09-09 15:08:12 +00005418
Douglas Gregor1135c352009-08-06 05:28:30 +00005419template<typename Derived>
5420NestedNameSpecifier *
5421TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5422 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005423 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005424 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005425 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005426 CXXScopeSpec SS;
5427 // FIXME: The source location information is all wrong.
5428 SS.setRange(Range);
5429 SS.setScopeRep(Prefix);
5430 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005431 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005432 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005433 ObjectType,
5434 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005435 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005436}
5437
5438template<typename Derived>
5439NestedNameSpecifier *
5440TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5441 SourceRange Range,
5442 NamespaceDecl *NS) {
5443 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5444}
5445
5446template<typename Derived>
5447NestedNameSpecifier *
5448TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5449 SourceRange Range,
5450 bool TemplateKW,
5451 QualType T) {
5452 if (T->isDependentType() || T->isRecordType() ||
5453 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005454 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005455 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5456 T.getTypePtr());
5457 }
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregor1135c352009-08-06 05:28:30 +00005459 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5460 return 0;
5461}
Mike Stump11289f42009-09-09 15:08:12 +00005462
Douglas Gregor71dc5092009-08-06 06:41:21 +00005463template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005464TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005465TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5466 bool TemplateKW,
5467 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005468 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005469 Template);
5470}
5471
5472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005473TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005474TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005475 const IdentifierInfo &II,
5476 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005477 CXXScopeSpec SS;
5478 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005479 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005480 UnqualifiedId Name;
5481 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005482 return getSema().ActOnDependentTemplateName(
5483 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005484 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005485 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005486 ObjectType.getAsOpaquePtr(),
5487 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005488 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005489}
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005492TemplateName
5493TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5494 OverloadedOperatorKind Operator,
5495 QualType ObjectType) {
5496 CXXScopeSpec SS;
5497 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5498 SS.setScopeRep(Qualifier);
5499 UnqualifiedId Name;
5500 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5501 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5502 Operator, SymbolLocations);
5503 return getSema().ActOnDependentTemplateName(
5504 /*FIXME:*/getDerived().getBaseLocation(),
5505 SS,
5506 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005507 ObjectType.getAsOpaquePtr(),
5508 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005509 .template getAsVal<TemplateName>();
5510}
5511
5512template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005513Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005514TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5515 SourceLocation OpLoc,
5516 ExprArg Callee,
5517 ExprArg First,
5518 ExprArg Second) {
5519 Expr *FirstExpr = (Expr *)First.get();
5520 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005521 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005525 if (Op == OO_Subscript) {
5526 if (!FirstExpr->getType()->isOverloadableType() &&
5527 !SecondExpr->getType()->isOverloadableType())
5528 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005529 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005530 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005531 } else if (Op == OO_Arrow) {
5532 // -> is never a builtin operation.
5533 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005534 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005535 if (!FirstExpr->getType()->isOverloadableType()) {
5536 // The argument is not of overloadable type, so try to create a
5537 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005538 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005539 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5542 }
5543 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005544 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 !SecondExpr->getType()->isOverloadableType()) {
5546 // Neither of the arguments is an overloadable type, so try to
5547 // create a built-in binary operation.
5548 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005549 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005550 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5551 if (Result.isInvalid())
5552 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 First.release();
5555 Second.release();
5556 return move(Result);
5557 }
5558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
5560 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 // used during overload resolution.
5562 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005563
John McCalld14a8642009-11-21 08:51:07 +00005564 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5565 assert(ULE->requiresADL());
5566
5567 // FIXME: Do we have to check
5568 // IsAcceptableNonMemberOperatorCandidate for each of these?
5569 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5570 E = ULE->decls_end(); I != E; ++I)
5571 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5572 } else {
5573 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5574 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5575 }
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 // Add any functions found via argument-dependent lookup.
5578 Expr *Args[2] = { FirstExpr, SecondExpr };
5579 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005580 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005582 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5583 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005584
Douglas Gregora16548e2009-08-11 05:31:07 +00005585 // Create the overloaded operator invocation for unary operators.
5586 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005587 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5589 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5590 }
Mike Stump11289f42009-09-09 15:08:12 +00005591
Sebastian Redladba46e2009-10-29 20:17:01 +00005592 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005593 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5594 OpLoc,
5595 move(First),
5596 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005597
Douglas Gregora16548e2009-08-11 05:31:07 +00005598 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005599 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005600 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005601 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005602 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5603 if (Result.isInvalid())
5604 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606 First.release();
5607 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005608 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005609}
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregord6ff3322009-08-04 16:50:30 +00005611} // end namespace clang
5612
5613#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H