blob: 469ff72d3fc09b750802371067c534c2af6672ea [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,
1030 QualType T,
1031 SourceLocation RParenLoc,
1032 ExprArg Init) {
1033 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1034 RParenLoc, move(Init));
1035 }
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) {
1240 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall97513962010-01-15 18:39:57 +00001241 LAngleLoc,
1242 TInfo->getType().getAsOpaquePtr(),
1243 RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 LParenLoc, move(SubExpr), RParenLoc);
1245 }
1246
1247 /// \brief Build a new C++ dynamic_cast expression.
1248 ///
1249 /// By default, performs semantic analysis to build the new expression.
1250 /// Subclasses may override this routine to provide different behavior.
1251 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1252 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001253 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 SourceLocation RAngleLoc,
1255 SourceLocation LParenLoc,
1256 ExprArg SubExpr,
1257 SourceLocation RParenLoc) {
1258 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall97513962010-01-15 18:39:57 +00001259 LAngleLoc,
1260 TInfo->getType().getAsOpaquePtr(),
1261 RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 LParenLoc, move(SubExpr), RParenLoc);
1263 }
1264
1265 /// \brief Build a new C++ reinterpret_cast expression.
1266 ///
1267 /// By default, performs semantic analysis to build the new expression.
1268 /// Subclasses may override this routine to provide different behavior.
1269 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1270 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001271 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 SourceLocation RAngleLoc,
1273 SourceLocation LParenLoc,
1274 ExprArg SubExpr,
1275 SourceLocation RParenLoc) {
1276 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall97513962010-01-15 18:39:57 +00001277 LAngleLoc,
1278 TInfo->getType().getAsOpaquePtr(),
1279 RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 LParenLoc, move(SubExpr), RParenLoc);
1281 }
1282
1283 /// \brief Build a new C++ const_cast expression.
1284 ///
1285 /// By default, performs semantic analysis to build the new expression.
1286 /// Subclasses may override this routine to provide different behavior.
1287 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1288 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001289 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 SourceLocation RAngleLoc,
1291 SourceLocation LParenLoc,
1292 ExprArg SubExpr,
1293 SourceLocation RParenLoc) {
1294 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall97513962010-01-15 18:39:57 +00001295 LAngleLoc,
1296 TInfo->getType().getAsOpaquePtr(),
1297 RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 LParenLoc, move(SubExpr), RParenLoc);
1299 }
Mike Stump11289f42009-09-09 15:08:12 +00001300
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 /// \brief Build a new C++ functional-style cast expression.
1302 ///
1303 /// By default, performs semantic analysis to build the new expression.
1304 /// Subclasses may override this routine to provide different behavior.
1305 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001306 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 SourceLocation LParenLoc,
1308 ExprArg SubExpr,
1309 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001310 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001312 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001314 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001315 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 RParenLoc);
1317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new C++ typeid(type) expression.
1320 ///
1321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1324 SourceLocation LParenLoc,
1325 QualType T,
1326 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001327 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 T.getAsOpaquePtr(), RParenLoc);
1329 }
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// \brief Build a new C++ typeid(expr) expression.
1332 ///
1333 /// By default, performs semantic analysis to build the new expression.
1334 /// Subclasses may override this routine to provide different behavior.
1335 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1336 SourceLocation LParenLoc,
1337 ExprArg Operand,
1338 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001339 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1341 RParenLoc);
1342 if (Result.isInvalid())
1343 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001344
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1346 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001347 }
1348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// \brief Build a new C++ "this" expression.
1350 ///
1351 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001352 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001354 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001355 QualType ThisType,
1356 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001357 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001358 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1359 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 }
1361
1362 /// \brief Build a new C++ throw expression.
1363 ///
1364 /// By default, performs semantic analysis to build the new expression.
1365 /// Subclasses may override this routine to provide different behavior.
1366 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1367 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1368 }
1369
1370 /// \brief Build a new C++ default-argument expression.
1371 ///
1372 /// By default, builds a new default-argument expression, which does not
1373 /// require any semantic analysis. Subclasses may override this routine to
1374 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001375 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1376 ParmVarDecl *Param) {
1377 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1378 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 }
1380
1381 /// \brief Build a new C++ zero-initialization expression.
1382 ///
1383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001385 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 SourceLocation LParenLoc,
1387 QualType T,
1388 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001389 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1390 T.getAsOpaquePtr(), LParenLoc,
1391 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 0, RParenLoc);
1393 }
Mike Stump11289f42009-09-09 15:08:12 +00001394
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// \brief Build a new C++ "new" expression.
1396 ///
1397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001399 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 bool UseGlobal,
1401 SourceLocation PlacementLParen,
1402 MultiExprArg PlacementArgs,
1403 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001404 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 QualType AllocType,
1406 SourceLocation TypeLoc,
1407 SourceRange TypeRange,
1408 ExprArg ArraySize,
1409 SourceLocation ConstructorLParen,
1410 MultiExprArg ConstructorArgs,
1411 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001412 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 PlacementLParen,
1414 move(PlacementArgs),
1415 PlacementRParen,
1416 ParenTypeId,
1417 AllocType,
1418 TypeLoc,
1419 TypeRange,
1420 move(ArraySize),
1421 ConstructorLParen,
1422 move(ConstructorArgs),
1423 ConstructorRParen);
1424 }
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 /// \brief Build a new C++ "delete" expression.
1427 ///
1428 /// By default, performs semantic analysis to build the new expression.
1429 /// Subclasses may override this routine to provide different behavior.
1430 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1431 bool IsGlobalDelete,
1432 bool IsArrayForm,
1433 ExprArg Operand) {
1434 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1435 move(Operand));
1436 }
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 /// \brief Build a new unary type trait expression.
1439 ///
1440 /// By default, performs semantic analysis to build the new expression.
1441 /// Subclasses may override this routine to provide different behavior.
1442 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1443 SourceLocation StartLoc,
1444 SourceLocation LParenLoc,
1445 QualType T,
1446 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001447 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 T.getAsOpaquePtr(), RParenLoc);
1449 }
1450
Mike Stump11289f42009-09-09 15:08:12 +00001451 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 /// expression.
1453 ///
1454 /// By default, performs semantic analysis to build the new expression.
1455 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001456 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 SourceRange QualifierRange,
1458 DeclarationName Name,
1459 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001460 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001461 CXXScopeSpec SS;
1462 SS.setRange(QualifierRange);
1463 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001464
1465 if (TemplateArgs)
1466 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1467 *TemplateArgs);
1468
1469 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 }
1471
1472 /// \brief Build a new template-id expression.
1473 ///
1474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001476 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1477 LookupResult &R,
1478 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001479 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001480 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 }
1482
1483 /// \brief Build a new object-construction expression.
1484 ///
1485 /// By default, performs semantic analysis to build the new expression.
1486 /// Subclasses may override this routine to provide different behavior.
1487 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001488 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 CXXConstructorDecl *Constructor,
1490 bool IsElidable,
1491 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001492 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1493 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1494 ConvertedArgs))
1495 return getSema().ExprError();
1496
1497 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1498 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 }
1500
1501 /// \brief Build a new object-construction expression.
1502 ///
1503 /// By default, performs semantic analysis to build the new expression.
1504 /// Subclasses may override this routine to provide different behavior.
1505 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1506 QualType T,
1507 SourceLocation LParenLoc,
1508 MultiExprArg Args,
1509 SourceLocation *Commas,
1510 SourceLocation RParenLoc) {
1511 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1512 T.getAsOpaquePtr(),
1513 LParenLoc,
1514 move(Args),
1515 Commas,
1516 RParenLoc);
1517 }
1518
1519 /// \brief Build a new object-construction expression.
1520 ///
1521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1524 QualType T,
1525 SourceLocation LParenLoc,
1526 MultiExprArg Args,
1527 SourceLocation *Commas,
1528 SourceLocation RParenLoc) {
1529 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1530 /*FIXME*/LParenLoc),
1531 T.getAsOpaquePtr(),
1532 LParenLoc,
1533 move(Args),
1534 Commas,
1535 RParenLoc);
1536 }
Mike Stump11289f42009-09-09 15:08:12 +00001537
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// \brief Build a new member reference expression.
1539 ///
1540 /// By default, performs semantic analysis to build the new expression.
1541 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001542 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001543 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 bool IsArrow,
1545 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001546 NestedNameSpecifier *Qualifier,
1547 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001548 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001550 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001551 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001553 SS.setRange(QualifierRange);
1554 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001555
John McCall2d74de92009-12-01 22:10:20 +00001556 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1557 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001558 SS, FirstQualifierInScope,
1559 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 }
1561
John McCall10eae182009-11-30 22:42:35 +00001562 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001563 ///
1564 /// By default, performs semantic analysis to build the new expression.
1565 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001566 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001567 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001568 SourceLocation OperatorLoc,
1569 bool IsArrow,
1570 NestedNameSpecifier *Qualifier,
1571 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001572 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001573 LookupResult &R,
1574 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001575 CXXScopeSpec SS;
1576 SS.setRange(QualifierRange);
1577 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001578
John McCall2d74de92009-12-01 22:10:20 +00001579 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1580 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001581 SS, FirstQualifierInScope,
1582 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001583 }
Mike Stump11289f42009-09-09 15:08:12 +00001584
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 /// \brief Build a new Objective-C @encode expression.
1586 ///
1587 /// By default, performs semantic analysis to build the new expression.
1588 /// Subclasses may override this routine to provide different behavior.
1589 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1590 QualType T,
1591 SourceLocation RParenLoc) {
1592 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1593 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001594 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001595
1596 /// \brief Build a new Objective-C protocol expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1600 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1601 SourceLocation AtLoc,
1602 SourceLocation ProtoLoc,
1603 SourceLocation LParenLoc,
1604 SourceLocation RParenLoc) {
1605 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1606 Protocol->getIdentifier(),
1607 AtLoc,
1608 ProtoLoc,
1609 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001610 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 }
Mike Stump11289f42009-09-09 15:08:12 +00001612
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 /// \brief Build a new shuffle vector expression.
1614 ///
1615 /// By default, performs semantic analysis to build the new expression.
1616 /// Subclasses may override this routine to provide different behavior.
1617 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1618 MultiExprArg SubExprs,
1619 SourceLocation RParenLoc) {
1620 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001621 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1623 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1624 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1625 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001626
Douglas Gregora16548e2009-08-11 05:31:07 +00001627 // Build a reference to the __builtin_shufflevector builtin
1628 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001629 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001631 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001633
1634 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 unsigned NumSubExprs = SubExprs.size();
1636 Expr **Subs = (Expr **)SubExprs.release();
1637 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1638 Subs, NumSubExprs,
1639 Builtin->getResultType(),
1640 RParenLoc);
1641 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001642
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 // Type-check the __builtin_shufflevector expression.
1644 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1645 if (Result.isInvalid())
1646 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001649 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001651};
Douglas Gregora16548e2009-08-11 05:31:07 +00001652
Douglas Gregorebe10102009-08-20 07:17:43 +00001653template<typename Derived>
1654Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1655 if (!S)
1656 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregorebe10102009-08-20 07:17:43 +00001658 switch (S->getStmtClass()) {
1659 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001660
Douglas Gregorebe10102009-08-20 07:17:43 +00001661 // Transform individual statement nodes
1662#define STMT(Node, Parent) \
1663 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1664#define EXPR(Node, Parent)
1665#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001666
Douglas Gregorebe10102009-08-20 07:17:43 +00001667 // Transform expressions by calling TransformExpr.
1668#define STMT(Node, Parent)
1669#define EXPR(Node, Parent) case Stmt::Node##Class:
1670#include "clang/AST/StmtNodes.def"
1671 {
1672 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1673 if (E.isInvalid())
1674 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001675
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001676 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 }
Mike Stump11289f42009-09-09 15:08:12 +00001678 }
1679
Douglas Gregorebe10102009-08-20 07:17:43 +00001680 return SemaRef.Owned(S->Retain());
1681}
Mike Stump11289f42009-09-09 15:08:12 +00001682
1683
Douglas Gregore922c772009-08-04 22:27:00 +00001684template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001685Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 if (!E)
1687 return SemaRef.Owned(E);
1688
1689 switch (E->getStmtClass()) {
1690 case Stmt::NoStmtClass: break;
1691#define STMT(Node, Parent) case Stmt::Node##Class: break;
1692#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001693 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001694#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001695 }
1696
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001698}
1699
1700template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001701NestedNameSpecifier *
1702TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001703 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001704 QualType ObjectType,
1705 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001706 if (!NNS)
1707 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001708
Douglas Gregorebe10102009-08-20 07:17:43 +00001709 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001710 NestedNameSpecifier *Prefix = NNS->getPrefix();
1711 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001712 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001713 ObjectType,
1714 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001715 if (!Prefix)
1716 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001717
1718 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001719 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001721 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001722 }
Mike Stump11289f42009-09-09 15:08:12 +00001723
Douglas Gregor1135c352009-08-06 05:28:30 +00001724 switch (NNS->getKind()) {
1725 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001726 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001727 "Identifier nested-name-specifier with no prefix or object type");
1728 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1729 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001731
1732 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001733 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001734 ObjectType,
1735 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregor1135c352009-08-06 05:28:30 +00001737 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001738 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 = cast_or_null<NamespaceDecl>(
1740 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001741 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 Prefix == NNS->getPrefix() &&
1743 NS == NNS->getAsNamespace())
1744 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001745
Douglas Gregor1135c352009-08-06 05:28:30 +00001746 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1747 }
Mike Stump11289f42009-09-09 15:08:12 +00001748
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 case NestedNameSpecifier::Global:
1750 // There is no meaningful transformation that one could perform on the
1751 // global scope.
1752 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 case NestedNameSpecifier::TypeSpecWithTemplate:
1755 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001756 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001758 if (T.isNull())
1759 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregor1135c352009-08-06 05:28:30 +00001761 if (!getDerived().AlwaysRebuild() &&
1762 Prefix == NNS->getPrefix() &&
1763 T == QualType(NNS->getAsType(), 0))
1764 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001765
1766 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1767 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001768 T);
1769 }
1770 }
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001773 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001774}
1775
1776template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001777DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001778TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001779 SourceLocation Loc,
1780 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001781 if (!Name)
1782 return Name;
1783
1784 switch (Name.getNameKind()) {
1785 case DeclarationName::Identifier:
1786 case DeclarationName::ObjCZeroArgSelector:
1787 case DeclarationName::ObjCOneArgSelector:
1788 case DeclarationName::ObjCMultiArgSelector:
1789 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001790 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001791 case DeclarationName::CXXUsingDirective:
1792 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001793
Douglas Gregorf816bd72009-09-03 22:13:48 +00001794 case DeclarationName::CXXConstructorName:
1795 case DeclarationName::CXXDestructorName:
1796 case DeclarationName::CXXConversionFunctionName: {
1797 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001798 QualType T;
1799 if (!ObjectType.isNull() &&
1800 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1801 TemplateSpecializationType *SpecType
1802 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1803 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1804 } else
1805 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001806 if (T.isNull())
1807 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001808
Douglas Gregorf816bd72009-09-03 22:13:48 +00001809 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001810 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001811 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001812 }
Mike Stump11289f42009-09-09 15:08:12 +00001813 }
1814
Douglas Gregorf816bd72009-09-03 22:13:48 +00001815 return DeclarationName();
1816}
1817
1818template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001819TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001820TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1821 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001822 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001823 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001824 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1825 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1826 if (!NNS)
1827 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregor71dc5092009-08-06 06:41:21 +00001829 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001830 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001831 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1832 if (!TransTemplate)
1833 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001834
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 if (!getDerived().AlwaysRebuild() &&
1836 NNS == QTN->getQualifier() &&
1837 TransTemplate == Template)
1838 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001839
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1841 TransTemplate);
1842 }
Mike Stump11289f42009-09-09 15:08:12 +00001843
John McCalle66edc12009-11-24 19:00:30 +00001844 // These should be getting filtered out before they make it into the AST.
1845 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001849 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1851 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001852 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001853 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregor71dc5092009-08-06 06:41:21 +00001855 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001856 NNS == DTN->getQualifier() &&
1857 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71395fa2009-11-04 00:56:37 +00001860 if (DTN->isIdentifier())
1861 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1862 ObjectType);
1863
1864 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1865 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 }
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001869 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1871 if (!TransTemplate)
1872 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 if (!getDerived().AlwaysRebuild() &&
1875 TransTemplate == Template)
1876 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 return TemplateName(TransTemplate);
1879 }
Mike Stump11289f42009-09-09 15:08:12 +00001880
John McCalle66edc12009-11-24 19:00:30 +00001881 // These should be getting filtered out before they reach the AST.
1882 assert(false && "overloaded function decl survived to here");
1883 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884}
1885
1886template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001887void TreeTransform<Derived>::InventTemplateArgumentLoc(
1888 const TemplateArgument &Arg,
1889 TemplateArgumentLoc &Output) {
1890 SourceLocation Loc = getDerived().getBaseLocation();
1891 switch (Arg.getKind()) {
1892 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001893 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001894 break;
1895
1896 case TemplateArgument::Type:
1897 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001898 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001899
1900 break;
1901
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001902 case TemplateArgument::Template:
1903 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1904 break;
1905
John McCall0ad16662009-10-29 08:12:44 +00001906 case TemplateArgument::Expression:
1907 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1908 break;
1909
1910 case TemplateArgument::Declaration:
1911 case TemplateArgument::Integral:
1912 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001913 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001914 break;
1915 }
1916}
1917
1918template<typename Derived>
1919bool TreeTransform<Derived>::TransformTemplateArgument(
1920 const TemplateArgumentLoc &Input,
1921 TemplateArgumentLoc &Output) {
1922 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001923 switch (Arg.getKind()) {
1924 case TemplateArgument::Null:
1925 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001926 Output = Input;
1927 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001928
Douglas Gregore922c772009-08-04 22:27:00 +00001929 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001930 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001931 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001932 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001933
1934 DI = getDerived().TransformType(DI);
1935 if (!DI) return true;
1936
1937 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1938 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregore922c772009-08-04 22:27:00 +00001941 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001942 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001943 DeclarationName Name;
1944 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1945 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001946 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001947 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001948 if (!D) return true;
1949
John McCall0d07eb32009-10-29 18:45:58 +00001950 Expr *SourceExpr = Input.getSourceDeclExpression();
1951 if (SourceExpr) {
1952 EnterExpressionEvaluationContext Unevaluated(getSema(),
1953 Action::Unevaluated);
1954 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1955 if (E.isInvalid())
1956 SourceExpr = NULL;
1957 else {
1958 SourceExpr = E.takeAs<Expr>();
1959 SourceExpr->Retain();
1960 }
1961 }
1962
1963 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001964 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001965 }
Mike Stump11289f42009-09-09 15:08:12 +00001966
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001967 case TemplateArgument::Template: {
1968 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1969 TemplateName Template
1970 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1971 if (Template.isNull())
1972 return true;
1973
1974 Output = TemplateArgumentLoc(TemplateArgument(Template),
1975 Input.getTemplateQualifierRange(),
1976 Input.getTemplateNameLoc());
1977 return false;
1978 }
1979
Douglas Gregore922c772009-08-04 22:27:00 +00001980 case TemplateArgument::Expression: {
1981 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001982 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001983 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001984
John McCall0ad16662009-10-29 08:12:44 +00001985 Expr *InputExpr = Input.getSourceExpression();
1986 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1987
1988 Sema::OwningExprResult E
1989 = getDerived().TransformExpr(InputExpr);
1990 if (E.isInvalid()) return true;
1991
1992 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001993 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001994 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1995 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001996 }
Mike Stump11289f42009-09-09 15:08:12 +00001997
Douglas Gregore922c772009-08-04 22:27:00 +00001998 case TemplateArgument::Pack: {
1999 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2000 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002001 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002002 AEnd = Arg.pack_end();
2003 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002004
John McCall0ad16662009-10-29 08:12:44 +00002005 // FIXME: preserve source information here when we start
2006 // caring about parameter packs.
2007
John McCall0d07eb32009-10-29 18:45:58 +00002008 TemplateArgumentLoc InputArg;
2009 TemplateArgumentLoc OutputArg;
2010 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2011 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002012 return true;
2013
John McCall0d07eb32009-10-29 18:45:58 +00002014 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002015 }
2016 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002017 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002018 true);
John McCall0d07eb32009-10-29 18:45:58 +00002019 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002020 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002021 }
2022 }
Mike Stump11289f42009-09-09 15:08:12 +00002023
Douglas Gregore922c772009-08-04 22:27:00 +00002024 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002025 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002026}
2027
Douglas Gregord6ff3322009-08-04 16:50:30 +00002028//===----------------------------------------------------------------------===//
2029// Type transformation
2030//===----------------------------------------------------------------------===//
2031
2032template<typename Derived>
2033QualType TreeTransform<Derived>::TransformType(QualType T) {
2034 if (getDerived().AlreadyTransformed(T))
2035 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002036
John McCall550e0c22009-10-21 00:40:46 +00002037 // Temporary workaround. All of these transformations should
2038 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002039 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002040 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002041
John McCallbcd03502009-12-07 02:54:59 +00002042 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002043
John McCall550e0c22009-10-21 00:40:46 +00002044 if (!NewDI)
2045 return QualType();
2046
2047 return NewDI->getType();
2048}
2049
2050template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002051TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002052 if (getDerived().AlreadyTransformed(DI->getType()))
2053 return DI;
2054
2055 TypeLocBuilder TLB;
2056
2057 TypeLoc TL = DI->getTypeLoc();
2058 TLB.reserve(TL.getFullDataSize());
2059
2060 QualType Result = getDerived().TransformType(TLB, TL);
2061 if (Result.isNull())
2062 return 0;
2063
John McCallbcd03502009-12-07 02:54:59 +00002064 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002065}
2066
2067template<typename Derived>
2068QualType
2069TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2070 switch (T.getTypeLocClass()) {
2071#define ABSTRACT_TYPELOC(CLASS, PARENT)
2072#define TYPELOC(CLASS, PARENT) \
2073 case TypeLoc::CLASS: \
2074 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2075#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002076 }
Mike Stump11289f42009-09-09 15:08:12 +00002077
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002078 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002079 return QualType();
2080}
2081
2082/// FIXME: By default, this routine adds type qualifiers only to types
2083/// that can have qualifiers, and silently suppresses those qualifiers
2084/// that are not permitted (e.g., qualifiers on reference or function
2085/// types). This is the right thing for template instantiation, but
2086/// probably not for other clients.
2087template<typename Derived>
2088QualType
2089TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2090 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002091 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002092
2093 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2094 if (Result.isNull())
2095 return QualType();
2096
2097 // Silently suppress qualifiers if the result type can't be qualified.
2098 // FIXME: this is the right thing for template instantiation, but
2099 // probably not for other clients.
2100 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002101 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002102
John McCall550e0c22009-10-21 00:40:46 +00002103 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2104
2105 TLB.push<QualifiedTypeLoc>(Result);
2106
2107 // No location information to preserve.
2108
2109 return Result;
2110}
2111
2112template <class TyLoc> static inline
2113QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2114 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2115 NewT.setNameLoc(T.getNameLoc());
2116 return T.getType();
2117}
2118
2119// Ugly metaprogramming macros because I couldn't be bothered to make
2120// the equivalent template version work.
2121#define TransformPointerLikeType(TypeClass) do { \
2122 QualType PointeeType \
2123 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2124 if (PointeeType.isNull()) \
2125 return QualType(); \
2126 \
2127 QualType Result = TL.getType(); \
2128 if (getDerived().AlwaysRebuild() || \
2129 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002130 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2131 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002132 if (Result.isNull()) \
2133 return QualType(); \
2134 } \
2135 \
2136 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2137 NewT.setSigilLoc(TL.getSigilLoc()); \
2138 \
2139 return Result; \
2140} while(0)
2141
John McCall550e0c22009-10-21 00:40:46 +00002142template<typename Derived>
2143QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2144 BuiltinTypeLoc T) {
2145 return TransformTypeSpecType(TLB, T);
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) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 QualType T;
3857 {
3858 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003859 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003860 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3861 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregora16548e2009-08-11 05:31:07 +00003863 T = getDerived().TransformType(E->getType());
3864 if (T.isNull())
3865 return SemaRef.ExprError();
3866 }
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3869 if (Init.isInvalid())
3870 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregora16548e2009-08-11 05:31:07 +00003872 if (!getDerived().AlwaysRebuild() &&
3873 T == E->getType() &&
3874 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003875 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003876
3877 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3878 /*FIXME:*/E->getInitializer()->getLocEnd(),
3879 move(Init));
3880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregora16548e2009-08-11 05:31:07 +00003882template<typename Derived>
3883Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003884TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3886 if (Base.isInvalid())
3887 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregora16548e2009-08-11 05:31:07 +00003889 if (!getDerived().AlwaysRebuild() &&
3890 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003891 return SemaRef.Owned(E->Retain());
3892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003894 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003895 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3896 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3897 E->getAccessorLoc(),
3898 E->getAccessor());
3899}
Mike Stump11289f42009-09-09 15:08:12 +00003900
Douglas Gregora16548e2009-08-11 05:31:07 +00003901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003902Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003903TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregora16548e2009-08-11 05:31:07 +00003906 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3907 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3908 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3909 if (Init.isInvalid())
3910 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 InitChanged = InitChanged || Init.get() != E->getInit(I);
3913 Inits.push_back(Init.takeAs<Expr>());
3914 }
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003917 return SemaRef.Owned(E->Retain());
3918
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003920 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregora16548e2009-08-11 05:31:07 +00003923template<typename Derived>
3924Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003925TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregorebe10102009-08-20 07:17:43 +00003928 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3930 if (Init.isInvalid())
3931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003932
Douglas Gregorebe10102009-08-20 07:17:43 +00003933 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3935 bool ExprChanged = false;
3936 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3937 DEnd = E->designators_end();
3938 D != DEnd; ++D) {
3939 if (D->isFieldDesignator()) {
3940 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3941 D->getDotLoc(),
3942 D->getFieldLoc()));
3943 continue;
3944 }
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946 if (D->isArrayDesignator()) {
3947 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3948 if (Index.isInvalid())
3949 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003950
3951 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3955 ArrayExprs.push_back(Index.release());
3956 continue;
3957 }
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003960 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3962 if (Start.isInvalid())
3963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003964
Douglas Gregora16548e2009-08-11 05:31:07 +00003965 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3966 if (End.isInvalid())
3967 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003968
3969 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 End.get(),
3971 D->getLBracketLoc(),
3972 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3975 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003976
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 ArrayExprs.push_back(Start.release());
3978 ArrayExprs.push_back(End.release());
3979 }
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 if (!getDerived().AlwaysRebuild() &&
3982 Init.get() == E->getInit() &&
3983 !ExprChanged)
3984 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3987 E->getEqualOrColonLoc(),
3988 E->usesGNUSyntax(), move(Init));
3989}
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003992Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003993TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003994 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003995 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3996
3997 // FIXME: Will we ever have proper type location here? Will we actually
3998 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003999 QualType T = getDerived().TransformType(E->getType());
4000 if (T.isNull())
4001 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 if (!getDerived().AlwaysRebuild() &&
4004 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004005 return SemaRef.Owned(E->Retain());
4006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 return getDerived().RebuildImplicitValueInitExpr(T);
4008}
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004011Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004012TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004013 // FIXME: Do we want the type as written?
4014 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004015
Douglas Gregora16548e2009-08-11 05:31:07 +00004016 {
4017 // FIXME: Source location isn't quite accurate.
4018 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4019 T = getDerived().TransformType(E->getType());
4020 if (T.isNull())
4021 return SemaRef.ExprError();
4022 }
Mike Stump11289f42009-09-09 15:08:12 +00004023
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4025 if (SubExpr.isInvalid())
4026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028 if (!getDerived().AlwaysRebuild() &&
4029 T == E->getType() &&
4030 SubExpr.get() == E->getSubExpr())
4031 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4034 T, E->getRParenLoc());
4035}
4036
4037template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004038Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004039TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004040 bool ArgumentChanged = false;
4041 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4042 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4043 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4044 if (Init.isInvalid())
4045 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregora16548e2009-08-11 05:31:07 +00004047 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4048 Inits.push_back(Init.takeAs<Expr>());
4049 }
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4052 move_arg(Inits),
4053 E->getRParenLoc());
4054}
Mike Stump11289f42009-09-09 15:08:12 +00004055
Douglas Gregora16548e2009-08-11 05:31:07 +00004056/// \brief Transform an address-of-label expression.
4057///
4058/// By default, the transformation of an address-of-label expression always
4059/// rebuilds the expression, so that the label identifier can be resolved to
4060/// the corresponding label statement by semantic analysis.
4061template<typename Derived>
4062Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004063TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4065 E->getLabel());
4066}
Mike Stump11289f42009-09-09 15:08:12 +00004067
4068template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004069Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004070TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004071 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004072 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4073 if (SubStmt.isInvalid())
4074 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004075
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 if (!getDerived().AlwaysRebuild() &&
4077 SubStmt.get() == E->getSubStmt())
4078 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004079
4080 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 move(SubStmt),
4082 E->getRParenLoc());
4083}
Mike Stump11289f42009-09-09 15:08:12 +00004084
Douglas Gregora16548e2009-08-11 05:31:07 +00004085template<typename Derived>
4086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004087TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 QualType T1, T2;
4089 {
4090 // FIXME: Source location isn't quite accurate.
4091 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004092
Douglas Gregora16548e2009-08-11 05:31:07 +00004093 T1 = getDerived().TransformType(E->getArgType1());
4094 if (T1.isNull())
4095 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 T2 = getDerived().TransformType(E->getArgType2());
4098 if (T2.isNull())
4099 return SemaRef.ExprError();
4100 }
4101
4102 if (!getDerived().AlwaysRebuild() &&
4103 T1 == E->getArgType1() &&
4104 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004105 return SemaRef.Owned(E->Retain());
4106
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4108 T1, T2, E->getRParenLoc());
4109}
Mike Stump11289f42009-09-09 15:08:12 +00004110
Douglas Gregora16548e2009-08-11 05:31:07 +00004111template<typename Derived>
4112Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004113TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004114 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4115 if (Cond.isInvalid())
4116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004117
Douglas Gregora16548e2009-08-11 05:31:07 +00004118 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4119 if (LHS.isInvalid())
4120 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4123 if (RHS.isInvalid())
4124 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregora16548e2009-08-11 05:31:07 +00004126 if (!getDerived().AlwaysRebuild() &&
4127 Cond.get() == E->getCond() &&
4128 LHS.get() == E->getLHS() &&
4129 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004130 return SemaRef.Owned(E->Retain());
4131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4133 move(Cond), move(LHS), move(RHS),
4134 E->getRParenLoc());
4135}
Mike Stump11289f42009-09-09 15:08:12 +00004136
Douglas Gregora16548e2009-08-11 05:31:07 +00004137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004139TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004140 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004141}
4142
4143template<typename Derived>
4144Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004145TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004146 switch (E->getOperator()) {
4147 case OO_New:
4148 case OO_Delete:
4149 case OO_Array_New:
4150 case OO_Array_Delete:
4151 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4152 return SemaRef.ExprError();
4153
4154 case OO_Call: {
4155 // This is a call to an object's operator().
4156 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4157
4158 // Transform the object itself.
4159 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4160 if (Object.isInvalid())
4161 return SemaRef.ExprError();
4162
4163 // FIXME: Poor location information
4164 SourceLocation FakeLParenLoc
4165 = SemaRef.PP.getLocForEndOfToken(
4166 static_cast<Expr *>(Object.get())->getLocEnd());
4167
4168 // Transform the call arguments.
4169 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4170 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4171 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004172 if (getDerived().DropCallArgument(E->getArg(I)))
4173 break;
4174
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004175 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4176 if (Arg.isInvalid())
4177 return SemaRef.ExprError();
4178
4179 // FIXME: Poor source location information.
4180 SourceLocation FakeCommaLoc
4181 = SemaRef.PP.getLocForEndOfToken(
4182 static_cast<Expr *>(Arg.get())->getLocEnd());
4183 FakeCommaLocs.push_back(FakeCommaLoc);
4184 Args.push_back(Arg.release());
4185 }
4186
4187 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4188 move_arg(Args),
4189 FakeCommaLocs.data(),
4190 E->getLocEnd());
4191 }
4192
4193#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4194 case OO_##Name:
4195#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4196#include "clang/Basic/OperatorKinds.def"
4197 case OO_Subscript:
4198 // Handled below.
4199 break;
4200
4201 case OO_Conditional:
4202 llvm_unreachable("conditional operator is not actually overloadable");
4203 return SemaRef.ExprError();
4204
4205 case OO_None:
4206 case NUM_OVERLOADED_OPERATORS:
4207 llvm_unreachable("not an overloaded operator?");
4208 return SemaRef.ExprError();
4209 }
4210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4212 if (Callee.isInvalid())
4213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004214
John McCall47f29ea2009-12-08 09:21:05 +00004215 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 if (First.isInvalid())
4217 return SemaRef.ExprError();
4218
4219 OwningExprResult Second(SemaRef);
4220 if (E->getNumArgs() == 2) {
4221 Second = getDerived().TransformExpr(E->getArg(1));
4222 if (Second.isInvalid())
4223 return SemaRef.ExprError();
4224 }
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 if (!getDerived().AlwaysRebuild() &&
4227 Callee.get() == E->getCallee() &&
4228 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004229 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4230 return SemaRef.Owned(E->Retain());
4231
Douglas Gregora16548e2009-08-11 05:31:07 +00004232 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4233 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004234 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004235 move(First),
4236 move(Second));
4237}
Mike Stump11289f42009-09-09 15:08:12 +00004238
Douglas Gregora16548e2009-08-11 05:31:07 +00004239template<typename Derived>
4240Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004241TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4242 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004243}
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004246Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004247TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004248 TypeSourceInfo *OldT;
4249 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004250 {
4251 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004252 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4254 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004255
John McCall97513962010-01-15 18:39:57 +00004256 OldT = E->getTypeInfoAsWritten();
4257 NewT = getDerived().TransformType(OldT);
4258 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 return SemaRef.ExprError();
4260 }
Mike Stump11289f42009-09-09 15:08:12 +00004261
Douglas Gregor6131b442009-12-12 18:16:41 +00004262 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004263 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004264 if (SubExpr.isInvalid())
4265 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004268 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004270 return SemaRef.Owned(E->Retain());
4271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004273 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4275 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4276 SourceLocation FakeRParenLoc
4277 = SemaRef.PP.getLocForEndOfToken(
4278 E->getSubExpr()->getSourceRange().getEnd());
4279 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004280 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004282 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 FakeRAngleLoc,
4284 FakeRAngleLoc,
4285 move(SubExpr),
4286 FakeRParenLoc);
4287}
Mike Stump11289f42009-09-09 15:08:12 +00004288
Douglas Gregora16548e2009-08-11 05:31:07 +00004289template<typename Derived>
4290Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004291TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4292 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004293}
Mike Stump11289f42009-09-09 15:08:12 +00004294
4295template<typename Derived>
4296Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004297TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4298 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004299}
4300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301template<typename Derived>
4302Sema::OwningExprResult
4303TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004304 CXXReinterpretCastExpr *E) {
4305 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004306}
Mike Stump11289f42009-09-09 15:08:12 +00004307
Douglas Gregora16548e2009-08-11 05:31:07 +00004308template<typename Derived>
4309Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004310TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4311 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004312}
Mike Stump11289f42009-09-09 15:08:12 +00004313
Douglas Gregora16548e2009-08-11 05:31:07 +00004314template<typename Derived>
4315Sema::OwningExprResult
4316TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004317 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004318 TypeSourceInfo *OldT;
4319 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 {
4321 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004322
John McCall97513962010-01-15 18:39:57 +00004323 OldT = E->getTypeInfoAsWritten();
4324 NewT = getDerived().TransformType(OldT);
4325 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 return SemaRef.ExprError();
4327 }
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregor6131b442009-12-12 18:16:41 +00004329 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004330 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 if (SubExpr.isInvalid())
4332 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004335 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004337 return SemaRef.Owned(E->Retain());
4338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 // FIXME: The end of the type's source range is wrong
4340 return getDerived().RebuildCXXFunctionalCastExpr(
4341 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004342 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 /*FIXME:*/E->getSubExpr()->getLocStart(),
4344 move(SubExpr),
4345 E->getRParenLoc());
4346}
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348template<typename Derived>
4349Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004350TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 if (E->isTypeOperand()) {
4352 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 QualType T = getDerived().TransformType(E->getTypeOperand());
4355 if (T.isNull())
4356 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004357
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 if (!getDerived().AlwaysRebuild() &&
4359 T == E->getTypeOperand())
4360 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004361
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4363 /*FIXME:*/E->getLocStart(),
4364 T,
4365 E->getLocEnd());
4366 }
Mike Stump11289f42009-09-09 15:08:12 +00004367
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 // We don't know whether the expression is potentially evaluated until
4369 // after we perform semantic analysis, so the expression is potentially
4370 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004371 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4375 if (SubExpr.isInvalid())
4376 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378 if (!getDerived().AlwaysRebuild() &&
4379 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004380 return SemaRef.Owned(E->Retain());
4381
Douglas Gregora16548e2009-08-11 05:31:07 +00004382 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4383 /*FIXME:*/E->getLocStart(),
4384 move(SubExpr),
4385 E->getLocEnd());
4386}
4387
4388template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004389Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004390TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
4396TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004397 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004398 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401template<typename Derived>
4402Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004403TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 QualType T = getDerived().TransformType(E->getType());
4407 if (T.isNull())
4408 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 if (!getDerived().AlwaysRebuild() &&
4411 T == E->getType())
4412 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregorb15af892010-01-07 23:12:05 +00004414 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4421 if (SubExpr.isInvalid())
4422 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004423
Douglas Gregora16548e2009-08-11 05:31:07 +00004424 if (!getDerived().AlwaysRebuild() &&
4425 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004426 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004427
4428 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4429}
Mike Stump11289f42009-09-09 15:08:12 +00004430
Douglas Gregora16548e2009-08-11 05:31:07 +00004431template<typename Derived>
4432Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004433TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004434 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4436 if (!Param)
4437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 if (getDerived().AlwaysRebuild() &&
4440 Param == E->getParam())
4441 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregor033f6752009-12-23 23:03:06 +00004443 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004444}
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregora16548e2009-08-11 05:31:07 +00004446template<typename Derived>
4447Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004448TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4450
4451 QualType T = getDerived().TransformType(E->getType());
4452 if (T.isNull())
4453 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 if (!getDerived().AlwaysRebuild() &&
4456 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004457 return SemaRef.Owned(E->Retain());
4458
4459 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 /*FIXME:*/E->getTypeBeginLoc(),
4461 T,
4462 E->getRParenLoc());
4463}
Mike Stump11289f42009-09-09 15:08:12 +00004464
Douglas Gregora16548e2009-08-11 05:31:07 +00004465template<typename Derived>
4466Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004467TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 // Transform the type that we're allocating
4469 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4470 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4471 if (AllocType.isNull())
4472 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004473
Douglas Gregora16548e2009-08-11 05:31:07 +00004474 // Transform the size of the array we're allocating (if any).
4475 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4476 if (ArraySize.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 // Transform the placement arguments (if any).
4480 bool ArgumentChanged = false;
4481 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4482 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4483 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4484 if (Arg.isInvalid())
4485 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4488 PlacementArgs.push_back(Arg.take());
4489 }
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregorebe10102009-08-20 07:17:43 +00004491 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4493 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4494 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4495 if (Arg.isInvalid())
4496 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregora16548e2009-08-11 05:31:07 +00004498 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4499 ConstructorArgs.push_back(Arg.take());
4500 }
Mike Stump11289f42009-09-09 15:08:12 +00004501
Douglas Gregora16548e2009-08-11 05:31:07 +00004502 if (!getDerived().AlwaysRebuild() &&
4503 AllocType == E->getAllocatedType() &&
4504 ArraySize.get() == E->getArraySize() &&
4505 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004506 return SemaRef.Owned(E->Retain());
4507
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004508 if (!ArraySize.get()) {
4509 // If no array size was specified, but the new expression was
4510 // instantiated with an array type (e.g., "new T" where T is
4511 // instantiated with "int[4]"), extract the outer bound from the
4512 // array type as our array size. We do this with constant and
4513 // dependently-sized array types.
4514 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4515 if (!ArrayT) {
4516 // Do nothing
4517 } else if (const ConstantArrayType *ConsArrayT
4518 = dyn_cast<ConstantArrayType>(ArrayT)) {
4519 ArraySize
4520 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4521 ConsArrayT->getSize(),
4522 SemaRef.Context.getSizeType(),
4523 /*FIXME:*/E->getLocStart()));
4524 AllocType = ConsArrayT->getElementType();
4525 } else if (const DependentSizedArrayType *DepArrayT
4526 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4527 if (DepArrayT->getSizeExpr()) {
4528 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4529 AllocType = DepArrayT->getElementType();
4530 }
4531 }
4532 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4534 E->isGlobalNew(),
4535 /*FIXME:*/E->getLocStart(),
4536 move_arg(PlacementArgs),
4537 /*FIXME:*/E->getLocStart(),
4538 E->isParenTypeId(),
4539 AllocType,
4540 /*FIXME:*/E->getLocStart(),
4541 /*FIXME:*/SourceRange(),
4542 move(ArraySize),
4543 /*FIXME:*/E->getLocStart(),
4544 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004545 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548template<typename Derived>
4549Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004550TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4552 if (Operand.isInvalid())
4553 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004554
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004556 Operand.get() == E->getArgument())
4557 return SemaRef.Owned(E->Retain());
4558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4560 E->isGlobalDelete(),
4561 E->isArrayForm(),
4562 move(Operand));
4563}
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565template<typename Derived>
4566Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004567TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004568 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004569 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4570 if (Base.isInvalid())
4571 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004572
Douglas Gregorad8a3362009-09-04 17:36:40 +00004573 NestedNameSpecifier *Qualifier
4574 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4575 E->getQualifierRange());
4576 if (E->getQualifier() && !Qualifier)
4577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregorad8a3362009-09-04 17:36:40 +00004579 QualType DestroyedType;
4580 {
4581 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4582 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4583 if (DestroyedType.isNull())
4584 return SemaRef.ExprError();
4585 }
Mike Stump11289f42009-09-09 15:08:12 +00004586
Douglas Gregorad8a3362009-09-04 17:36:40 +00004587 if (!getDerived().AlwaysRebuild() &&
4588 Base.get() == E->getBase() &&
4589 Qualifier == E->getQualifier() &&
4590 DestroyedType == E->getDestroyedType())
4591 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004592
Douglas Gregorad8a3362009-09-04 17:36:40 +00004593 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4594 E->getOperatorLoc(),
4595 E->isArrow(),
4596 E->getDestroyedTypeLoc(),
4597 DestroyedType,
4598 Qualifier,
4599 E->getQualifierRange());
4600}
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregorad8a3362009-09-04 17:36:40 +00004602template<typename Derived>
4603Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004604TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004605 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004606 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4607
4608 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4609 Sema::LookupOrdinaryName);
4610
4611 // Transform all the decls.
4612 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4613 E = Old->decls_end(); I != E; ++I) {
4614 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004615 if (!InstD) {
4616 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4617 // This can happen because of dependent hiding.
4618 if (isa<UsingShadowDecl>(*I))
4619 continue;
4620 else
4621 return SemaRef.ExprError();
4622 }
John McCalle66edc12009-11-24 19:00:30 +00004623
4624 // Expand using declarations.
4625 if (isa<UsingDecl>(InstD)) {
4626 UsingDecl *UD = cast<UsingDecl>(InstD);
4627 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4628 E = UD->shadow_end(); I != E; ++I)
4629 R.addDecl(*I);
4630 continue;
4631 }
4632
4633 R.addDecl(InstD);
4634 }
4635
4636 // Resolve a kind, but don't do any further analysis. If it's
4637 // ambiguous, the callee needs to deal with it.
4638 R.resolveKind();
4639
4640 // Rebuild the nested-name qualifier, if present.
4641 CXXScopeSpec SS;
4642 NestedNameSpecifier *Qualifier = 0;
4643 if (Old->getQualifier()) {
4644 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4645 Old->getQualifierRange());
4646 if (!Qualifier)
4647 return SemaRef.ExprError();
4648
4649 SS.setScopeRep(Qualifier);
4650 SS.setRange(Old->getQualifierRange());
4651 }
4652
4653 // If we have no template arguments, it's a normal declaration name.
4654 if (!Old->hasExplicitTemplateArgs())
4655 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4656
4657 // If we have template arguments, rebuild them, then rebuild the
4658 // templateid expression.
4659 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4660 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4661 TemplateArgumentLoc Loc;
4662 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4663 return SemaRef.ExprError();
4664 TransArgs.addArgument(Loc);
4665 }
4666
4667 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4668 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004669}
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671template<typename Derived>
4672Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004673TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004674 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 QualType T = getDerived().TransformType(E->getQueriedType());
4677 if (T.isNull())
4678 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 if (!getDerived().AlwaysRebuild() &&
4681 T == E->getQueriedType())
4682 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 // FIXME: Bad location information
4685 SourceLocation FakeLParenLoc
4686 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004687
4688 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 E->getLocStart(),
4690 /*FIXME:*/FakeLParenLoc,
4691 T,
4692 E->getLocEnd());
4693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695template<typename Derived>
4696Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004697TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004698 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004700 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4701 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 if (!NNS)
4703 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004704
4705 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004706 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4707 if (!Name)
4708 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004709
John McCalle66edc12009-11-24 19:00:30 +00004710 if (!E->hasExplicitTemplateArgs()) {
4711 if (!getDerived().AlwaysRebuild() &&
4712 NNS == E->getQualifier() &&
4713 Name == E->getDeclName())
4714 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004715
John McCalle66edc12009-11-24 19:00:30 +00004716 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4717 E->getQualifierRange(),
4718 Name, E->getLocation(),
4719 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004720 }
John McCall6b51f282009-11-23 01:53:49 +00004721
4722 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004724 TemplateArgumentLoc Loc;
4725 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004726 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004727 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 }
4729
John McCalle66edc12009-11-24 19:00:30 +00004730 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4731 E->getQualifierRange(),
4732 Name, E->getLocation(),
4733 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004734}
4735
4736template<typename Derived>
4737Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004738TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4740
4741 QualType T = getDerived().TransformType(E->getType());
4742 if (T.isNull())
4743 return SemaRef.ExprError();
4744
4745 CXXConstructorDecl *Constructor
4746 = cast_or_null<CXXConstructorDecl>(
4747 getDerived().TransformDecl(E->getConstructor()));
4748 if (!Constructor)
4749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004750
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 bool ArgumentChanged = false;
4752 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004753 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 ArgEnd = E->arg_end();
4755 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004756 if (getDerived().DropCallArgument(*Arg)) {
4757 ArgumentChanged = true;
4758 break;
4759 }
4760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4762 if (TransArg.isInvalid())
4763 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4766 Args.push_back(TransArg.takeAs<Expr>());
4767 }
4768
4769 if (!getDerived().AlwaysRebuild() &&
4770 T == E->getType() &&
4771 Constructor == E->getConstructor() &&
4772 !ArgumentChanged)
4773 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregordb121ba2009-12-14 16:27:04 +00004775 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4776 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 move_arg(Args));
4778}
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780/// \brief Transform a C++ temporary-binding expression.
4781///
Douglas Gregor363b1512009-12-24 18:51:59 +00004782/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4783/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004784template<typename Derived>
4785Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004786TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004787 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004788}
Mike Stump11289f42009-09-09 15:08:12 +00004789
4790/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004791/// be destroyed after the expression is evaluated.
4792///
Douglas Gregor363b1512009-12-24 18:51:59 +00004793/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4794/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004795template<typename Derived>
4796Sema::OwningExprResult
4797TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004798 CXXExprWithTemporaries *E) {
4799 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004800}
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802template<typename Derived>
4803Sema::OwningExprResult
4804TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004805 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4807 QualType T = getDerived().TransformType(E->getType());
4808 if (T.isNull())
4809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 CXXConstructorDecl *Constructor
4812 = cast_or_null<CXXConstructorDecl>(
4813 getDerived().TransformDecl(E->getConstructor()));
4814 if (!Constructor)
4815 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 bool ArgumentChanged = false;
4818 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4819 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004820 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 ArgEnd = E->arg_end();
4822 Arg != ArgEnd; ++Arg) {
4823 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4824 if (TransArg.isInvalid())
4825 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004826
Douglas Gregora16548e2009-08-11 05:31:07 +00004827 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4828 Args.push_back((Expr *)TransArg.release());
4829 }
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 if (!getDerived().AlwaysRebuild() &&
4832 T == E->getType() &&
4833 Constructor == E->getConstructor() &&
4834 !ArgumentChanged)
4835 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 // FIXME: Bogus location information
4838 SourceLocation CommaLoc;
4839 if (Args.size() > 1) {
4840 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004841 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4843 }
4844 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4845 T,
4846 /*FIXME:*/E->getTypeBeginLoc(),
4847 move_arg(Args),
4848 &CommaLoc,
4849 E->getLocEnd());
4850}
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregora16548e2009-08-11 05:31:07 +00004852template<typename Derived>
4853Sema::OwningExprResult
4854TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004855 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4857 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4858 if (T.isNull())
4859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 bool ArgumentChanged = false;
4862 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4863 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4864 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4865 ArgEnd = E->arg_end();
4866 Arg != ArgEnd; ++Arg) {
4867 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4868 if (TransArg.isInvalid())
4869 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4872 FakeCommaLocs.push_back(
4873 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4874 Args.push_back(TransArg.takeAs<Expr>());
4875 }
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 if (!getDerived().AlwaysRebuild() &&
4878 T == E->getTypeAsWritten() &&
4879 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004880 return SemaRef.Owned(E->Retain());
4881
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 // FIXME: we're faking the locations of the commas
4883 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4884 T,
4885 E->getLParenLoc(),
4886 move_arg(Args),
4887 FakeCommaLocs.data(),
4888 E->getRParenLoc());
4889}
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891template<typename Derived>
4892Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004893TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004894 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004895 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004896 OwningExprResult Base(SemaRef, (Expr*) 0);
4897 Expr *OldBase;
4898 QualType BaseType;
4899 QualType ObjectType;
4900 if (!E->isImplicitAccess()) {
4901 OldBase = E->getBase();
4902 Base = getDerived().TransformExpr(OldBase);
4903 if (Base.isInvalid())
4904 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004905
John McCall2d74de92009-12-01 22:10:20 +00004906 // Start the member reference and compute the object's type.
4907 Sema::TypeTy *ObjectTy = 0;
4908 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4909 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004910 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004911 ObjectTy);
4912 if (Base.isInvalid())
4913 return SemaRef.ExprError();
4914
4915 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4916 BaseType = ((Expr*) Base.get())->getType();
4917 } else {
4918 OldBase = 0;
4919 BaseType = getDerived().TransformType(E->getBaseType());
4920 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4921 }
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004923 // Transform the first part of the nested-name-specifier that qualifies
4924 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004925 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004926 = getDerived().TransformFirstQualifierInScope(
4927 E->getFirstQualifierFoundInScope(),
4928 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004930 NestedNameSpecifier *Qualifier = 0;
4931 if (E->getQualifier()) {
4932 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4933 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004934 ObjectType,
4935 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004936 if (!Qualifier)
4937 return SemaRef.ExprError();
4938 }
Mike Stump11289f42009-09-09 15:08:12 +00004939
4940 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004941 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004942 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004943 if (!Name)
4944 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004945
John McCall2d74de92009-12-01 22:10:20 +00004946 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004947 // This is a reference to a member without an explicitly-specified
4948 // template argument list. Optimize for this common case.
4949 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004950 Base.get() == OldBase &&
4951 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004952 Qualifier == E->getQualifier() &&
4953 Name == E->getMember() &&
4954 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004955 return SemaRef.Owned(E->Retain());
4956
John McCall8cd78132009-11-19 22:55:06 +00004957 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004958 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004959 E->isArrow(),
4960 E->getOperatorLoc(),
4961 Qualifier,
4962 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004963 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004964 Name,
4965 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004966 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004967 }
4968
John McCall6b51f282009-11-23 01:53:49 +00004969 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004970 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004971 TemplateArgumentLoc Loc;
4972 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004973 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004974 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004975 }
Mike Stump11289f42009-09-09 15:08:12 +00004976
John McCall8cd78132009-11-19 22:55:06 +00004977 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004978 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 E->isArrow(),
4980 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004981 Qualifier,
4982 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004983 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004984 Name,
4985 E->getMemberLoc(),
4986 &TransArgs);
4987}
4988
4989template<typename Derived>
4990Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004991TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004992 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004993 OwningExprResult Base(SemaRef, (Expr*) 0);
4994 QualType BaseType;
4995 if (!Old->isImplicitAccess()) {
4996 Base = getDerived().TransformExpr(Old->getBase());
4997 if (Base.isInvalid())
4998 return SemaRef.ExprError();
4999 BaseType = ((Expr*) Base.get())->getType();
5000 } else {
5001 BaseType = getDerived().TransformType(Old->getBaseType());
5002 }
John McCall10eae182009-11-30 22:42:35 +00005003
5004 NestedNameSpecifier *Qualifier = 0;
5005 if (Old->getQualifier()) {
5006 Qualifier
5007 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5008 Old->getQualifierRange());
5009 if (Qualifier == 0)
5010 return SemaRef.ExprError();
5011 }
5012
5013 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5014 Sema::LookupOrdinaryName);
5015
5016 // Transform all the decls.
5017 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5018 E = Old->decls_end(); I != E; ++I) {
5019 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005020 if (!InstD) {
5021 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5022 // This can happen because of dependent hiding.
5023 if (isa<UsingShadowDecl>(*I))
5024 continue;
5025 else
5026 return SemaRef.ExprError();
5027 }
John McCall10eae182009-11-30 22:42:35 +00005028
5029 // Expand using declarations.
5030 if (isa<UsingDecl>(InstD)) {
5031 UsingDecl *UD = cast<UsingDecl>(InstD);
5032 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5033 E = UD->shadow_end(); I != E; ++I)
5034 R.addDecl(*I);
5035 continue;
5036 }
5037
5038 R.addDecl(InstD);
5039 }
5040
5041 R.resolveKind();
5042
5043 TemplateArgumentListInfo TransArgs;
5044 if (Old->hasExplicitTemplateArgs()) {
5045 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5046 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5047 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5048 TemplateArgumentLoc Loc;
5049 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5050 Loc))
5051 return SemaRef.ExprError();
5052 TransArgs.addArgument(Loc);
5053 }
5054 }
John McCall38836f02010-01-15 08:34:02 +00005055
5056 // FIXME: to do this check properly, we will need to preserve the
5057 // first-qualifier-in-scope here, just in case we had a dependent
5058 // base (and therefore couldn't do the check) and a
5059 // nested-name-qualifier (and therefore could do the lookup).
5060 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005061
5062 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005063 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005064 Old->getOperatorLoc(),
5065 Old->isArrow(),
5066 Qualifier,
5067 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005068 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005069 R,
5070 (Old->hasExplicitTemplateArgs()
5071 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005072}
5073
5074template<typename Derived>
5075Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005076TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005077 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005078}
5079
Mike Stump11289f42009-09-09 15:08:12 +00005080template<typename Derived>
5081Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 // FIXME: poor source location
5084 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5085 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5086 if (EncodedType.isNull())
5087 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089 if (!getDerived().AlwaysRebuild() &&
5090 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005091 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005092
5093 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5094 EncodedType,
5095 E->getRParenLoc());
5096}
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregora16548e2009-08-11 05:31:07 +00005098template<typename Derived>
5099Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005100TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005101 // FIXME: Implement this!
5102 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005103 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005104}
5105
Mike Stump11289f42009-09-09 15:08:12 +00005106template<typename Derived>
5107Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005108TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005109 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005110}
5111
Mike Stump11289f42009-09-09 15:08:12 +00005112template<typename Derived>
5113Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005115 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005116 = cast_or_null<ObjCProtocolDecl>(
5117 getDerived().TransformDecl(E->getProtocol()));
5118 if (!Protocol)
5119 return SemaRef.ExprError();
5120
5121 if (!getDerived().AlwaysRebuild() &&
5122 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005123 return SemaRef.Owned(E->Retain());
5124
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 return getDerived().RebuildObjCProtocolExpr(Protocol,
5126 E->getAtLoc(),
5127 /*FIXME:*/E->getAtLoc(),
5128 /*FIXME:*/E->getAtLoc(),
5129 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131}
5132
Mike Stump11289f42009-09-09 15:08:12 +00005133template<typename Derived>
5134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005135TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005136 // FIXME: Implement this!
5137 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005138 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005139}
5140
Mike Stump11289f42009-09-09 15:08:12 +00005141template<typename Derived>
5142Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005143TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 // FIXME: Implement this!
5145 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005146 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005147}
5148
Mike Stump11289f42009-09-09 15:08:12 +00005149template<typename Derived>
5150Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005151TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005152 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 // FIXME: Implement this!
5154 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005155 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005156}
5157
Mike Stump11289f42009-09-09 15:08:12 +00005158template<typename Derived>
5159Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005160TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 // FIXME: Implement this!
5162 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005163 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005164}
5165
Mike Stump11289f42009-09-09 15:08:12 +00005166template<typename Derived>
5167Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005168TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 // FIXME: Implement this!
5170 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005171 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005172}
5173
Mike Stump11289f42009-09-09 15:08:12 +00005174template<typename Derived>
5175Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 bool ArgumentChanged = false;
5178 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5179 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5180 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5181 if (SubExpr.isInvalid())
5182 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005183
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5185 SubExprs.push_back(SubExpr.takeAs<Expr>());
5186 }
Mike Stump11289f42009-09-09 15:08:12 +00005187
Douglas Gregora16548e2009-08-11 05:31:07 +00005188 if (!getDerived().AlwaysRebuild() &&
5189 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005190 return SemaRef.Owned(E->Retain());
5191
Douglas Gregora16548e2009-08-11 05:31:07 +00005192 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5193 move_arg(SubExprs),
5194 E->getRParenLoc());
5195}
5196
Mike Stump11289f42009-09-09 15:08:12 +00005197template<typename Derived>
5198Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005199TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 // FIXME: Implement this!
5201 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005202 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005203}
5204
Mike Stump11289f42009-09-09 15:08:12 +00005205template<typename Derived>
5206Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005207TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005208 // FIXME: Implement this!
5209 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005210 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005211}
Mike Stump11289f42009-09-09 15:08:12 +00005212
Douglas Gregora16548e2009-08-11 05:31:07 +00005213//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005214// Type reconstruction
5215//===----------------------------------------------------------------------===//
5216
Mike Stump11289f42009-09-09 15:08:12 +00005217template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005218QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5219 SourceLocation Star) {
5220 return SemaRef.BuildPointerType(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>
John McCall70dd5f62009-10-30 00:06:24 +00005225QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5226 SourceLocation Star) {
5227 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005228 getDerived().getBaseEntity());
5229}
5230
Mike Stump11289f42009-09-09 15:08:12 +00005231template<typename Derived>
5232QualType
John McCall70dd5f62009-10-30 00:06:24 +00005233TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5234 bool WrittenAsLValue,
5235 SourceLocation Sigil) {
5236 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5237 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238}
5239
5240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005241QualType
John McCall70dd5f62009-10-30 00:06:24 +00005242TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5243 QualType ClassType,
5244 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005245 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005246 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247}
5248
5249template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005250QualType
John McCall70dd5f62009-10-30 00:06:24 +00005251TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5252 SourceLocation Sigil) {
5253 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005254 getDerived().getBaseEntity());
5255}
5256
5257template<typename Derived>
5258QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5260 ArrayType::ArraySizeModifier SizeMod,
5261 const llvm::APInt *Size,
5262 Expr *SizeExpr,
5263 unsigned IndexTypeQuals,
5264 SourceRange BracketsRange) {
5265 if (SizeExpr || !Size)
5266 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5267 IndexTypeQuals, BracketsRange,
5268 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005269
5270 QualType Types[] = {
5271 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5272 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5273 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005274 };
5275 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5276 QualType SizeType;
5277 for (unsigned I = 0; I != NumTypes; ++I)
5278 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5279 SizeType = Types[I];
5280 break;
5281 }
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregord6ff3322009-08-04 16:50:30 +00005283 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005284 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005286 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005287}
Mike Stump11289f42009-09-09 15:08:12 +00005288
Douglas Gregord6ff3322009-08-04 16:50:30 +00005289template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005290QualType
5291TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005292 ArrayType::ArraySizeModifier SizeMod,
5293 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005294 unsigned IndexTypeQuals,
5295 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005296 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005297 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005298}
5299
5300template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005301QualType
Mike Stump11289f42009-09-09 15:08:12 +00005302TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005304 unsigned IndexTypeQuals,
5305 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005306 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005307 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005308}
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005311QualType
5312TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005313 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005314 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005315 unsigned IndexTypeQuals,
5316 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005317 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005318 SizeExpr.takeAs<Expr>(),
5319 IndexTypeQuals, BracketsRange);
5320}
5321
5322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005323QualType
5324TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005325 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005326 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005327 unsigned IndexTypeQuals,
5328 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005329 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005330 SizeExpr.takeAs<Expr>(),
5331 IndexTypeQuals, BracketsRange);
5332}
5333
5334template<typename Derived>
5335QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5336 unsigned NumElements) {
5337 // FIXME: semantic checking!
5338 return SemaRef.Context.getVectorType(ElementType, NumElements);
5339}
Mike Stump11289f42009-09-09 15:08:12 +00005340
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341template<typename Derived>
5342QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5343 unsigned NumElements,
5344 SourceLocation AttributeLoc) {
5345 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5346 NumElements, true);
5347 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005348 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349 AttributeLoc);
5350 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5351 AttributeLoc);
5352}
Mike Stump11289f42009-09-09 15:08:12 +00005353
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005355QualType
5356TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005357 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005358 SourceLocation AttributeLoc) {
5359 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5360}
Mike Stump11289f42009-09-09 15:08:12 +00005361
Douglas Gregord6ff3322009-08-04 16:50:30 +00005362template<typename Derived>
5363QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005364 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005365 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005366 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005368 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005369 Quals,
5370 getDerived().getBaseLocation(),
5371 getDerived().getBaseEntity());
5372}
Mike Stump11289f42009-09-09 15:08:12 +00005373
Douglas Gregord6ff3322009-08-04 16:50:30 +00005374template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005375QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5376 return SemaRef.Context.getFunctionNoProtoType(T);
5377}
5378
5379template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005380QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5381 assert(D && "no decl found");
5382 if (D->isInvalidDecl()) return QualType();
5383
5384 TypeDecl *Ty;
5385 if (isa<UsingDecl>(D)) {
5386 UsingDecl *Using = cast<UsingDecl>(D);
5387 assert(Using->isTypeName() &&
5388 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5389
5390 // A valid resolved using typename decl points to exactly one type decl.
5391 assert(++Using->shadow_begin() == Using->shadow_end());
5392 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5393
5394 } else {
5395 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5396 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5397 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5398 }
5399
5400 return SemaRef.Context.getTypeDeclType(Ty);
5401}
5402
5403template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005404QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005405 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5406}
5407
5408template<typename Derived>
5409QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5410 return SemaRef.Context.getTypeOfType(Underlying);
5411}
5412
5413template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005414QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005415 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5416}
5417
5418template<typename Derived>
5419QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005420 TemplateName Template,
5421 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005422 const TemplateArgumentListInfo &TemplateArgs) {
5423 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005424}
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregor1135c352009-08-06 05:28:30 +00005426template<typename Derived>
5427NestedNameSpecifier *
5428TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5429 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005430 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005431 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005432 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005433 CXXScopeSpec SS;
5434 // FIXME: The source location information is all wrong.
5435 SS.setRange(Range);
5436 SS.setScopeRep(Prefix);
5437 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005438 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005439 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005440 ObjectType,
5441 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005442 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005443}
5444
5445template<typename Derived>
5446NestedNameSpecifier *
5447TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5448 SourceRange Range,
5449 NamespaceDecl *NS) {
5450 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5451}
5452
5453template<typename Derived>
5454NestedNameSpecifier *
5455TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5456 SourceRange Range,
5457 bool TemplateKW,
5458 QualType T) {
5459 if (T->isDependentType() || T->isRecordType() ||
5460 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005461 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005462 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5463 T.getTypePtr());
5464 }
Mike Stump11289f42009-09-09 15:08:12 +00005465
Douglas Gregor1135c352009-08-06 05:28:30 +00005466 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5467 return 0;
5468}
Mike Stump11289f42009-09-09 15:08:12 +00005469
Douglas Gregor71dc5092009-08-06 06:41:21 +00005470template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005471TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005472TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5473 bool TemplateKW,
5474 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005475 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005476 Template);
5477}
5478
5479template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005480TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005481TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005482 const IdentifierInfo &II,
5483 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005484 CXXScopeSpec SS;
5485 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005486 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005487 UnqualifiedId Name;
5488 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005489 return getSema().ActOnDependentTemplateName(
5490 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005491 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005492 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005493 ObjectType.getAsOpaquePtr(),
5494 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005495 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005496}
Mike Stump11289f42009-09-09 15:08:12 +00005497
Douglas Gregora16548e2009-08-11 05:31:07 +00005498template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005499TemplateName
5500TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5501 OverloadedOperatorKind Operator,
5502 QualType ObjectType) {
5503 CXXScopeSpec SS;
5504 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5505 SS.setScopeRep(Qualifier);
5506 UnqualifiedId Name;
5507 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5508 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5509 Operator, SymbolLocations);
5510 return getSema().ActOnDependentTemplateName(
5511 /*FIXME:*/getDerived().getBaseLocation(),
5512 SS,
5513 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005514 ObjectType.getAsOpaquePtr(),
5515 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005516 .template getAsVal<TemplateName>();
5517}
5518
5519template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005520Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005521TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5522 SourceLocation OpLoc,
5523 ExprArg Callee,
5524 ExprArg First,
5525 ExprArg Second) {
5526 Expr *FirstExpr = (Expr *)First.get();
5527 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005528 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005529 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005532 if (Op == OO_Subscript) {
5533 if (!FirstExpr->getType()->isOverloadableType() &&
5534 !SecondExpr->getType()->isOverloadableType())
5535 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005536 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005537 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005538 } else if (Op == OO_Arrow) {
5539 // -> is never a builtin operation.
5540 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005541 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005542 if (!FirstExpr->getType()->isOverloadableType()) {
5543 // The argument is not of overloadable type, so try to create a
5544 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005545 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5549 }
5550 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005551 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005552 !SecondExpr->getType()->isOverloadableType()) {
5553 // Neither of the arguments is an overloadable type, so try to
5554 // create a built-in binary operation.
5555 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005556 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005557 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5558 if (Result.isInvalid())
5559 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 First.release();
5562 Second.release();
5563 return move(Result);
5564 }
5565 }
Mike Stump11289f42009-09-09 15:08:12 +00005566
5567 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 // used during overload resolution.
5569 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005570
John McCalld14a8642009-11-21 08:51:07 +00005571 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5572 assert(ULE->requiresADL());
5573
5574 // FIXME: Do we have to check
5575 // IsAcceptableNonMemberOperatorCandidate for each of these?
5576 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5577 E = ULE->decls_end(); I != E; ++I)
5578 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5579 } else {
5580 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5581 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 // Add any functions found via argument-dependent lookup.
5585 Expr *Args[2] = { FirstExpr, SecondExpr };
5586 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005587 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005589 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5590 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 // Create the overloaded operator invocation for unary operators.
5593 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005594 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5596 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5597 }
Mike Stump11289f42009-09-09 15:08:12 +00005598
Sebastian Redladba46e2009-10-29 20:17:01 +00005599 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005600 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5601 OpLoc,
5602 move(First),
5603 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005604
Douglas Gregora16548e2009-08-11 05:31:07 +00005605 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005606 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005607 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005608 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5610 if (Result.isInvalid())
5611 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005612
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 First.release();
5614 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005615 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005616}
Mike Stump11289f42009-09-09 15:08:12 +00005617
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618} // end namespace clang
5619
5620#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H