blob: 1938e3dfb5973610c25e23adbe81edf31170666c [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
Anders Carlssonaaeef072010-01-24 05:50:09 +0000779 /// \brief Build a new inline asm statement.
780 ///
781 /// By default, performs semantic analysis to build the new statement.
782 /// Subclasses may override this routine to provide different behavior.
783 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
784 bool IsSimple,
785 bool IsVolatile,
786 unsigned NumOutputs,
787 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000788 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000789 MultiExprArg Constraints,
790 MultiExprArg Exprs,
791 ExprArg AsmString,
792 MultiExprArg Clobbers,
793 SourceLocation RParenLoc,
794 bool MSAsm) {
795 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
796 NumInputs, Names, move(Constraints),
797 move(Exprs), move(AsmString), move(Clobbers),
798 RParenLoc, MSAsm);
799 }
800
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 /// \brief Build a new C++ exception declaration.
802 ///
803 /// By default, performs semantic analysis to build the new decaration.
804 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000805 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000806 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000807 IdentifierInfo *Name,
808 SourceLocation Loc,
809 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000810 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000811 TypeRange);
812 }
813
814 /// \brief Build a new C++ catch statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
818 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
819 VarDecl *ExceptionDecl,
820 StmtArg Handler) {
821 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000822 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000823 Handler.takeAs<Stmt>()));
824 }
Mike Stump11289f42009-09-09 15:08:12 +0000825
Douglas Gregorebe10102009-08-20 07:17:43 +0000826 /// \brief Build a new C++ try statement.
827 ///
828 /// By default, performs semantic analysis to build the new statement.
829 /// Subclasses may override this routine to provide different behavior.
830 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
831 StmtArg TryBlock,
832 MultiStmtArg Handlers) {
833 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
834 }
Mike Stump11289f42009-09-09 15:08:12 +0000835
Douglas Gregora16548e2009-08-11 05:31:07 +0000836 /// \brief Build a new expression that references a declaration.
837 ///
838 /// By default, performs semantic analysis to build the new expression.
839 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000840 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
841 LookupResult &R,
842 bool RequiresADL) {
843 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
844 }
845
846
847 /// \brief Build a new expression that references a declaration.
848 ///
849 /// By default, performs semantic analysis to build the new expression.
850 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000851 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
852 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000853 ValueDecl *VD, SourceLocation Loc,
854 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000855 CXXScopeSpec SS;
856 SS.setScopeRep(Qualifier);
857 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000858
859 // FIXME: loses template args.
860
861 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000862 }
Mike Stump11289f42009-09-09 15:08:12 +0000863
Douglas Gregora16548e2009-08-11 05:31:07 +0000864 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000865 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000866 /// By default, performs semantic analysis to build the new expression.
867 /// Subclasses may override this routine to provide different behavior.
868 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
869 SourceLocation RParen) {
870 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
871 }
872
Douglas Gregorad8a3362009-09-04 17:36:40 +0000873 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000874 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000875 /// By default, performs semantic analysis to build the new expression.
876 /// Subclasses may override this routine to provide different behavior.
877 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
878 SourceLocation OperatorLoc,
879 bool isArrow,
880 SourceLocation DestroyedTypeLoc,
881 QualType DestroyedType,
882 NestedNameSpecifier *Qualifier,
883 SourceRange QualifierRange) {
884 CXXScopeSpec SS;
885 if (Qualifier) {
886 SS.setRange(QualifierRange);
887 SS.setScopeRep(Qualifier);
888 }
889
John McCall2d74de92009-12-01 22:10:20 +0000890 QualType BaseType = ((Expr*) Base.get())->getType();
891
Mike Stump11289f42009-09-09 15:08:12 +0000892 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000893 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
894 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000895
John McCall2d74de92009-12-01 22:10:20 +0000896 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
897 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000898 SS, /*FIXME: FirstQualifier*/ 0,
899 Name, DestroyedTypeLoc,
900 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000901 }
902
Douglas Gregora16548e2009-08-11 05:31:07 +0000903 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000905 /// By default, performs semantic analysis to build the new expression.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
908 UnaryOperator::Opcode Opc,
909 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000910 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 }
Mike Stump11289f42009-09-09 15:08:12 +0000912
Douglas Gregora16548e2009-08-11 05:31:07 +0000913 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000914 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000915 /// By default, performs semantic analysis to build the new expression.
916 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000917 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000918 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000919 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000920 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000921 }
922
Mike Stump11289f42009-09-09 15:08:12 +0000923 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000925 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 /// By default, performs semantic analysis to build the new expression.
927 /// Subclasses may override this routine to provide different behavior.
928 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
929 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000930 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
932 OpLoc, isSizeOf, R);
933 if (Result.isInvalid())
934 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000935
Douglas Gregora16548e2009-08-11 05:31:07 +0000936 SubExpr.release();
937 return move(Result);
938 }
Mike Stump11289f42009-09-09 15:08:12 +0000939
Douglas Gregora16548e2009-08-11 05:31:07 +0000940 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000941 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000942 /// By default, performs semantic analysis to build the new expression.
943 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000944 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 SourceLocation LBracketLoc,
946 ExprArg RHS,
947 SourceLocation RBracketLoc) {
948 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000949 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000950 RBracketLoc);
951 }
952
953 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000955 /// By default, performs semantic analysis to build the new expression.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
958 MultiExprArg Args,
959 SourceLocation *CommaLocs,
960 SourceLocation RParenLoc) {
961 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
962 move(Args), CommaLocs, RParenLoc);
963 }
964
965 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000966 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000967 /// By default, performs semantic analysis to build the new expression.
968 /// Subclasses may override this routine to provide different behavior.
969 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000970 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000971 NestedNameSpecifier *Qualifier,
972 SourceRange QualifierRange,
973 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000974 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000975 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000976 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000977 if (!Member->getDeclName()) {
978 // We have a reference to an unnamed field.
979 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000980
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000981 Expr *BaseExpr = Base.takeAs<Expr>();
982 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
983 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000984
Mike Stump11289f42009-09-09 15:08:12 +0000985 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000986 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000987 Member, MemberLoc,
988 cast<FieldDecl>(Member)->getType());
989 return getSema().Owned(ME);
990 }
Mike Stump11289f42009-09-09 15:08:12 +0000991
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000992 CXXScopeSpec SS;
993 if (Qualifier) {
994 SS.setRange(QualifierRange);
995 SS.setScopeRep(Qualifier);
996 }
997
John McCall2d74de92009-12-01 22:10:20 +0000998 QualType BaseType = ((Expr*) Base.get())->getType();
999
John McCall38836f02010-01-15 08:34:02 +00001000 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1001 Sema::LookupMemberName);
1002 R.addDecl(Member);
1003 R.resolveKind();
1004
John McCall2d74de92009-12-01 22:10:20 +00001005 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1006 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001007 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001008 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001012 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 /// By default, performs semantic analysis to build the new expression.
1014 /// Subclasses may override this routine to provide different behavior.
1015 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1016 BinaryOperator::Opcode Opc,
1017 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001018 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1019 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001020 }
1021
1022 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001023 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 /// By default, performs semantic analysis to build the new expression.
1025 /// Subclasses may override this routine to provide different behavior.
1026 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1027 SourceLocation QuestionLoc,
1028 ExprArg LHS,
1029 SourceLocation ColonLoc,
1030 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001031 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001032 move(LHS), move(RHS));
1033 }
1034
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001036 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001039 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1040 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 SourceLocation RParenLoc,
1042 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001043 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1044 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001048 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
1051 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001052 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 SourceLocation RParenLoc,
1054 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001055 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1056 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001057 }
Mike Stump11289f42009-09-09 15:08:12 +00001058
Douglas Gregora16548e2009-08-11 05:31:07 +00001059 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001060 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001061 /// By default, performs semantic analysis to build the new expression.
1062 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001063 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 SourceLocation OpLoc,
1065 SourceLocation AccessorLoc,
1066 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001067
John McCall10eae182009-11-30 22:42:35 +00001068 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001069 QualType BaseType = ((Expr*) Base.get())->getType();
1070 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001071 OpLoc, /*IsArrow*/ false,
1072 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001073 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001074 AccessorLoc,
1075 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 }
Mike Stump11289f42009-09-09 15:08:12 +00001077
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001079 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1083 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001084 SourceLocation RBraceLoc,
1085 QualType ResultTy) {
1086 OwningExprResult Result
1087 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1088 if (Result.isInvalid() || ResultTy->isDependentType())
1089 return move(Result);
1090
1091 // Patch in the result type we were given, which may have been computed
1092 // when the initial InitListExpr was built.
1093 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1094 ILE->setType(ResultTy);
1095 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
1102 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1103 MultiExprArg ArrayExprs,
1104 SourceLocation EqualOrColonLoc,
1105 bool GNUSyntax,
1106 ExprArg Init) {
1107 OwningExprResult Result
1108 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1109 move(Init));
1110 if (Result.isInvalid())
1111 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 ArrayExprs.release();
1114 return move(Result);
1115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001118 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 /// By default, builds the implicit value initialization without performing
1120 /// any semantic analysis. Subclasses may override this routine to provide
1121 /// different behavior.
1122 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1123 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1131 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001132 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 RParenLoc);
1134 }
1135
1136 /// \brief Build a new expression list in parentheses.
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 RebuildParenListExpr(SourceLocation LParenLoc,
1141 MultiExprArg SubExprs,
1142 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001143 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1144 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001145 }
Mike Stump11289f42009-09-09 15:08:12 +00001146
Douglas Gregora16548e2009-08-11 05:31:07 +00001147 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001148 ///
1149 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001150 /// rather than attempting to map the label statement itself.
1151 /// Subclasses may override this routine to provide different behavior.
1152 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1153 SourceLocation LabelLoc,
1154 LabelStmt *Label) {
1155 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1156 }
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001159 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1163 StmtArg SubStmt,
1164 SourceLocation RParenLoc) {
1165 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1166 }
Mike Stump11289f42009-09-09 15:08:12 +00001167
Douglas Gregora16548e2009-08-11 05:31:07 +00001168 /// \brief Build a new __builtin_types_compatible_p expression.
1169 ///
1170 /// By default, performs semantic analysis to build the new expression.
1171 /// Subclasses may override this routine to provide different behavior.
1172 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1173 QualType T1, QualType T2,
1174 SourceLocation RParenLoc) {
1175 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1176 T1.getAsOpaquePtr(),
1177 T2.getAsOpaquePtr(),
1178 RParenLoc);
1179 }
Mike Stump11289f42009-09-09 15:08:12 +00001180
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 /// \brief Build a new __builtin_choose_expr expression.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1186 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1187 SourceLocation RParenLoc) {
1188 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1189 move(Cond), move(LHS), move(RHS),
1190 RParenLoc);
1191 }
Mike Stump11289f42009-09-09 15:08:12 +00001192
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 /// \brief Build a new overloaded operator call expression.
1194 ///
1195 /// By default, performs semantic analysis to build the new expression.
1196 /// The semantic analysis provides the behavior of template instantiation,
1197 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001198 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// argument-dependent lookup, etc. Subclasses may override this routine to
1200 /// provide different behavior.
1201 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1202 SourceLocation OpLoc,
1203 ExprArg Callee,
1204 ExprArg First,
1205 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001206
1207 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 /// reinterpret_cast.
1209 ///
1210 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001211 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1214 Stmt::StmtClass Class,
1215 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001216 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 SourceLocation RAngleLoc,
1218 SourceLocation LParenLoc,
1219 ExprArg SubExpr,
1220 SourceLocation RParenLoc) {
1221 switch (Class) {
1222 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001223 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001224 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 move(SubExpr), RParenLoc);
1226
1227 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001228 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001229 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001233 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001234 RAngleLoc, LParenLoc,
1235 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001239 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001240 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 default:
1244 assert(false && "Invalid C++ named cast");
1245 break;
1246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 return getSema().ExprError();
1249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 /// \brief Build a new C++ static_cast expression.
1252 ///
1253 /// By default, performs semantic analysis to build the new expression.
1254 /// Subclasses may override this routine to provide different behavior.
1255 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1256 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001257 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 SourceLocation RAngleLoc,
1259 SourceLocation LParenLoc,
1260 ExprArg SubExpr,
1261 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001262 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1263 TInfo, move(SubExpr),
1264 SourceRange(LAngleLoc, RAngleLoc),
1265 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 }
1267
1268 /// \brief Build a new C++ dynamic_cast expression.
1269 ///
1270 /// By default, performs semantic analysis to build the new expression.
1271 /// Subclasses may override this routine to provide different behavior.
1272 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1273 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001274 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 SourceLocation RAngleLoc,
1276 SourceLocation LParenLoc,
1277 ExprArg SubExpr,
1278 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001279 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1280 TInfo, move(SubExpr),
1281 SourceRange(LAngleLoc, RAngleLoc),
1282 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 }
1284
1285 /// \brief Build a new C++ reinterpret_cast expression.
1286 ///
1287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
1289 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1290 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001291 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 SourceLocation RAngleLoc,
1293 SourceLocation LParenLoc,
1294 ExprArg SubExpr,
1295 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001296 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1297 TInfo, move(SubExpr),
1298 SourceRange(LAngleLoc, RAngleLoc),
1299 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 }
1301
1302 /// \brief Build a new C++ const_cast expression.
1303 ///
1304 /// By default, performs semantic analysis to build the new expression.
1305 /// Subclasses may override this routine to provide different behavior.
1306 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1307 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001308 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 SourceLocation RAngleLoc,
1310 SourceLocation LParenLoc,
1311 ExprArg SubExpr,
1312 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001313 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1314 TInfo, move(SubExpr),
1315 SourceRange(LAngleLoc, RAngleLoc),
1316 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 }
Mike Stump11289f42009-09-09 15:08:12 +00001318
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// \brief Build a new C++ functional-style cast 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 RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001324 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 SourceLocation LParenLoc,
1326 ExprArg SubExpr,
1327 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001328 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001330 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001332 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001333 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 RParenLoc);
1335 }
Mike Stump11289f42009-09-09 15:08:12 +00001336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// \brief Build a new C++ typeid(type) expression.
1338 ///
1339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
1341 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1342 SourceLocation LParenLoc,
1343 QualType T,
1344 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001345 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 T.getAsOpaquePtr(), RParenLoc);
1347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 /// \brief Build a new C++ typeid(expr) expression.
1350 ///
1351 /// By default, performs semantic analysis to build the new expression.
1352 /// Subclasses may override this routine to provide different behavior.
1353 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1354 SourceLocation LParenLoc,
1355 ExprArg Operand,
1356 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001357 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1359 RParenLoc);
1360 if (Result.isInvalid())
1361 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001362
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1364 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001365 }
1366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 /// \brief Build a new C++ "this" expression.
1368 ///
1369 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001370 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001372 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001373 QualType ThisType,
1374 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001376 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1377 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 }
1379
1380 /// \brief Build a new C++ throw expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
1384 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1385 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1386 }
1387
1388 /// \brief Build a new C++ default-argument expression.
1389 ///
1390 /// By default, builds a new default-argument expression, which does not
1391 /// require any semantic analysis. Subclasses may override this routine to
1392 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001393 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1394 ParmVarDecl *Param) {
1395 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1396 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 }
1398
1399 /// \brief Build a new C++ zero-initialization expression.
1400 ///
1401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001403 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 SourceLocation LParenLoc,
1405 QualType T,
1406 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001407 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1408 T.getAsOpaquePtr(), LParenLoc,
1409 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 0, RParenLoc);
1411 }
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// \brief Build a new C++ "new" expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001417 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 bool UseGlobal,
1419 SourceLocation PlacementLParen,
1420 MultiExprArg PlacementArgs,
1421 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001422 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 QualType AllocType,
1424 SourceLocation TypeLoc,
1425 SourceRange TypeRange,
1426 ExprArg ArraySize,
1427 SourceLocation ConstructorLParen,
1428 MultiExprArg ConstructorArgs,
1429 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001430 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 PlacementLParen,
1432 move(PlacementArgs),
1433 PlacementRParen,
1434 ParenTypeId,
1435 AllocType,
1436 TypeLoc,
1437 TypeRange,
1438 move(ArraySize),
1439 ConstructorLParen,
1440 move(ConstructorArgs),
1441 ConstructorRParen);
1442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// \brief Build a new C++ "delete" expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
1448 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1449 bool IsGlobalDelete,
1450 bool IsArrayForm,
1451 ExprArg Operand) {
1452 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1453 move(Operand));
1454 }
Mike Stump11289f42009-09-09 15:08:12 +00001455
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// \brief Build a new unary type trait expression.
1457 ///
1458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
1460 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1461 SourceLocation StartLoc,
1462 SourceLocation LParenLoc,
1463 QualType T,
1464 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001465 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 T.getAsOpaquePtr(), RParenLoc);
1467 }
1468
Mike Stump11289f42009-09-09 15:08:12 +00001469 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 /// expression.
1471 ///
1472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001474 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 SourceRange QualifierRange,
1476 DeclarationName Name,
1477 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001478 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 CXXScopeSpec SS;
1480 SS.setRange(QualifierRange);
1481 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001482
1483 if (TemplateArgs)
1484 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1485 *TemplateArgs);
1486
1487 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 }
1489
1490 /// \brief Build a new template-id expression.
1491 ///
1492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001494 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1495 LookupResult &R,
1496 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001497 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001498 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
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 RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001506 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001507 CXXConstructorDecl *Constructor,
1508 bool IsElidable,
1509 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001510 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1511 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1512 ConvertedArgs))
1513 return getSema().ExprError();
1514
1515 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1516 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 }
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 RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1524 QualType T,
1525 SourceLocation LParenLoc,
1526 MultiExprArg Args,
1527 SourceLocation *Commas,
1528 SourceLocation RParenLoc) {
1529 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1530 T.getAsOpaquePtr(),
1531 LParenLoc,
1532 move(Args),
1533 Commas,
1534 RParenLoc);
1535 }
1536
1537 /// \brief Build a new object-construction expression.
1538 ///
1539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
1541 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1542 QualType T,
1543 SourceLocation LParenLoc,
1544 MultiExprArg Args,
1545 SourceLocation *Commas,
1546 SourceLocation RParenLoc) {
1547 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1548 /*FIXME*/LParenLoc),
1549 T.getAsOpaquePtr(),
1550 LParenLoc,
1551 move(Args),
1552 Commas,
1553 RParenLoc);
1554 }
Mike Stump11289f42009-09-09 15:08:12 +00001555
Douglas Gregora16548e2009-08-11 05:31:07 +00001556 /// \brief Build a new member reference expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001560 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001561 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 bool IsArrow,
1563 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001564 NestedNameSpecifier *Qualifier,
1565 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001566 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001568 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001569 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001570 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001571 SS.setRange(QualifierRange);
1572 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001573
John McCall2d74de92009-12-01 22:10:20 +00001574 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1575 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001576 SS, FirstQualifierInScope,
1577 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001578 }
1579
John McCall10eae182009-11-30 22:42:35 +00001580 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001584 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001585 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001586 SourceLocation OperatorLoc,
1587 bool IsArrow,
1588 NestedNameSpecifier *Qualifier,
1589 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001590 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001591 LookupResult &R,
1592 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001593 CXXScopeSpec SS;
1594 SS.setRange(QualifierRange);
1595 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001596
John McCall2d74de92009-12-01 22:10:20 +00001597 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1598 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001599 SS, FirstQualifierInScope,
1600 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001601 }
Mike Stump11289f42009-09-09 15:08:12 +00001602
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// \brief Build a new Objective-C @encode expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
1607 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1608 QualType T,
1609 SourceLocation RParenLoc) {
1610 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1611 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001612 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001613
1614 /// \brief Build a new Objective-C protocol expression.
1615 ///
1616 /// By default, performs semantic analysis to build the new expression.
1617 /// Subclasses may override this routine to provide different behavior.
1618 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1619 SourceLocation AtLoc,
1620 SourceLocation ProtoLoc,
1621 SourceLocation LParenLoc,
1622 SourceLocation RParenLoc) {
1623 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1624 Protocol->getIdentifier(),
1625 AtLoc,
1626 ProtoLoc,
1627 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001628 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 }
Mike Stump11289f42009-09-09 15:08:12 +00001630
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 /// \brief Build a new shuffle vector expression.
1632 ///
1633 /// By default, performs semantic analysis to build the new expression.
1634 /// Subclasses may override this routine to provide different behavior.
1635 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1636 MultiExprArg SubExprs,
1637 SourceLocation RParenLoc) {
1638 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001639 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1641 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1642 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1643 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001644
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 // Build a reference to the __builtin_shufflevector builtin
1646 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001647 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001649 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001651
1652 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001653 unsigned NumSubExprs = SubExprs.size();
1654 Expr **Subs = (Expr **)SubExprs.release();
1655 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1656 Subs, NumSubExprs,
1657 Builtin->getResultType(),
1658 RParenLoc);
1659 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001660
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 // Type-check the __builtin_shufflevector expression.
1662 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1663 if (Result.isInvalid())
1664 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregora16548e2009-08-11 05:31:07 +00001666 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001667 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001669};
Douglas Gregora16548e2009-08-11 05:31:07 +00001670
Douglas Gregorebe10102009-08-20 07:17:43 +00001671template<typename Derived>
1672Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1673 if (!S)
1674 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001675
Douglas Gregorebe10102009-08-20 07:17:43 +00001676 switch (S->getStmtClass()) {
1677 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001678
Douglas Gregorebe10102009-08-20 07:17:43 +00001679 // Transform individual statement nodes
1680#define STMT(Node, Parent) \
1681 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1682#define EXPR(Node, Parent)
1683#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001684
Douglas Gregorebe10102009-08-20 07:17:43 +00001685 // Transform expressions by calling TransformExpr.
1686#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001687#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001688#define EXPR(Node, Parent) case Stmt::Node##Class:
1689#include "clang/AST/StmtNodes.def"
1690 {
1691 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1692 if (E.isInvalid())
1693 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001694
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001695 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001696 }
Mike Stump11289f42009-09-09 15:08:12 +00001697 }
1698
Douglas Gregorebe10102009-08-20 07:17:43 +00001699 return SemaRef.Owned(S->Retain());
1700}
Mike Stump11289f42009-09-09 15:08:12 +00001701
1702
Douglas Gregore922c772009-08-04 22:27:00 +00001703template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001704Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 if (!E)
1706 return SemaRef.Owned(E);
1707
1708 switch (E->getStmtClass()) {
1709 case Stmt::NoStmtClass: break;
1710#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001711#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001712#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001713 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001714#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001715 }
1716
Douglas Gregora16548e2009-08-11 05:31:07 +00001717 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001718}
1719
1720template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001721NestedNameSpecifier *
1722TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001723 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001724 QualType ObjectType,
1725 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001726 if (!NNS)
1727 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001728
Douglas Gregorebe10102009-08-20 07:17:43 +00001729 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 NestedNameSpecifier *Prefix = NNS->getPrefix();
1731 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001732 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001733 ObjectType,
1734 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001735 if (!Prefix)
1736 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001737
1738 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001739 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001740 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001741 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 }
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 switch (NNS->getKind()) {
1745 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001746 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001747 "Identifier nested-name-specifier with no prefix or object type");
1748 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1749 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001750 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001751
1752 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001753 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001754 ObjectType,
1755 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001758 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 = cast_or_null<NamespaceDecl>(
1760 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001761 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001762 Prefix == NNS->getPrefix() &&
1763 NS == NNS->getAsNamespace())
1764 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1767 }
Mike Stump11289f42009-09-09 15:08:12 +00001768
Douglas Gregor1135c352009-08-06 05:28:30 +00001769 case NestedNameSpecifier::Global:
1770 // There is no meaningful transformation that one could perform on the
1771 // global scope.
1772 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregor1135c352009-08-06 05:28:30 +00001774 case NestedNameSpecifier::TypeSpecWithTemplate:
1775 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001776 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001777 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001778 if (T.isNull())
1779 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregor1135c352009-08-06 05:28:30 +00001781 if (!getDerived().AlwaysRebuild() &&
1782 Prefix == NNS->getPrefix() &&
1783 T == QualType(NNS->getAsType(), 0))
1784 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001785
1786 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1787 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001788 T);
1789 }
1790 }
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregor1135c352009-08-06 05:28:30 +00001792 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001793 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001794}
1795
1796template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001797DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001798TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001799 SourceLocation Loc,
1800 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001801 if (!Name)
1802 return Name;
1803
1804 switch (Name.getNameKind()) {
1805 case DeclarationName::Identifier:
1806 case DeclarationName::ObjCZeroArgSelector:
1807 case DeclarationName::ObjCOneArgSelector:
1808 case DeclarationName::ObjCMultiArgSelector:
1809 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001810 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001811 case DeclarationName::CXXUsingDirective:
1812 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001813
Douglas Gregorf816bd72009-09-03 22:13:48 +00001814 case DeclarationName::CXXConstructorName:
1815 case DeclarationName::CXXDestructorName:
1816 case DeclarationName::CXXConversionFunctionName: {
1817 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001818 QualType T;
1819 if (!ObjectType.isNull() &&
1820 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1821 TemplateSpecializationType *SpecType
1822 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1823 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1824 } else
1825 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001826 if (T.isNull())
1827 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregorf816bd72009-09-03 22:13:48 +00001829 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001830 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001831 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001832 }
Mike Stump11289f42009-09-09 15:08:12 +00001833 }
1834
Douglas Gregorf816bd72009-09-03 22:13:48 +00001835 return DeclarationName();
1836}
1837
1838template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001839TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001840TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1841 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001843 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001844 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1845 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1846 if (!NNS)
1847 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001850 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1852 if (!TransTemplate)
1853 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregor71dc5092009-08-06 06:41:21 +00001855 if (!getDerived().AlwaysRebuild() &&
1856 NNS == QTN->getQualifier() &&
1857 TransTemplate == Template)
1858 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1861 TransTemplate);
1862 }
Mike Stump11289f42009-09-09 15:08:12 +00001863
John McCalle66edc12009-11-24 19:00:30 +00001864 // These should be getting filtered out before they make it into the AST.
1865 assert(false && "overloaded template name survived to here");
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 (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001869 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1871 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001872 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001873 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001874
Douglas Gregor71dc5092009-08-06 06:41:21 +00001875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001876 NNS == DTN->getQualifier() &&
1877 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001879
Douglas Gregor71395fa2009-11-04 00:56:37 +00001880 if (DTN->isIdentifier())
1881 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1882 ObjectType);
1883
1884 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1885 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregor71dc5092009-08-06 06:41:21 +00001888 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001889 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001890 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1891 if (!TransTemplate)
1892 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001893
Douglas Gregor71dc5092009-08-06 06:41:21 +00001894 if (!getDerived().AlwaysRebuild() &&
1895 TransTemplate == Template)
1896 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001897
Douglas Gregor71dc5092009-08-06 06:41:21 +00001898 return TemplateName(TransTemplate);
1899 }
Mike Stump11289f42009-09-09 15:08:12 +00001900
John McCalle66edc12009-11-24 19:00:30 +00001901 // These should be getting filtered out before they reach the AST.
1902 assert(false && "overloaded function decl survived to here");
1903 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001904}
1905
1906template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001907void TreeTransform<Derived>::InventTemplateArgumentLoc(
1908 const TemplateArgument &Arg,
1909 TemplateArgumentLoc &Output) {
1910 SourceLocation Loc = getDerived().getBaseLocation();
1911 switch (Arg.getKind()) {
1912 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001913 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001914 break;
1915
1916 case TemplateArgument::Type:
1917 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001918 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001919
1920 break;
1921
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001922 case TemplateArgument::Template:
1923 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1924 break;
1925
John McCall0ad16662009-10-29 08:12:44 +00001926 case TemplateArgument::Expression:
1927 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1928 break;
1929
1930 case TemplateArgument::Declaration:
1931 case TemplateArgument::Integral:
1932 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001933 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001934 break;
1935 }
1936}
1937
1938template<typename Derived>
1939bool TreeTransform<Derived>::TransformTemplateArgument(
1940 const TemplateArgumentLoc &Input,
1941 TemplateArgumentLoc &Output) {
1942 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001943 switch (Arg.getKind()) {
1944 case TemplateArgument::Null:
1945 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001946 Output = Input;
1947 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001948
Douglas Gregore922c772009-08-04 22:27:00 +00001949 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001950 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001951 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001952 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001953
1954 DI = getDerived().TransformType(DI);
1955 if (!DI) return true;
1956
1957 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1958 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001959 }
Mike Stump11289f42009-09-09 15:08:12 +00001960
Douglas Gregore922c772009-08-04 22:27:00 +00001961 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001962 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001963 DeclarationName Name;
1964 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1965 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001966 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001967 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001968 if (!D) return true;
1969
John McCall0d07eb32009-10-29 18:45:58 +00001970 Expr *SourceExpr = Input.getSourceDeclExpression();
1971 if (SourceExpr) {
1972 EnterExpressionEvaluationContext Unevaluated(getSema(),
1973 Action::Unevaluated);
1974 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1975 if (E.isInvalid())
1976 SourceExpr = NULL;
1977 else {
1978 SourceExpr = E.takeAs<Expr>();
1979 SourceExpr->Retain();
1980 }
1981 }
1982
1983 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001984 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001985 }
Mike Stump11289f42009-09-09 15:08:12 +00001986
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001987 case TemplateArgument::Template: {
1988 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1989 TemplateName Template
1990 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1991 if (Template.isNull())
1992 return true;
1993
1994 Output = TemplateArgumentLoc(TemplateArgument(Template),
1995 Input.getTemplateQualifierRange(),
1996 Input.getTemplateNameLoc());
1997 return false;
1998 }
1999
Douglas Gregore922c772009-08-04 22:27:00 +00002000 case TemplateArgument::Expression: {
2001 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002002 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002003 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002004
John McCall0ad16662009-10-29 08:12:44 +00002005 Expr *InputExpr = Input.getSourceExpression();
2006 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2007
2008 Sema::OwningExprResult E
2009 = getDerived().TransformExpr(InputExpr);
2010 if (E.isInvalid()) return true;
2011
2012 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002013 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002014 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2015 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregore922c772009-08-04 22:27:00 +00002018 case TemplateArgument::Pack: {
2019 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2020 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002021 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002022 AEnd = Arg.pack_end();
2023 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002024
John McCall0ad16662009-10-29 08:12:44 +00002025 // FIXME: preserve source information here when we start
2026 // caring about parameter packs.
2027
John McCall0d07eb32009-10-29 18:45:58 +00002028 TemplateArgumentLoc InputArg;
2029 TemplateArgumentLoc OutputArg;
2030 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2031 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002032 return true;
2033
John McCall0d07eb32009-10-29 18:45:58 +00002034 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002035 }
2036 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002037 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002038 true);
John McCall0d07eb32009-10-29 18:45:58 +00002039 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002040 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002041 }
2042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregore922c772009-08-04 22:27:00 +00002044 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002045 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002046}
2047
Douglas Gregord6ff3322009-08-04 16:50:30 +00002048//===----------------------------------------------------------------------===//
2049// Type transformation
2050//===----------------------------------------------------------------------===//
2051
2052template<typename Derived>
2053QualType TreeTransform<Derived>::TransformType(QualType T) {
2054 if (getDerived().AlreadyTransformed(T))
2055 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002056
John McCall550e0c22009-10-21 00:40:46 +00002057 // Temporary workaround. All of these transformations should
2058 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002059 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002060 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002061
John McCallbcd03502009-12-07 02:54:59 +00002062 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002063
John McCall550e0c22009-10-21 00:40:46 +00002064 if (!NewDI)
2065 return QualType();
2066
2067 return NewDI->getType();
2068}
2069
2070template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002071TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002072 if (getDerived().AlreadyTransformed(DI->getType()))
2073 return DI;
2074
2075 TypeLocBuilder TLB;
2076
2077 TypeLoc TL = DI->getTypeLoc();
2078 TLB.reserve(TL.getFullDataSize());
2079
2080 QualType Result = getDerived().TransformType(TLB, TL);
2081 if (Result.isNull())
2082 return 0;
2083
John McCallbcd03502009-12-07 02:54:59 +00002084 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002085}
2086
2087template<typename Derived>
2088QualType
2089TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2090 switch (T.getTypeLocClass()) {
2091#define ABSTRACT_TYPELOC(CLASS, PARENT)
2092#define TYPELOC(CLASS, PARENT) \
2093 case TypeLoc::CLASS: \
2094 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2095#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002096 }
Mike Stump11289f42009-09-09 15:08:12 +00002097
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002098 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002099 return QualType();
2100}
2101
2102/// FIXME: By default, this routine adds type qualifiers only to types
2103/// that can have qualifiers, and silently suppresses those qualifiers
2104/// that are not permitted (e.g., qualifiers on reference or function
2105/// types). This is the right thing for template instantiation, but
2106/// probably not for other clients.
2107template<typename Derived>
2108QualType
2109TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2110 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002111 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002112
2113 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2114 if (Result.isNull())
2115 return QualType();
2116
2117 // Silently suppress qualifiers if the result type can't be qualified.
2118 // FIXME: this is the right thing for template instantiation, but
2119 // probably not for other clients.
2120 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002121 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002122
John McCall550e0c22009-10-21 00:40:46 +00002123 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2124
2125 TLB.push<QualifiedTypeLoc>(Result);
2126
2127 // No location information to preserve.
2128
2129 return Result;
2130}
2131
2132template <class TyLoc> static inline
2133QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2134 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2135 NewT.setNameLoc(T.getNameLoc());
2136 return T.getType();
2137}
2138
2139// Ugly metaprogramming macros because I couldn't be bothered to make
2140// the equivalent template version work.
2141#define TransformPointerLikeType(TypeClass) do { \
2142 QualType PointeeType \
2143 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2144 if (PointeeType.isNull()) \
2145 return QualType(); \
2146 \
2147 QualType Result = TL.getType(); \
2148 if (getDerived().AlwaysRebuild() || \
2149 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002150 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2151 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002152 if (Result.isNull()) \
2153 return QualType(); \
2154 } \
2155 \
2156 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2157 NewT.setSigilLoc(TL.getSigilLoc()); \
2158 \
2159 return Result; \
2160} while(0)
2161
John McCall550e0c22009-10-21 00:40:46 +00002162template<typename Derived>
2163QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2164 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002165 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2166 NewT.setBuiltinLoc(T.getBuiltinLoc());
2167 if (T.needsExtraLocalData())
2168 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2169 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170}
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregord6ff3322009-08-04 16:50:30 +00002172template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002173QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2174 ComplexTypeLoc T) {
2175 // FIXME: recurse?
2176 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177}
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregord6ff3322009-08-04 16:50:30 +00002179template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002180QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2181 PointerTypeLoc TL) {
2182 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002183}
Mike Stump11289f42009-09-09 15:08:12 +00002184
2185template<typename Derived>
2186QualType
John McCall550e0c22009-10-21 00:40:46 +00002187TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2188 BlockPointerTypeLoc TL) {
2189 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002190}
2191
John McCall70dd5f62009-10-30 00:06:24 +00002192/// Transforms a reference type. Note that somewhat paradoxically we
2193/// don't care whether the type itself is an l-value type or an r-value
2194/// type; we only care if the type was *written* as an l-value type
2195/// or an r-value type.
2196template<typename Derived>
2197QualType
2198TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2199 ReferenceTypeLoc TL) {
2200 const ReferenceType *T = TL.getTypePtr();
2201
2202 // Note that this works with the pointee-as-written.
2203 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2204 if (PointeeType.isNull())
2205 return QualType();
2206
2207 QualType Result = TL.getType();
2208 if (getDerived().AlwaysRebuild() ||
2209 PointeeType != T->getPointeeTypeAsWritten()) {
2210 Result = getDerived().RebuildReferenceType(PointeeType,
2211 T->isSpelledAsLValue(),
2212 TL.getSigilLoc());
2213 if (Result.isNull())
2214 return QualType();
2215 }
2216
2217 // r-value references can be rebuilt as l-value references.
2218 ReferenceTypeLoc NewTL;
2219 if (isa<LValueReferenceType>(Result))
2220 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2221 else
2222 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2223 NewTL.setSigilLoc(TL.getSigilLoc());
2224
2225 return Result;
2226}
2227
Mike Stump11289f42009-09-09 15:08:12 +00002228template<typename Derived>
2229QualType
John McCall550e0c22009-10-21 00:40:46 +00002230TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2231 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002232 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002233}
2234
Mike Stump11289f42009-09-09 15:08:12 +00002235template<typename Derived>
2236QualType
John McCall550e0c22009-10-21 00:40:46 +00002237TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2238 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002239 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002240}
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregord6ff3322009-08-04 16:50:30 +00002242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002243QualType
John McCall550e0c22009-10-21 00:40:46 +00002244TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2245 MemberPointerTypeLoc TL) {
2246 MemberPointerType *T = TL.getTypePtr();
2247
2248 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002249 if (PointeeType.isNull())
2250 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002251
John McCall550e0c22009-10-21 00:40:46 +00002252 // TODO: preserve source information for this.
2253 QualType ClassType
2254 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002255 if (ClassType.isNull())
2256 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002257
John McCall550e0c22009-10-21 00:40:46 +00002258 QualType Result = TL.getType();
2259 if (getDerived().AlwaysRebuild() ||
2260 PointeeType != T->getPointeeType() ||
2261 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002262 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2263 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002264 if (Result.isNull())
2265 return QualType();
2266 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002267
John McCall550e0c22009-10-21 00:40:46 +00002268 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2269 NewTL.setSigilLoc(TL.getSigilLoc());
2270
2271 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002272}
2273
Mike Stump11289f42009-09-09 15:08:12 +00002274template<typename Derived>
2275QualType
John McCall550e0c22009-10-21 00:40:46 +00002276TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2277 ConstantArrayTypeLoc TL) {
2278 ConstantArrayType *T = TL.getTypePtr();
2279 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002280 if (ElementType.isNull())
2281 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002282
John McCall550e0c22009-10-21 00:40:46 +00002283 QualType Result = TL.getType();
2284 if (getDerived().AlwaysRebuild() ||
2285 ElementType != T->getElementType()) {
2286 Result = getDerived().RebuildConstantArrayType(ElementType,
2287 T->getSizeModifier(),
2288 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002289 T->getIndexTypeCVRQualifiers(),
2290 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002291 if (Result.isNull())
2292 return QualType();
2293 }
2294
2295 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2296 NewTL.setLBracketLoc(TL.getLBracketLoc());
2297 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCall550e0c22009-10-21 00:40:46 +00002299 Expr *Size = TL.getSizeExpr();
2300 if (Size) {
2301 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2302 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2303 }
2304 NewTL.setSizeExpr(Size);
2305
2306 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002307}
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregord6ff3322009-08-04 16:50:30 +00002309template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002310QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002311 TypeLocBuilder &TLB,
2312 IncompleteArrayTypeLoc TL) {
2313 IncompleteArrayType *T = TL.getTypePtr();
2314 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002315 if (ElementType.isNull())
2316 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002317
John McCall550e0c22009-10-21 00:40:46 +00002318 QualType Result = TL.getType();
2319 if (getDerived().AlwaysRebuild() ||
2320 ElementType != T->getElementType()) {
2321 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002322 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002323 T->getIndexTypeCVRQualifiers(),
2324 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002325 if (Result.isNull())
2326 return QualType();
2327 }
2328
2329 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2330 NewTL.setLBracketLoc(TL.getLBracketLoc());
2331 NewTL.setRBracketLoc(TL.getRBracketLoc());
2332 NewTL.setSizeExpr(0);
2333
2334 return Result;
2335}
2336
2337template<typename Derived>
2338QualType
2339TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2340 VariableArrayTypeLoc TL) {
2341 VariableArrayType *T = TL.getTypePtr();
2342 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2343 if (ElementType.isNull())
2344 return QualType();
2345
2346 // Array bounds are not potentially evaluated contexts
2347 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2348
2349 Sema::OwningExprResult SizeResult
2350 = getDerived().TransformExpr(T->getSizeExpr());
2351 if (SizeResult.isInvalid())
2352 return QualType();
2353
2354 Expr *Size = static_cast<Expr*>(SizeResult.get());
2355
2356 QualType Result = TL.getType();
2357 if (getDerived().AlwaysRebuild() ||
2358 ElementType != T->getElementType() ||
2359 Size != T->getSizeExpr()) {
2360 Result = getDerived().RebuildVariableArrayType(ElementType,
2361 T->getSizeModifier(),
2362 move(SizeResult),
2363 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002364 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002365 if (Result.isNull())
2366 return QualType();
2367 }
2368 else SizeResult.take();
2369
2370 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2371 NewTL.setLBracketLoc(TL.getLBracketLoc());
2372 NewTL.setRBracketLoc(TL.getRBracketLoc());
2373 NewTL.setSizeExpr(Size);
2374
2375 return Result;
2376}
2377
2378template<typename Derived>
2379QualType
2380TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2381 DependentSizedArrayTypeLoc TL) {
2382 DependentSizedArrayType *T = TL.getTypePtr();
2383 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2384 if (ElementType.isNull())
2385 return QualType();
2386
2387 // Array bounds are not potentially evaluated contexts
2388 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2389
2390 Sema::OwningExprResult SizeResult
2391 = getDerived().TransformExpr(T->getSizeExpr());
2392 if (SizeResult.isInvalid())
2393 return QualType();
2394
2395 Expr *Size = static_cast<Expr*>(SizeResult.get());
2396
2397 QualType Result = TL.getType();
2398 if (getDerived().AlwaysRebuild() ||
2399 ElementType != T->getElementType() ||
2400 Size != T->getSizeExpr()) {
2401 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2402 T->getSizeModifier(),
2403 move(SizeResult),
2404 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002405 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002406 if (Result.isNull())
2407 return QualType();
2408 }
2409 else SizeResult.take();
2410
2411 // We might have any sort of array type now, but fortunately they
2412 // all have the same location layout.
2413 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2414 NewTL.setLBracketLoc(TL.getLBracketLoc());
2415 NewTL.setRBracketLoc(TL.getRBracketLoc());
2416 NewTL.setSizeExpr(Size);
2417
2418 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002419}
Mike Stump11289f42009-09-09 15:08:12 +00002420
2421template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002423 TypeLocBuilder &TLB,
2424 DependentSizedExtVectorTypeLoc TL) {
2425 DependentSizedExtVectorType *T = TL.getTypePtr();
2426
2427 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002428 QualType ElementType = getDerived().TransformType(T->getElementType());
2429 if (ElementType.isNull())
2430 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002431
Douglas Gregore922c772009-08-04 22:27:00 +00002432 // Vector sizes are not potentially evaluated contexts
2433 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2434
Douglas Gregord6ff3322009-08-04 16:50:30 +00002435 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2436 if (Size.isInvalid())
2437 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002438
John McCall550e0c22009-10-21 00:40:46 +00002439 QualType Result = TL.getType();
2440 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002441 ElementType != T->getElementType() ||
2442 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002443 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002444 move(Size),
2445 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002446 if (Result.isNull())
2447 return QualType();
2448 }
2449 else Size.take();
2450
2451 // Result might be dependent or not.
2452 if (isa<DependentSizedExtVectorType>(Result)) {
2453 DependentSizedExtVectorTypeLoc NewTL
2454 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2455 NewTL.setNameLoc(TL.getNameLoc());
2456 } else {
2457 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2458 NewTL.setNameLoc(TL.getNameLoc());
2459 }
2460
2461 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002462}
Mike Stump11289f42009-09-09 15:08:12 +00002463
2464template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002465QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2466 VectorTypeLoc TL) {
2467 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002468 QualType ElementType = getDerived().TransformType(T->getElementType());
2469 if (ElementType.isNull())
2470 return QualType();
2471
John McCall550e0c22009-10-21 00:40:46 +00002472 QualType Result = TL.getType();
2473 if (getDerived().AlwaysRebuild() ||
2474 ElementType != T->getElementType()) {
2475 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2476 if (Result.isNull())
2477 return QualType();
2478 }
2479
2480 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2481 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002482
John McCall550e0c22009-10-21 00:40:46 +00002483 return Result;
2484}
2485
2486template<typename Derived>
2487QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2488 ExtVectorTypeLoc TL) {
2489 VectorType *T = TL.getTypePtr();
2490 QualType ElementType = getDerived().TransformType(T->getElementType());
2491 if (ElementType.isNull())
2492 return QualType();
2493
2494 QualType Result = TL.getType();
2495 if (getDerived().AlwaysRebuild() ||
2496 ElementType != T->getElementType()) {
2497 Result = getDerived().RebuildExtVectorType(ElementType,
2498 T->getNumElements(),
2499 /*FIXME*/ SourceLocation());
2500 if (Result.isNull())
2501 return QualType();
2502 }
2503
2504 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2505 NewTL.setNameLoc(TL.getNameLoc());
2506
2507 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002508}
Mike Stump11289f42009-09-09 15:08:12 +00002509
2510template<typename Derived>
2511QualType
John McCall550e0c22009-10-21 00:40:46 +00002512TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2513 FunctionProtoTypeLoc TL) {
2514 FunctionProtoType *T = TL.getTypePtr();
2515 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002516 if (ResultType.isNull())
2517 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002518
John McCall550e0c22009-10-21 00:40:46 +00002519 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002520 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002521 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2522 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2523 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002524
John McCall550e0c22009-10-21 00:40:46 +00002525 QualType NewType;
2526 ParmVarDecl *NewParm;
2527
2528 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002529 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002530 assert(OldDI->getType() == T->getArgType(i));
2531
John McCallbcd03502009-12-07 02:54:59 +00002532 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002533 if (!NewDI)
2534 return QualType();
2535
2536 if (NewDI == OldDI)
2537 NewParm = OldParm;
2538 else
2539 NewParm = ParmVarDecl::Create(SemaRef.Context,
2540 OldParm->getDeclContext(),
2541 OldParm->getLocation(),
2542 OldParm->getIdentifier(),
2543 NewDI->getType(),
2544 NewDI,
2545 OldParm->getStorageClass(),
2546 /* DefArg */ NULL);
2547 NewType = NewParm->getType();
2548
2549 // Deal with the possibility that we don't have a parameter
2550 // declaration for this parameter.
2551 } else {
2552 NewParm = 0;
2553
2554 QualType OldType = T->getArgType(i);
2555 NewType = getDerived().TransformType(OldType);
2556 if (NewType.isNull())
2557 return QualType();
2558 }
2559
2560 ParamTypes.push_back(NewType);
2561 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002562 }
Mike Stump11289f42009-09-09 15:08:12 +00002563
John McCall550e0c22009-10-21 00:40:46 +00002564 QualType Result = TL.getType();
2565 if (getDerived().AlwaysRebuild() ||
2566 ResultType != T->getResultType() ||
2567 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2568 Result = getDerived().RebuildFunctionProtoType(ResultType,
2569 ParamTypes.data(),
2570 ParamTypes.size(),
2571 T->isVariadic(),
2572 T->getTypeQuals());
2573 if (Result.isNull())
2574 return QualType();
2575 }
Mike Stump11289f42009-09-09 15:08:12 +00002576
John McCall550e0c22009-10-21 00:40:46 +00002577 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2578 NewTL.setLParenLoc(TL.getLParenLoc());
2579 NewTL.setRParenLoc(TL.getRParenLoc());
2580 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2581 NewTL.setArg(i, ParamDecls[i]);
2582
2583 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002584}
Mike Stump11289f42009-09-09 15:08:12 +00002585
Douglas Gregord6ff3322009-08-04 16:50:30 +00002586template<typename Derived>
2587QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002588 TypeLocBuilder &TLB,
2589 FunctionNoProtoTypeLoc TL) {
2590 FunctionNoProtoType *T = TL.getTypePtr();
2591 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2592 if (ResultType.isNull())
2593 return QualType();
2594
2595 QualType Result = TL.getType();
2596 if (getDerived().AlwaysRebuild() ||
2597 ResultType != T->getResultType())
2598 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2599
2600 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2601 NewTL.setLParenLoc(TL.getLParenLoc());
2602 NewTL.setRParenLoc(TL.getRParenLoc());
2603
2604 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605}
Mike Stump11289f42009-09-09 15:08:12 +00002606
John McCallb96ec562009-12-04 22:46:56 +00002607template<typename Derived> QualType
2608TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2609 UnresolvedUsingTypeLoc TL) {
2610 UnresolvedUsingType *T = TL.getTypePtr();
2611 Decl *D = getDerived().TransformDecl(T->getDecl());
2612 if (!D)
2613 return QualType();
2614
2615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2617 Result = getDerived().RebuildUnresolvedUsingType(D);
2618 if (Result.isNull())
2619 return QualType();
2620 }
2621
2622 // We might get an arbitrary type spec type back. We should at
2623 // least always get a type spec type, though.
2624 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2625 NewTL.setNameLoc(TL.getNameLoc());
2626
2627 return Result;
2628}
2629
Douglas Gregord6ff3322009-08-04 16:50:30 +00002630template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002631QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2632 TypedefTypeLoc TL) {
2633 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634 TypedefDecl *Typedef
2635 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2636 if (!Typedef)
2637 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002638
John McCall550e0c22009-10-21 00:40:46 +00002639 QualType Result = TL.getType();
2640 if (getDerived().AlwaysRebuild() ||
2641 Typedef != T->getDecl()) {
2642 Result = getDerived().RebuildTypedefType(Typedef);
2643 if (Result.isNull())
2644 return QualType();
2645 }
Mike Stump11289f42009-09-09 15:08:12 +00002646
John McCall550e0c22009-10-21 00:40:46 +00002647 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2648 NewTL.setNameLoc(TL.getNameLoc());
2649
2650 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651}
Mike Stump11289f42009-09-09 15:08:12 +00002652
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002654QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2655 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00002656 // typeof expressions are not potentially evaluated contexts
2657 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002658
John McCalle8595032010-01-13 20:03:27 +00002659 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002660 if (E.isInvalid())
2661 return QualType();
2662
John McCall550e0c22009-10-21 00:40:46 +00002663 QualType Result = TL.getType();
2664 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002665 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002666 Result = getDerived().RebuildTypeOfExprType(move(E));
2667 if (Result.isNull())
2668 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002669 }
John McCall550e0c22009-10-21 00:40:46 +00002670 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002671
John McCall550e0c22009-10-21 00:40:46 +00002672 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002673 NewTL.setTypeofLoc(TL.getTypeofLoc());
2674 NewTL.setLParenLoc(TL.getLParenLoc());
2675 NewTL.setRParenLoc(TL.getRParenLoc());
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>::TransformTypeOfType(TypeLocBuilder &TLB,
2682 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002683 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2684 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2685 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002686 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002687
John McCall550e0c22009-10-21 00:40:46 +00002688 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002689 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2690 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002691 if (Result.isNull())
2692 return QualType();
2693 }
Mike Stump11289f42009-09-09 15:08:12 +00002694
John McCall550e0c22009-10-21 00:40:46 +00002695 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002696 NewTL.setTypeofLoc(TL.getTypeofLoc());
2697 NewTL.setLParenLoc(TL.getLParenLoc());
2698 NewTL.setRParenLoc(TL.getRParenLoc());
2699 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002700
2701 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002702}
Mike Stump11289f42009-09-09 15:08:12 +00002703
2704template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002705QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2706 DecltypeTypeLoc TL) {
2707 DecltypeType *T = TL.getTypePtr();
2708
Douglas Gregore922c772009-08-04 22:27:00 +00002709 // decltype expressions are not potentially evaluated contexts
2710 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002711
Douglas Gregord6ff3322009-08-04 16:50:30 +00002712 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2713 if (E.isInvalid())
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 E.get() != T->getUnderlyingExpr()) {
2719 Result = getDerived().RebuildDecltypeType(move(E));
2720 if (Result.isNull())
2721 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002722 }
John McCall550e0c22009-10-21 00:40:46 +00002723 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002724
John McCall550e0c22009-10-21 00:40:46 +00002725 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2726 NewTL.setNameLoc(TL.getNameLoc());
2727
2728 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002729}
2730
2731template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002732QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2733 RecordTypeLoc TL) {
2734 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002735 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002736 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002737 if (!Record)
2738 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002739
John McCall550e0c22009-10-21 00:40:46 +00002740 QualType Result = TL.getType();
2741 if (getDerived().AlwaysRebuild() ||
2742 Record != T->getDecl()) {
2743 Result = getDerived().RebuildRecordType(Record);
2744 if (Result.isNull())
2745 return QualType();
2746 }
Mike Stump11289f42009-09-09 15:08:12 +00002747
John McCall550e0c22009-10-21 00:40:46 +00002748 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2749 NewTL.setNameLoc(TL.getNameLoc());
2750
2751 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002752}
Mike Stump11289f42009-09-09 15:08:12 +00002753
2754template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002755QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2756 EnumTypeLoc TL) {
2757 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002759 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002760 if (!Enum)
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 Enum != T->getDecl()) {
2766 Result = getDerived().RebuildEnumType(Enum);
2767 if (Result.isNull())
2768 return QualType();
2769 }
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2772 NewTL.setNameLoc(TL.getNameLoc());
2773
2774 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775}
John McCallfcc33b02009-09-05 00:15:47 +00002776
2777template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002778QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2779 ElaboratedTypeLoc TL) {
2780 ElaboratedType *T = TL.getTypePtr();
2781
2782 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002783 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2784 if (Underlying.isNull())
2785 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 QualType Result = TL.getType();
2788 if (getDerived().AlwaysRebuild() ||
2789 Underlying != T->getUnderlyingType()) {
2790 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2791 if (Result.isNull())
2792 return QualType();
2793 }
Mike Stump11289f42009-09-09 15:08:12 +00002794
John McCall550e0c22009-10-21 00:40:46 +00002795 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797
2798 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002799}
Mike Stump11289f42009-09-09 15:08:12 +00002800
2801
Douglas Gregord6ff3322009-08-04 16:50:30 +00002802template<typename Derived>
2803QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002804 TypeLocBuilder &TLB,
2805 TemplateTypeParmTypeLoc TL) {
2806 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002807}
2808
Mike Stump11289f42009-09-09 15:08:12 +00002809template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002810QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002811 TypeLocBuilder &TLB,
2812 SubstTemplateTypeParmTypeLoc TL) {
2813 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002814}
2815
2816template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002817inline QualType
2818TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002819 TypeLocBuilder &TLB,
2820 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002821 return TransformTemplateSpecializationType(TLB, TL, QualType());
2822}
John McCall550e0c22009-10-21 00:40:46 +00002823
John McCall0ad16662009-10-29 08:12:44 +00002824template<typename Derived>
2825QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2826 const TemplateSpecializationType *TST,
2827 QualType ObjectType) {
2828 // FIXME: this entire method is a temporary workaround; callers
2829 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002830
John McCall0ad16662009-10-29 08:12:44 +00002831 // Fake up a TemplateSpecializationTypeLoc.
2832 TypeLocBuilder TLB;
2833 TemplateSpecializationTypeLoc TL
2834 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2835
John McCall0d07eb32009-10-29 18:45:58 +00002836 SourceLocation BaseLoc = getDerived().getBaseLocation();
2837
2838 TL.setTemplateNameLoc(BaseLoc);
2839 TL.setLAngleLoc(BaseLoc);
2840 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002841 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2842 const TemplateArgument &TA = TST->getArg(i);
2843 TemplateArgumentLoc TAL;
2844 getDerived().InventTemplateArgumentLoc(TA, TAL);
2845 TL.setArgLocInfo(i, TAL.getLocInfo());
2846 }
2847
2848 TypeLocBuilder IgnoredTLB;
2849 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002850}
2851
2852template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002853QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002854 TypeLocBuilder &TLB,
2855 TemplateSpecializationTypeLoc TL,
2856 QualType ObjectType) {
2857 const TemplateSpecializationType *T = TL.getTypePtr();
2858
Mike Stump11289f42009-09-09 15:08:12 +00002859 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002860 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002861 if (Template.isNull())
2862 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002863
John McCall6b51f282009-11-23 01:53:49 +00002864 TemplateArgumentListInfo NewTemplateArgs;
2865 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2866 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2867
2868 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2869 TemplateArgumentLoc Loc;
2870 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002871 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002872 NewTemplateArgs.addArgument(Loc);
2873 }
Mike Stump11289f42009-09-09 15:08:12 +00002874
John McCall0ad16662009-10-29 08:12:44 +00002875 // FIXME: maybe don't rebuild if all the template arguments are the same.
2876
2877 QualType Result =
2878 getDerived().RebuildTemplateSpecializationType(Template,
2879 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002880 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002881
2882 if (!Result.isNull()) {
2883 TemplateSpecializationTypeLoc NewTL
2884 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2885 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2886 NewTL.setLAngleLoc(TL.getLAngleLoc());
2887 NewTL.setRAngleLoc(TL.getRAngleLoc());
2888 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2889 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002890 }
Mike Stump11289f42009-09-09 15:08:12 +00002891
John McCall0ad16662009-10-29 08:12:44 +00002892 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002893}
Mike Stump11289f42009-09-09 15:08:12 +00002894
2895template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002896QualType
2897TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2898 QualifiedNameTypeLoc TL) {
2899 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002900 NestedNameSpecifier *NNS
2901 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2902 SourceRange());
2903 if (!NNS)
2904 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002905
Douglas Gregord6ff3322009-08-04 16:50:30 +00002906 QualType Named = getDerived().TransformType(T->getNamedType());
2907 if (Named.isNull())
2908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002909
John McCall550e0c22009-10-21 00:40:46 +00002910 QualType Result = TL.getType();
2911 if (getDerived().AlwaysRebuild() ||
2912 NNS != T->getQualifier() ||
2913 Named != T->getNamedType()) {
2914 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2915 if (Result.isNull())
2916 return QualType();
2917 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918
John McCall550e0c22009-10-21 00:40:46 +00002919 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2920 NewTL.setNameLoc(TL.getNameLoc());
2921
2922 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002923}
Mike Stump11289f42009-09-09 15:08:12 +00002924
2925template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002926QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2927 TypenameTypeLoc TL) {
2928 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002929
2930 /* FIXME: preserve source information better than this */
2931 SourceRange SR(TL.getNameLoc());
2932
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002934 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002935 if (!NNS)
2936 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002937
John McCall550e0c22009-10-21 00:40:46 +00002938 QualType Result;
2939
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002941 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942 = getDerived().TransformType(QualType(TemplateId, 0));
2943 if (NewTemplateId.isNull())
2944 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002945
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946 if (!getDerived().AlwaysRebuild() &&
2947 NNS == T->getQualifier() &&
2948 NewTemplateId == QualType(TemplateId, 0))
2949 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002950
John McCall550e0c22009-10-21 00:40:46 +00002951 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2952 } else {
John McCall0ad16662009-10-29 08:12:44 +00002953 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002954 }
John McCall550e0c22009-10-21 00:40:46 +00002955 if (Result.isNull())
2956 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957
John McCall550e0c22009-10-21 00:40:46 +00002958 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2959 NewTL.setNameLoc(TL.getNameLoc());
2960
2961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962}
Mike Stump11289f42009-09-09 15:08:12 +00002963
Douglas Gregord6ff3322009-08-04 16:50:30 +00002964template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002965QualType
2966TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2967 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002968 assert(false && "TransformObjCInterfaceType unimplemented");
2969 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002970}
Mike Stump11289f42009-09-09 15:08:12 +00002971
2972template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002973QualType
2974TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2975 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002976 assert(false && "TransformObjCObjectPointerType unimplemented");
2977 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002978}
2979
Douglas Gregord6ff3322009-08-04 16:50:30 +00002980//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002981// Statement transformation
2982//===----------------------------------------------------------------------===//
2983template<typename Derived>
2984Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002985TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2986 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002987}
2988
2989template<typename Derived>
2990Sema::OwningStmtResult
2991TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2992 return getDerived().TransformCompoundStmt(S, false);
2993}
2994
2995template<typename Derived>
2996Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002997TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002998 bool IsStmtExpr) {
2999 bool SubStmtChanged = false;
3000 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3001 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3002 B != BEnd; ++B) {
3003 OwningStmtResult Result = getDerived().TransformStmt(*B);
3004 if (Result.isInvalid())
3005 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003006
Douglas Gregorebe10102009-08-20 07:17:43 +00003007 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3008 Statements.push_back(Result.takeAs<Stmt>());
3009 }
Mike Stump11289f42009-09-09 15:08:12 +00003010
Douglas Gregorebe10102009-08-20 07:17:43 +00003011 if (!getDerived().AlwaysRebuild() &&
3012 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003013 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003014
3015 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3016 move_arg(Statements),
3017 S->getRBracLoc(),
3018 IsStmtExpr);
3019}
Mike Stump11289f42009-09-09 15:08:12 +00003020
Douglas Gregorebe10102009-08-20 07:17:43 +00003021template<typename Derived>
3022Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003023TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003024 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3025 {
3026 // The case value expressions are not potentially evaluated.
3027 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003028
Eli Friedman06577382009-11-19 03:14:00 +00003029 // Transform the left-hand case value.
3030 LHS = getDerived().TransformExpr(S->getLHS());
3031 if (LHS.isInvalid())
3032 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003033
Eli Friedman06577382009-11-19 03:14:00 +00003034 // Transform the right-hand case value (for the GNU case-range extension).
3035 RHS = getDerived().TransformExpr(S->getRHS());
3036 if (RHS.isInvalid())
3037 return SemaRef.StmtError();
3038 }
Mike Stump11289f42009-09-09 15:08:12 +00003039
Douglas Gregorebe10102009-08-20 07:17:43 +00003040 // Build the case statement.
3041 // Case statements are always rebuilt so that they will attached to their
3042 // transformed switch statement.
3043 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3044 move(LHS),
3045 S->getEllipsisLoc(),
3046 move(RHS),
3047 S->getColonLoc());
3048 if (Case.isInvalid())
3049 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003050
Douglas Gregorebe10102009-08-20 07:17:43 +00003051 // Transform the statement following the case
3052 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 // Attach the body to the case statement
3057 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3058}
3059
3060template<typename Derived>
3061Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003062TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003063 // Transform the statement following the default case
3064 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3065 if (SubStmt.isInvalid())
3066 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003067
Douglas Gregorebe10102009-08-20 07:17:43 +00003068 // Default statements are always rebuilt
3069 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3070 move(SubStmt));
3071}
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregorebe10102009-08-20 07:17:43 +00003073template<typename Derived>
3074Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003075TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003076 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3077 if (SubStmt.isInvalid())
3078 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003079
Douglas Gregorebe10102009-08-20 07:17:43 +00003080 // FIXME: Pass the real colon location in.
3081 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3082 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3083 move(SubStmt));
3084}
Mike Stump11289f42009-09-09 15:08:12 +00003085
Douglas Gregorebe10102009-08-20 07:17:43 +00003086template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003087Sema::OwningStmtResult
3088TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003089 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003090 OwningExprResult Cond(SemaRef);
3091 VarDecl *ConditionVar = 0;
3092 if (S->getConditionVariable()) {
3093 ConditionVar
3094 = cast_or_null<VarDecl>(
3095 getDerived().TransformDefinition(S->getConditionVariable()));
3096 if (!ConditionVar)
3097 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003098 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003099 Cond = getDerived().TransformExpr(S->getCond());
3100
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003101 if (Cond.isInvalid())
3102 return SemaRef.StmtError();
3103 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003104
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003105 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003106
Douglas Gregorebe10102009-08-20 07:17:43 +00003107 // Transform the "then" branch.
3108 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3109 if (Then.isInvalid())
3110 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003111
Douglas Gregorebe10102009-08-20 07:17:43 +00003112 // Transform the "else" branch.
3113 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3114 if (Else.isInvalid())
3115 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003116
Douglas Gregorebe10102009-08-20 07:17:43 +00003117 if (!getDerived().AlwaysRebuild() &&
3118 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003119 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003120 Then.get() == S->getThen() &&
3121 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003122 return SemaRef.Owned(S->Retain());
3123
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003124 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3125 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003126 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003127}
3128
3129template<typename Derived>
3130Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003131TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003133 OwningExprResult Cond(SemaRef);
3134 VarDecl *ConditionVar = 0;
3135 if (S->getConditionVariable()) {
3136 ConditionVar
3137 = cast_or_null<VarDecl>(
3138 getDerived().TransformDefinition(S->getConditionVariable()));
3139 if (!ConditionVar)
3140 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003141 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003142 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003143
3144 if (Cond.isInvalid())
3145 return SemaRef.StmtError();
3146 }
Mike Stump11289f42009-09-09 15:08:12 +00003147
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003148 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003151 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3152 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 if (Switch.isInvalid())
3154 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156 // Transform the body of the switch statement.
3157 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3158 if (Body.isInvalid())
3159 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregorebe10102009-08-20 07:17:43 +00003161 // Complete the switch statement.
3162 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3163 move(Body));
3164}
Mike Stump11289f42009-09-09 15:08:12 +00003165
Douglas Gregorebe10102009-08-20 07:17:43 +00003166template<typename Derived>
3167Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003168TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003169 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003170 OwningExprResult Cond(SemaRef);
3171 VarDecl *ConditionVar = 0;
3172 if (S->getConditionVariable()) {
3173 ConditionVar
3174 = cast_or_null<VarDecl>(
3175 getDerived().TransformDefinition(S->getConditionVariable()));
3176 if (!ConditionVar)
3177 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003178 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003179 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003180
3181 if (Cond.isInvalid())
3182 return SemaRef.StmtError();
3183 }
Mike Stump11289f42009-09-09 15:08:12 +00003184
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003185 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003186
Douglas Gregorebe10102009-08-20 07:17:43 +00003187 // Transform the body
3188 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3189 if (Body.isInvalid())
3190 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003191
Douglas Gregorebe10102009-08-20 07:17:43 +00003192 if (!getDerived().AlwaysRebuild() &&
3193 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003194 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003195 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003196 return SemaRef.Owned(S->Retain());
3197
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003198 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3199 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003200}
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202template<typename Derived>
3203Sema::OwningStmtResult
3204TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3205 // Transform the condition
3206 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3207 if (Cond.isInvalid())
3208 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003209
Douglas Gregorebe10102009-08-20 07:17:43 +00003210 // Transform the body
3211 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3212 if (Body.isInvalid())
3213 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003214
Douglas Gregorebe10102009-08-20 07:17:43 +00003215 if (!getDerived().AlwaysRebuild() &&
3216 Cond.get() == S->getCond() &&
3217 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003218 return SemaRef.Owned(S->Retain());
3219
Douglas Gregorebe10102009-08-20 07:17:43 +00003220 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3221 /*FIXME:*/S->getWhileLoc(), move(Cond),
3222 S->getRParenLoc());
3223}
Mike Stump11289f42009-09-09 15:08:12 +00003224
Douglas Gregorebe10102009-08-20 07:17:43 +00003225template<typename Derived>
3226Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003227TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003228 // Transform the initialization statement
3229 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3230 if (Init.isInvalid())
3231 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003232
Douglas Gregorebe10102009-08-20 07:17:43 +00003233 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003234 OwningExprResult Cond(SemaRef);
3235 VarDecl *ConditionVar = 0;
3236 if (S->getConditionVariable()) {
3237 ConditionVar
3238 = cast_or_null<VarDecl>(
3239 getDerived().TransformDefinition(S->getConditionVariable()));
3240 if (!ConditionVar)
3241 return SemaRef.StmtError();
3242 } else {
3243 Cond = getDerived().TransformExpr(S->getCond());
3244
3245 if (Cond.isInvalid())
3246 return SemaRef.StmtError();
3247 }
Mike Stump11289f42009-09-09 15:08:12 +00003248
Douglas Gregorebe10102009-08-20 07:17:43 +00003249 // Transform the increment
3250 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3251 if (Inc.isInvalid())
3252 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 // Transform the body
3255 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3256 if (Body.isInvalid())
3257 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259 if (!getDerived().AlwaysRebuild() &&
3260 Init.get() == S->getInit() &&
3261 Cond.get() == S->getCond() &&
3262 Inc.get() == S->getInc() &&
3263 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003264 return SemaRef.Owned(S->Retain());
3265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003267 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003268 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003269 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003270 S->getRParenLoc(), move(Body));
3271}
3272
3273template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003274Sema::OwningStmtResult
3275TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003277 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 S->getLabel());
3279}
3280
3281template<typename Derived>
3282Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003283TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3285 if (Target.isInvalid())
3286 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 if (!getDerived().AlwaysRebuild() &&
3289 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003290 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003291
3292 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3293 move(Target));
3294}
3295
3296template<typename Derived>
3297Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003298TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3299 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003300}
Mike Stump11289f42009-09-09 15:08:12 +00003301
Douglas Gregorebe10102009-08-20 07:17:43 +00003302template<typename Derived>
3303Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003304TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3305 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003306}
Mike Stump11289f42009-09-09 15:08:12 +00003307
Douglas Gregorebe10102009-08-20 07:17:43 +00003308template<typename Derived>
3309Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003310TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003311 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3312 if (Result.isInvalid())
3313 return SemaRef.StmtError();
3314
Mike Stump11289f42009-09-09 15:08:12 +00003315 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003316 // to tell whether the return type of the function has changed.
3317 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003323 bool DeclChanged = false;
3324 llvm::SmallVector<Decl *, 4> Decls;
3325 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3326 D != DEnd; ++D) {
3327 Decl *Transformed = getDerived().TransformDefinition(*D);
3328 if (!Transformed)
3329 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003330
Douglas Gregorebe10102009-08-20 07:17:43 +00003331 if (Transformed != *D)
3332 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregorebe10102009-08-20 07:17:43 +00003334 Decls.push_back(Transformed);
3335 }
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregorebe10102009-08-20 07:17:43 +00003337 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003338 return SemaRef.Owned(S->Retain());
3339
3340 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003341 S->getStartLoc(), S->getEndLoc());
3342}
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>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003347 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003348 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003349}
3350
3351template<typename Derived>
3352Sema::OwningStmtResult
3353TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003354
3355 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3356 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003357 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003358
Anders Carlssonaaeef072010-01-24 05:50:09 +00003359 OwningExprResult AsmString(SemaRef);
3360 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3361
3362 bool ExprsChanged = false;
3363
3364 // Go through the outputs.
3365 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003366 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003367
Anders Carlssonaaeef072010-01-24 05:50:09 +00003368 // No need to transform the constraint literal.
3369 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3370
3371 // Transform the output expr.
3372 Expr *OutputExpr = S->getOutputExpr(I);
3373 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3374 if (Result.isInvalid())
3375 return SemaRef.StmtError();
3376
3377 ExprsChanged |= Result.get() != OutputExpr;
3378
3379 Exprs.push_back(Result.takeAs<Expr>());
3380 }
3381
3382 // Go through the inputs.
3383 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003384 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003385
Anders Carlssonaaeef072010-01-24 05:50:09 +00003386 // No need to transform the constraint literal.
3387 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3388
3389 // Transform the input expr.
3390 Expr *InputExpr = S->getInputExpr(I);
3391 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3392 if (Result.isInvalid())
3393 return SemaRef.StmtError();
3394
3395 ExprsChanged |= Result.get() != InputExpr;
3396
3397 Exprs.push_back(Result.takeAs<Expr>());
3398 }
3399
3400 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3401 return SemaRef.Owned(S->Retain());
3402
3403 // Go through the clobbers.
3404 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3405 Clobbers.push_back(S->getClobber(I)->Retain());
3406
3407 // No need to transform the asm string literal.
3408 AsmString = SemaRef.Owned(S->getAsmString());
3409
3410 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3411 S->isSimple(),
3412 S->isVolatile(),
3413 S->getNumOutputs(),
3414 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003415 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003416 move_arg(Constraints),
3417 move_arg(Exprs),
3418 move(AsmString),
3419 move_arg(Clobbers),
3420 S->getRParenLoc(),
3421 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003422}
3423
3424
3425template<typename Derived>
3426Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003427TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003428 // FIXME: Implement this
3429 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003430 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003431}
Mike Stump11289f42009-09-09 15:08:12 +00003432
Douglas Gregorebe10102009-08-20 07:17:43 +00003433template<typename Derived>
3434Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003435TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 // FIXME: Implement this
3437 assert(false && "Cannot transform an Objective-C @catch statement");
3438 return SemaRef.Owned(S->Retain());
3439}
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregorebe10102009-08-20 07:17:43 +00003441template<typename Derived>
3442Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003443TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 // FIXME: Implement this
3445 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003446 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003447}
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregorebe10102009-08-20 07:17:43 +00003449template<typename Derived>
3450Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003451TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003452 // FIXME: Implement this
3453 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003454 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003455}
Mike Stump11289f42009-09-09 15:08:12 +00003456
Douglas Gregorebe10102009-08-20 07:17:43 +00003457template<typename Derived>
3458Sema::OwningStmtResult
3459TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003460 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 // FIXME: Implement this
3462 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003464}
3465
3466template<typename Derived>
3467Sema::OwningStmtResult
3468TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003469 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003470 // FIXME: Implement this
3471 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003472 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003473}
3474
3475
3476template<typename Derived>
3477Sema::OwningStmtResult
3478TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3479 // Transform the exception declaration, if any.
3480 VarDecl *Var = 0;
3481 if (S->getExceptionDecl()) {
3482 VarDecl *ExceptionDecl = S->getExceptionDecl();
3483 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3484 ExceptionDecl->getDeclName());
3485
3486 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3487 if (T.isNull())
3488 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregorebe10102009-08-20 07:17:43 +00003490 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3491 T,
John McCallbcd03502009-12-07 02:54:59 +00003492 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003493 ExceptionDecl->getIdentifier(),
3494 ExceptionDecl->getLocation(),
3495 /*FIXME: Inaccurate*/
3496 SourceRange(ExceptionDecl->getLocation()));
3497 if (!Var || Var->isInvalidDecl()) {
3498 if (Var)
3499 Var->Destroy(SemaRef.Context);
3500 return SemaRef.StmtError();
3501 }
3502 }
Mike Stump11289f42009-09-09 15:08:12 +00003503
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 // Transform the actual exception handler.
3505 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3506 if (Handler.isInvalid()) {
3507 if (Var)
3508 Var->Destroy(SemaRef.Context);
3509 return SemaRef.StmtError();
3510 }
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 if (!getDerived().AlwaysRebuild() &&
3513 !Var &&
3514 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003515 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003516
3517 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3518 Var,
3519 move(Handler));
3520}
Mike Stump11289f42009-09-09 15:08:12 +00003521
Douglas Gregorebe10102009-08-20 07:17:43 +00003522template<typename Derived>
3523Sema::OwningStmtResult
3524TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3525 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003526 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 = getDerived().TransformCompoundStmt(S->getTryBlock());
3528 if (TryBlock.isInvalid())
3529 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 // Transform the handlers.
3532 bool HandlerChanged = false;
3533 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3534 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003535 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3537 if (Handler.isInvalid())
3538 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003539
Douglas Gregorebe10102009-08-20 07:17:43 +00003540 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3541 Handlers.push_back(Handler.takeAs<Stmt>());
3542 }
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregorebe10102009-08-20 07:17:43 +00003544 if (!getDerived().AlwaysRebuild() &&
3545 TryBlock.get() == S->getTryBlock() &&
3546 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003547 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003548
3549 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003550 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003551}
Mike Stump11289f42009-09-09 15:08:12 +00003552
Douglas Gregorebe10102009-08-20 07:17:43 +00003553//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003554// Expression transformation
3555//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003556template<typename Derived>
3557Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003558TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003559 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003560}
Mike Stump11289f42009-09-09 15:08:12 +00003561
3562template<typename Derived>
3563Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003564TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003565 NestedNameSpecifier *Qualifier = 0;
3566 if (E->getQualifier()) {
3567 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3568 E->getQualifierRange());
3569 if (!Qualifier)
3570 return SemaRef.ExprError();
3571 }
John McCallce546572009-12-08 09:08:17 +00003572
3573 ValueDecl *ND
3574 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003575 if (!ND)
3576 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003578 if (!getDerived().AlwaysRebuild() &&
3579 Qualifier == E->getQualifier() &&
3580 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003581 !E->hasExplicitTemplateArgumentList()) {
3582
3583 // Mark it referenced in the new context regardless.
3584 // FIXME: this is a bit instantiation-specific.
3585 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3586
Mike Stump11289f42009-09-09 15:08:12 +00003587 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003588 }
John McCallce546572009-12-08 09:08:17 +00003589
3590 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3591 if (E->hasExplicitTemplateArgumentList()) {
3592 TemplateArgs = &TransArgs;
3593 TransArgs.setLAngleLoc(E->getLAngleLoc());
3594 TransArgs.setRAngleLoc(E->getRAngleLoc());
3595 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3596 TemplateArgumentLoc Loc;
3597 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3598 return SemaRef.ExprError();
3599 TransArgs.addArgument(Loc);
3600 }
3601 }
3602
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003603 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003604 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003605}
Mike Stump11289f42009-09-09 15:08:12 +00003606
Douglas Gregora16548e2009-08-11 05:31:07 +00003607template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003608Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003609TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003610 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003611}
Mike Stump11289f42009-09-09 15:08:12 +00003612
Douglas Gregora16548e2009-08-11 05:31:07 +00003613template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003614Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003615TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003616 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003617}
Mike Stump11289f42009-09-09 15:08:12 +00003618
Douglas Gregora16548e2009-08-11 05:31:07 +00003619template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003620Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003621TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003622 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003623}
Mike Stump11289f42009-09-09 15:08:12 +00003624
Douglas Gregora16548e2009-08-11 05:31:07 +00003625template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003626Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003627TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003628 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003629}
Mike Stump11289f42009-09-09 15:08:12 +00003630
Douglas Gregora16548e2009-08-11 05:31:07 +00003631template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003632Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003633TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003634 return SemaRef.Owned(E->Retain());
3635}
3636
3637template<typename Derived>
3638Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003639TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003640 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3641 if (SubExpr.isInvalid())
3642 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003643
Douglas Gregora16548e2009-08-11 05:31:07 +00003644 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003645 return SemaRef.Owned(E->Retain());
3646
3647 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003648 E->getRParen());
3649}
3650
Mike Stump11289f42009-09-09 15:08:12 +00003651template<typename Derived>
3652Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003653TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3654 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003655 if (SubExpr.isInvalid())
3656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregora16548e2009-08-11 05:31:07 +00003658 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003659 return SemaRef.Owned(E->Retain());
3660
Douglas Gregora16548e2009-08-11 05:31:07 +00003661 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3662 E->getOpcode(),
3663 move(SubExpr));
3664}
Mike Stump11289f42009-09-09 15:08:12 +00003665
Douglas Gregora16548e2009-08-11 05:31:07 +00003666template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003667Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003668TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003669 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003670 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003671
John McCallbcd03502009-12-07 02:54:59 +00003672 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003673 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003674 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003675
John McCall4c98fd82009-11-04 07:28:41 +00003676 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003677 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003678
John McCall4c98fd82009-11-04 07:28:41 +00003679 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003680 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003681 E->getSourceRange());
3682 }
Mike Stump11289f42009-09-09 15:08:12 +00003683
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003685 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003686 // C++0x [expr.sizeof]p1:
3687 // The operand is either an expression, which is an unevaluated operand
3688 // [...]
3689 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregora16548e2009-08-11 05:31:07 +00003691 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3692 if (SubExpr.isInvalid())
3693 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003694
Douglas Gregora16548e2009-08-11 05:31:07 +00003695 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3696 return SemaRef.Owned(E->Retain());
3697 }
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregora16548e2009-08-11 05:31:07 +00003699 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3700 E->isSizeOf(),
3701 E->getSourceRange());
3702}
Mike Stump11289f42009-09-09 15:08:12 +00003703
Douglas Gregora16548e2009-08-11 05:31:07 +00003704template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003705Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003706TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3708 if (LHS.isInvalid())
3709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregora16548e2009-08-11 05:31:07 +00003711 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3712 if (RHS.isInvalid())
3713 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003714
3715
Douglas Gregora16548e2009-08-11 05:31:07 +00003716 if (!getDerived().AlwaysRebuild() &&
3717 LHS.get() == E->getLHS() &&
3718 RHS.get() == E->getRHS())
3719 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregora16548e2009-08-11 05:31:07 +00003721 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3722 /*FIXME:*/E->getLHS()->getLocStart(),
3723 move(RHS),
3724 E->getRBracketLoc());
3725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
3727template<typename Derived>
3728Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003729TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 // Transform the callee.
3731 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3732 if (Callee.isInvalid())
3733 return SemaRef.ExprError();
3734
3735 // Transform arguments.
3736 bool ArgChanged = false;
3737 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3738 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3739 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3740 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3741 if (Arg.isInvalid())
3742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 // FIXME: Wrong source location information for the ','.
3745 FakeCommaLocs.push_back(
3746 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003747
3748 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 Args.push_back(Arg.takeAs<Expr>());
3750 }
Mike Stump11289f42009-09-09 15:08:12 +00003751
Douglas Gregora16548e2009-08-11 05:31:07 +00003752 if (!getDerived().AlwaysRebuild() &&
3753 Callee.get() == E->getCallee() &&
3754 !ArgChanged)
3755 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003758 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003759 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3760 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3761 move_arg(Args),
3762 FakeCommaLocs.data(),
3763 E->getRParenLoc());
3764}
Mike Stump11289f42009-09-09 15:08:12 +00003765
3766template<typename Derived>
3767Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003768TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3770 if (Base.isInvalid())
3771 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003772
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003773 NestedNameSpecifier *Qualifier = 0;
3774 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003775 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003776 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3777 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003778 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003779 return SemaRef.ExprError();
3780 }
Mike Stump11289f42009-09-09 15:08:12 +00003781
Eli Friedman2cfcef62009-12-04 06:40:45 +00003782 ValueDecl *Member
3783 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003784 if (!Member)
3785 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003786
Douglas Gregora16548e2009-08-11 05:31:07 +00003787 if (!getDerived().AlwaysRebuild() &&
3788 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003789 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003790 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003791 !E->hasExplicitTemplateArgumentList()) {
3792
3793 // Mark it referenced in the new context regardless.
3794 // FIXME: this is a bit instantiation-specific.
3795 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003796 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003797 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003798
John McCall6b51f282009-11-23 01:53:49 +00003799 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003800 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003801 TransArgs.setLAngleLoc(E->getLAngleLoc());
3802 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003803 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003804 TemplateArgumentLoc Loc;
3805 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003806 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003807 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003808 }
3809 }
3810
Douglas Gregora16548e2009-08-11 05:31:07 +00003811 // FIXME: Bogus source location for the operator
3812 SourceLocation FakeOperatorLoc
3813 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3814
John McCall38836f02010-01-15 08:34:02 +00003815 // FIXME: to do this check properly, we will need to preserve the
3816 // first-qualifier-in-scope here, just in case we had a dependent
3817 // base (and therefore couldn't do the check) and a
3818 // nested-name-qualifier (and therefore could do the lookup).
3819 NamedDecl *FirstQualifierInScope = 0;
3820
Douglas Gregora16548e2009-08-11 05:31:07 +00003821 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3822 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003823 Qualifier,
3824 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003825 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003826 Member,
John McCall6b51f282009-11-23 01:53:49 +00003827 (E->hasExplicitTemplateArgumentList()
3828 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003829 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003830}
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregora16548e2009-08-11 05:31:07 +00003832template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003834TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003835 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3836 if (LHS.isInvalid())
3837 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregora16548e2009-08-11 05:31:07 +00003839 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3840 if (RHS.isInvalid())
3841 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843 if (!getDerived().AlwaysRebuild() &&
3844 LHS.get() == E->getLHS() &&
3845 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003846 return SemaRef.Owned(E->Retain());
3847
Douglas Gregora16548e2009-08-11 05:31:07 +00003848 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3849 move(LHS), move(RHS));
3850}
3851
Mike Stump11289f42009-09-09 15:08:12 +00003852template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003853Sema::OwningExprResult
3854TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003855 CompoundAssignOperator *E) {
3856 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003857}
Mike Stump11289f42009-09-09 15:08:12 +00003858
Douglas Gregora16548e2009-08-11 05:31:07 +00003859template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003860Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003861TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3863 if (Cond.isInvalid())
3864 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003865
Douglas Gregora16548e2009-08-11 05:31:07 +00003866 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3867 if (LHS.isInvalid())
3868 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003869
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3871 if (RHS.isInvalid())
3872 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003873
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 if (!getDerived().AlwaysRebuild() &&
3875 Cond.get() == E->getCond() &&
3876 LHS.get() == E->getLHS() &&
3877 RHS.get() == E->getRHS())
3878 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003879
3880 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003881 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003882 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003883 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003884 move(RHS));
3885}
Mike Stump11289f42009-09-09 15:08:12 +00003886
3887template<typename Derived>
3888Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003889TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003890 // Implicit casts are eliminated during transformation, since they
3891 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003892 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003893}
Mike Stump11289f42009-09-09 15:08:12 +00003894
Douglas Gregora16548e2009-08-11 05:31:07 +00003895template<typename Derived>
3896Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003897TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003898 TypeSourceInfo *OldT;
3899 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 {
3901 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003902 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003903 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3904 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003905
John McCall97513962010-01-15 18:39:57 +00003906 OldT = E->getTypeInfoAsWritten();
3907 NewT = getDerived().TransformType(OldT);
3908 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 return SemaRef.ExprError();
3910 }
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregor6131b442009-12-12 18:16:41 +00003912 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003913 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003914 if (SubExpr.isInvalid())
3915 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003918 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003920 return SemaRef.Owned(E->Retain());
3921
John McCall97513962010-01-15 18:39:57 +00003922 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3923 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 E->getRParenLoc(),
3925 move(SubExpr));
3926}
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregora16548e2009-08-11 05:31:07 +00003928template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003929Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003930TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003931 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3932 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3933 if (!NewT)
3934 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3937 if (Init.isInvalid())
3938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003941 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003943 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003944
John McCall5d7aa7f2010-01-19 22:33:45 +00003945 // Note: the expression type doesn't necessarily match the
3946 // type-as-written, but that's okay, because it should always be
3947 // derivable from the initializer.
3948
John McCalle15bbff2010-01-18 19:35:47 +00003949 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 /*FIXME:*/E->getInitializer()->getLocEnd(),
3951 move(Init));
3952}
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954template<typename Derived>
3955Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003956TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003957 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3958 if (Base.isInvalid())
3959 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 if (!getDerived().AlwaysRebuild() &&
3962 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003963 return SemaRef.Owned(E->Retain());
3964
Douglas Gregora16548e2009-08-11 05:31:07 +00003965 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003966 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3968 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3969 E->getAccessorLoc(),
3970 E->getAccessor());
3971}
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003974Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003975TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregora16548e2009-08-11 05:31:07 +00003978 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3979 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3980 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3981 if (Init.isInvalid())
3982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003983
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 InitChanged = InitChanged || Init.get() != E->getInit(I);
3985 Inits.push_back(Init.takeAs<Expr>());
3986 }
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003989 return SemaRef.Owned(E->Retain());
3990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003992 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003993}
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995template<typename Derived>
3996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003997TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003998 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregorebe10102009-08-20 07:17:43 +00004000 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004001 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4002 if (Init.isInvalid())
4003 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregorebe10102009-08-20 07:17:43 +00004005 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4007 bool ExprChanged = false;
4008 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4009 DEnd = E->designators_end();
4010 D != DEnd; ++D) {
4011 if (D->isFieldDesignator()) {
4012 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4013 D->getDotLoc(),
4014 D->getFieldLoc()));
4015 continue;
4016 }
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 if (D->isArrayDesignator()) {
4019 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4020 if (Index.isInvalid())
4021 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004022
4023 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4027 ArrayExprs.push_back(Index.release());
4028 continue;
4029 }
Mike Stump11289f42009-09-09 15:08:12 +00004030
Douglas Gregora16548e2009-08-11 05:31:07 +00004031 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004032 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4034 if (Start.isInvalid())
4035 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregora16548e2009-08-11 05:31:07 +00004037 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4038 if (End.isInvalid())
4039 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004040
4041 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004042 End.get(),
4043 D->getLBracketLoc(),
4044 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4047 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 ArrayExprs.push_back(Start.release());
4050 ArrayExprs.push_back(End.release());
4051 }
Mike Stump11289f42009-09-09 15:08:12 +00004052
Douglas Gregora16548e2009-08-11 05:31:07 +00004053 if (!getDerived().AlwaysRebuild() &&
4054 Init.get() == E->getInit() &&
4055 !ExprChanged)
4056 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregora16548e2009-08-11 05:31:07 +00004058 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4059 E->getEqualOrColonLoc(),
4060 E->usesGNUSyntax(), move(Init));
4061}
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregora16548e2009-08-11 05:31:07 +00004063template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004064Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004065TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004066 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004067 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4068
4069 // FIXME: Will we ever have proper type location here? Will we actually
4070 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 QualType T = getDerived().TransformType(E->getType());
4072 if (T.isNull())
4073 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 if (!getDerived().AlwaysRebuild() &&
4076 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004077 return SemaRef.Owned(E->Retain());
4078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079 return getDerived().RebuildImplicitValueInitExpr(T);
4080}
Mike Stump11289f42009-09-09 15:08:12 +00004081
Douglas Gregora16548e2009-08-11 05:31:07 +00004082template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004083Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004084TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004085 // FIXME: Do we want the type as written?
4086 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 {
4089 // FIXME: Source location isn't quite accurate.
4090 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4091 T = getDerived().TransformType(E->getType());
4092 if (T.isNull())
4093 return SemaRef.ExprError();
4094 }
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4097 if (SubExpr.isInvalid())
4098 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 if (!getDerived().AlwaysRebuild() &&
4101 T == E->getType() &&
4102 SubExpr.get() == E->getSubExpr())
4103 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregora16548e2009-08-11 05:31:07 +00004105 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4106 T, E->getRParenLoc());
4107}
4108
4109template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004110Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004111TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 bool ArgumentChanged = false;
4113 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4114 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4115 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4116 if (Init.isInvalid())
4117 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004118
Douglas Gregora16548e2009-08-11 05:31:07 +00004119 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4120 Inits.push_back(Init.takeAs<Expr>());
4121 }
Mike Stump11289f42009-09-09 15:08:12 +00004122
Douglas Gregora16548e2009-08-11 05:31:07 +00004123 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4124 move_arg(Inits),
4125 E->getRParenLoc());
4126}
Mike Stump11289f42009-09-09 15:08:12 +00004127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128/// \brief Transform an address-of-label expression.
4129///
4130/// By default, the transformation of an address-of-label expression always
4131/// rebuilds the expression, so that the label identifier can be resolved to
4132/// the corresponding label statement by semantic analysis.
4133template<typename Derived>
4134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004135TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004136 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4137 E->getLabel());
4138}
Mike Stump11289f42009-09-09 15:08:12 +00004139
4140template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004141Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004142TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004143 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004144 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4145 if (SubStmt.isInvalid())
4146 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregora16548e2009-08-11 05:31:07 +00004148 if (!getDerived().AlwaysRebuild() &&
4149 SubStmt.get() == E->getSubStmt())
4150 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004151
4152 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 move(SubStmt),
4154 E->getRParenLoc());
4155}
Mike Stump11289f42009-09-09 15:08:12 +00004156
Douglas Gregora16548e2009-08-11 05:31:07 +00004157template<typename Derived>
4158Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004159TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 QualType T1, T2;
4161 {
4162 // FIXME: Source location isn't quite accurate.
4163 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165 T1 = getDerived().TransformType(E->getArgType1());
4166 if (T1.isNull())
4167 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169 T2 = getDerived().TransformType(E->getArgType2());
4170 if (T2.isNull())
4171 return SemaRef.ExprError();
4172 }
4173
4174 if (!getDerived().AlwaysRebuild() &&
4175 T1 == E->getArgType1() &&
4176 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004177 return SemaRef.Owned(E->Retain());
4178
Douglas Gregora16548e2009-08-11 05:31:07 +00004179 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4180 T1, T2, E->getRParenLoc());
4181}
Mike Stump11289f42009-09-09 15:08:12 +00004182
Douglas Gregora16548e2009-08-11 05:31:07 +00004183template<typename Derived>
4184Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004185TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4187 if (Cond.isInvalid())
4188 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004189
Douglas Gregora16548e2009-08-11 05:31:07 +00004190 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4191 if (LHS.isInvalid())
4192 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004193
Douglas Gregora16548e2009-08-11 05:31:07 +00004194 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4195 if (RHS.isInvalid())
4196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 if (!getDerived().AlwaysRebuild() &&
4199 Cond.get() == E->getCond() &&
4200 LHS.get() == E->getLHS() &&
4201 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004202 return SemaRef.Owned(E->Retain());
4203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4205 move(Cond), move(LHS), move(RHS),
4206 E->getRParenLoc());
4207}
Mike Stump11289f42009-09-09 15:08:12 +00004208
Douglas Gregora16548e2009-08-11 05:31:07 +00004209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004210Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004211TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004212 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004213}
4214
4215template<typename Derived>
4216Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004217TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004218 switch (E->getOperator()) {
4219 case OO_New:
4220 case OO_Delete:
4221 case OO_Array_New:
4222 case OO_Array_Delete:
4223 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4224 return SemaRef.ExprError();
4225
4226 case OO_Call: {
4227 // This is a call to an object's operator().
4228 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4229
4230 // Transform the object itself.
4231 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4232 if (Object.isInvalid())
4233 return SemaRef.ExprError();
4234
4235 // FIXME: Poor location information
4236 SourceLocation FakeLParenLoc
4237 = SemaRef.PP.getLocForEndOfToken(
4238 static_cast<Expr *>(Object.get())->getLocEnd());
4239
4240 // Transform the call arguments.
4241 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4242 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4243 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004244 if (getDerived().DropCallArgument(E->getArg(I)))
4245 break;
4246
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004247 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4248 if (Arg.isInvalid())
4249 return SemaRef.ExprError();
4250
4251 // FIXME: Poor source location information.
4252 SourceLocation FakeCommaLoc
4253 = SemaRef.PP.getLocForEndOfToken(
4254 static_cast<Expr *>(Arg.get())->getLocEnd());
4255 FakeCommaLocs.push_back(FakeCommaLoc);
4256 Args.push_back(Arg.release());
4257 }
4258
4259 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4260 move_arg(Args),
4261 FakeCommaLocs.data(),
4262 E->getLocEnd());
4263 }
4264
4265#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4266 case OO_##Name:
4267#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4268#include "clang/Basic/OperatorKinds.def"
4269 case OO_Subscript:
4270 // Handled below.
4271 break;
4272
4273 case OO_Conditional:
4274 llvm_unreachable("conditional operator is not actually overloadable");
4275 return SemaRef.ExprError();
4276
4277 case OO_None:
4278 case NUM_OVERLOADED_OPERATORS:
4279 llvm_unreachable("not an overloaded operator?");
4280 return SemaRef.ExprError();
4281 }
4282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4284 if (Callee.isInvalid())
4285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004286
John McCall47f29ea2009-12-08 09:21:05 +00004287 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 if (First.isInvalid())
4289 return SemaRef.ExprError();
4290
4291 OwningExprResult Second(SemaRef);
4292 if (E->getNumArgs() == 2) {
4293 Second = getDerived().TransformExpr(E->getArg(1));
4294 if (Second.isInvalid())
4295 return SemaRef.ExprError();
4296 }
Mike Stump11289f42009-09-09 15:08:12 +00004297
Douglas Gregora16548e2009-08-11 05:31:07 +00004298 if (!getDerived().AlwaysRebuild() &&
4299 Callee.get() == E->getCallee() &&
4300 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004301 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4302 return SemaRef.Owned(E->Retain());
4303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4305 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004306 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 move(First),
4308 move(Second));
4309}
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311template<typename Derived>
4312Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004313TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4314 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004315}
Mike Stump11289f42009-09-09 15:08:12 +00004316
Douglas Gregora16548e2009-08-11 05:31:07 +00004317template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004318Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004319TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004320 TypeSourceInfo *OldT;
4321 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 {
4323 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004324 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4326 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004327
John McCall97513962010-01-15 18:39:57 +00004328 OldT = E->getTypeInfoAsWritten();
4329 NewT = getDerived().TransformType(OldT);
4330 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 return SemaRef.ExprError();
4332 }
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregor6131b442009-12-12 18:16:41 +00004334 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004335 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 if (SubExpr.isInvalid())
4337 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004340 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004342 return SemaRef.Owned(E->Retain());
4343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004345 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004346 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4347 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4348 SourceLocation FakeRParenLoc
4349 = SemaRef.PP.getLocForEndOfToken(
4350 E->getSubExpr()->getSourceRange().getEnd());
4351 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004352 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004354 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 FakeRAngleLoc,
4356 FakeRAngleLoc,
4357 move(SubExpr),
4358 FakeRParenLoc);
4359}
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361template<typename Derived>
4362Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004363TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4364 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004365}
Mike Stump11289f42009-09-09 15:08:12 +00004366
4367template<typename Derived>
4368Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004369TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4370 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004371}
4372
Douglas Gregora16548e2009-08-11 05:31:07 +00004373template<typename Derived>
4374Sema::OwningExprResult
4375TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004376 CXXReinterpretCastExpr *E) {
4377 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004378}
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregora16548e2009-08-11 05:31:07 +00004380template<typename Derived>
4381Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004382TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4383 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004384}
Mike Stump11289f42009-09-09 15:08:12 +00004385
Douglas Gregora16548e2009-08-11 05:31:07 +00004386template<typename Derived>
4387Sema::OwningExprResult
4388TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004389 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004390 TypeSourceInfo *OldT;
4391 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 {
4393 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004394
John McCall97513962010-01-15 18:39:57 +00004395 OldT = E->getTypeInfoAsWritten();
4396 NewT = getDerived().TransformType(OldT);
4397 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 return SemaRef.ExprError();
4399 }
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregor6131b442009-12-12 18:16:41 +00004401 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004402 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 if (SubExpr.isInvalid())
4404 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004407 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004408 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004409 return SemaRef.Owned(E->Retain());
4410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 // FIXME: The end of the type's source range is wrong
4412 return getDerived().RebuildCXXFunctionalCastExpr(
4413 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004414 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 /*FIXME:*/E->getSubExpr()->getLocStart(),
4416 move(SubExpr),
4417 E->getRParenLoc());
4418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregora16548e2009-08-11 05:31:07 +00004420template<typename Derived>
4421Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004422TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 if (E->isTypeOperand()) {
4424 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 QualType T = getDerived().TransformType(E->getTypeOperand());
4427 if (T.isNull())
4428 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 if (!getDerived().AlwaysRebuild() &&
4431 T == E->getTypeOperand())
4432 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregora16548e2009-08-11 05:31:07 +00004434 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4435 /*FIXME:*/E->getLocStart(),
4436 T,
4437 E->getLocEnd());
4438 }
Mike Stump11289f42009-09-09 15:08:12 +00004439
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 // We don't know whether the expression is potentially evaluated until
4441 // after we perform semantic analysis, so the expression is potentially
4442 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004443 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4447 if (SubExpr.isInvalid())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 if (!getDerived().AlwaysRebuild() &&
4451 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004452 return SemaRef.Owned(E->Retain());
4453
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4455 /*FIXME:*/E->getLocStart(),
4456 move(SubExpr),
4457 E->getLocEnd());
4458}
4459
4460template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004461Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004462TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004463 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004464}
Mike Stump11289f42009-09-09 15:08:12 +00004465
Douglas Gregora16548e2009-08-11 05:31:07 +00004466template<typename Derived>
4467Sema::OwningExprResult
4468TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004469 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004470 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004471}
Mike Stump11289f42009-09-09 15:08:12 +00004472
Douglas Gregora16548e2009-08-11 05:31:07 +00004473template<typename Derived>
4474Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004475TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 QualType T = getDerived().TransformType(E->getType());
4479 if (T.isNull())
4480 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004481
Douglas Gregora16548e2009-08-11 05:31:07 +00004482 if (!getDerived().AlwaysRebuild() &&
4483 T == E->getType())
4484 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004485
Douglas Gregorb15af892010-01-07 23:12:05 +00004486 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004487}
Mike Stump11289f42009-09-09 15:08:12 +00004488
Douglas Gregora16548e2009-08-11 05:31:07 +00004489template<typename Derived>
4490Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004491TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4493 if (SubExpr.isInvalid())
4494 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregora16548e2009-08-11 05:31:07 +00004496 if (!getDerived().AlwaysRebuild() &&
4497 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004498 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004499
4500 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4501}
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregora16548e2009-08-11 05:31:07 +00004503template<typename Derived>
4504Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004505TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004506 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004507 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4508 if (!Param)
4509 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 if (getDerived().AlwaysRebuild() &&
4512 Param == E->getParam())
4513 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004514
Douglas Gregor033f6752009-12-23 23:03:06 +00004515 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004516}
Mike Stump11289f42009-09-09 15:08:12 +00004517
Douglas Gregora16548e2009-08-11 05:31:07 +00004518template<typename Derived>
4519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004520TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4522
4523 QualType T = getDerived().TransformType(E->getType());
4524 if (T.isNull())
4525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregora16548e2009-08-11 05:31:07 +00004527 if (!getDerived().AlwaysRebuild() &&
4528 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004529 return SemaRef.Owned(E->Retain());
4530
4531 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 /*FIXME:*/E->getTypeBeginLoc(),
4533 T,
4534 E->getRParenLoc());
4535}
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregora16548e2009-08-11 05:31:07 +00004537template<typename Derived>
4538Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004539TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 // Transform the type that we're allocating
4541 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4542 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4543 if (AllocType.isNull())
4544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 // Transform the size of the array we're allocating (if any).
4547 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4548 if (ArraySize.isInvalid())
4549 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregora16548e2009-08-11 05:31:07 +00004551 // Transform the placement arguments (if any).
4552 bool ArgumentChanged = false;
4553 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4554 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4555 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4556 if (Arg.isInvalid())
4557 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4560 PlacementArgs.push_back(Arg.take());
4561 }
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregorebe10102009-08-20 07:17:43 +00004563 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4565 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4566 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4567 if (Arg.isInvalid())
4568 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4571 ConstructorArgs.push_back(Arg.take());
4572 }
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 AllocType == E->getAllocatedType() &&
4576 ArraySize.get() == E->getArraySize() &&
4577 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004578 return SemaRef.Owned(E->Retain());
4579
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004580 if (!ArraySize.get()) {
4581 // If no array size was specified, but the new expression was
4582 // instantiated with an array type (e.g., "new T" where T is
4583 // instantiated with "int[4]"), extract the outer bound from the
4584 // array type as our array size. We do this with constant and
4585 // dependently-sized array types.
4586 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4587 if (!ArrayT) {
4588 // Do nothing
4589 } else if (const ConstantArrayType *ConsArrayT
4590 = dyn_cast<ConstantArrayType>(ArrayT)) {
4591 ArraySize
4592 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4593 ConsArrayT->getSize(),
4594 SemaRef.Context.getSizeType(),
4595 /*FIXME:*/E->getLocStart()));
4596 AllocType = ConsArrayT->getElementType();
4597 } else if (const DependentSizedArrayType *DepArrayT
4598 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4599 if (DepArrayT->getSizeExpr()) {
4600 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4601 AllocType = DepArrayT->getElementType();
4602 }
4603 }
4604 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4606 E->isGlobalNew(),
4607 /*FIXME:*/E->getLocStart(),
4608 move_arg(PlacementArgs),
4609 /*FIXME:*/E->getLocStart(),
4610 E->isParenTypeId(),
4611 AllocType,
4612 /*FIXME:*/E->getLocStart(),
4613 /*FIXME:*/SourceRange(),
4614 move(ArraySize),
4615 /*FIXME:*/E->getLocStart(),
4616 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004617 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004618}
Mike Stump11289f42009-09-09 15:08:12 +00004619
Douglas Gregora16548e2009-08-11 05:31:07 +00004620template<typename Derived>
4621Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004622TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4624 if (Operand.isInvalid())
4625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004626
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004628 Operand.get() == E->getArgument())
4629 return SemaRef.Owned(E->Retain());
4630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4632 E->isGlobalDelete(),
4633 E->isArrayForm(),
4634 move(Operand));
4635}
Mike Stump11289f42009-09-09 15:08:12 +00004636
Douglas Gregora16548e2009-08-11 05:31:07 +00004637template<typename Derived>
4638Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004639TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004640 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004641 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4642 if (Base.isInvalid())
4643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004644
Douglas Gregorad8a3362009-09-04 17:36:40 +00004645 NestedNameSpecifier *Qualifier
4646 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4647 E->getQualifierRange());
4648 if (E->getQualifier() && !Qualifier)
4649 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregorad8a3362009-09-04 17:36:40 +00004651 QualType DestroyedType;
4652 {
4653 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4654 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4655 if (DestroyedType.isNull())
4656 return SemaRef.ExprError();
4657 }
Mike Stump11289f42009-09-09 15:08:12 +00004658
Douglas Gregorad8a3362009-09-04 17:36:40 +00004659 if (!getDerived().AlwaysRebuild() &&
4660 Base.get() == E->getBase() &&
4661 Qualifier == E->getQualifier() &&
4662 DestroyedType == E->getDestroyedType())
4663 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregorad8a3362009-09-04 17:36:40 +00004665 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4666 E->getOperatorLoc(),
4667 E->isArrow(),
4668 E->getDestroyedTypeLoc(),
4669 DestroyedType,
4670 Qualifier,
4671 E->getQualifierRange());
4672}
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregorad8a3362009-09-04 17:36:40 +00004674template<typename Derived>
4675Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004676TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004677 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004678 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4679
4680 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4681 Sema::LookupOrdinaryName);
4682
4683 // Transform all the decls.
4684 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4685 E = Old->decls_end(); I != E; ++I) {
4686 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004687 if (!InstD) {
4688 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4689 // This can happen because of dependent hiding.
4690 if (isa<UsingShadowDecl>(*I))
4691 continue;
4692 else
4693 return SemaRef.ExprError();
4694 }
John McCalle66edc12009-11-24 19:00:30 +00004695
4696 // Expand using declarations.
4697 if (isa<UsingDecl>(InstD)) {
4698 UsingDecl *UD = cast<UsingDecl>(InstD);
4699 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4700 E = UD->shadow_end(); I != E; ++I)
4701 R.addDecl(*I);
4702 continue;
4703 }
4704
4705 R.addDecl(InstD);
4706 }
4707
4708 // Resolve a kind, but don't do any further analysis. If it's
4709 // ambiguous, the callee needs to deal with it.
4710 R.resolveKind();
4711
4712 // Rebuild the nested-name qualifier, if present.
4713 CXXScopeSpec SS;
4714 NestedNameSpecifier *Qualifier = 0;
4715 if (Old->getQualifier()) {
4716 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4717 Old->getQualifierRange());
4718 if (!Qualifier)
4719 return SemaRef.ExprError();
4720
4721 SS.setScopeRep(Qualifier);
4722 SS.setRange(Old->getQualifierRange());
4723 }
4724
4725 // If we have no template arguments, it's a normal declaration name.
4726 if (!Old->hasExplicitTemplateArgs())
4727 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4728
4729 // If we have template arguments, rebuild them, then rebuild the
4730 // templateid expression.
4731 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4732 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4733 TemplateArgumentLoc Loc;
4734 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4735 return SemaRef.ExprError();
4736 TransArgs.addArgument(Loc);
4737 }
4738
4739 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4740 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004741}
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743template<typename Derived>
4744Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004745TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 QualType T = getDerived().TransformType(E->getQueriedType());
4749 if (T.isNull())
4750 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 if (!getDerived().AlwaysRebuild() &&
4753 T == E->getQueriedType())
4754 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 // FIXME: Bad location information
4757 SourceLocation FakeLParenLoc
4758 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004759
4760 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 E->getLocStart(),
4762 /*FIXME:*/FakeLParenLoc,
4763 T,
4764 E->getLocEnd());
4765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767template<typename Derived>
4768Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004769TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004770 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004771 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004772 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4773 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 if (!NNS)
4775 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004776
4777 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004778 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4779 if (!Name)
4780 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004781
John McCalle66edc12009-11-24 19:00:30 +00004782 if (!E->hasExplicitTemplateArgs()) {
4783 if (!getDerived().AlwaysRebuild() &&
4784 NNS == E->getQualifier() &&
4785 Name == E->getDeclName())
4786 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004787
John McCalle66edc12009-11-24 19:00:30 +00004788 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4789 E->getQualifierRange(),
4790 Name, E->getLocation(),
4791 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004792 }
John McCall6b51f282009-11-23 01:53:49 +00004793
4794 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004796 TemplateArgumentLoc Loc;
4797 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004799 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004800 }
4801
John McCalle66edc12009-11-24 19:00:30 +00004802 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4803 E->getQualifierRange(),
4804 Name, E->getLocation(),
4805 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004806}
4807
4808template<typename Derived>
4809Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004810TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4812
4813 QualType T = getDerived().TransformType(E->getType());
4814 if (T.isNull())
4815 return SemaRef.ExprError();
4816
4817 CXXConstructorDecl *Constructor
4818 = cast_or_null<CXXConstructorDecl>(
4819 getDerived().TransformDecl(E->getConstructor()));
4820 if (!Constructor)
4821 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 bool ArgumentChanged = false;
4824 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004825 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 ArgEnd = E->arg_end();
4827 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004828 if (getDerived().DropCallArgument(*Arg)) {
4829 ArgumentChanged = true;
4830 break;
4831 }
4832
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4834 if (TransArg.isInvalid())
4835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4838 Args.push_back(TransArg.takeAs<Expr>());
4839 }
4840
4841 if (!getDerived().AlwaysRebuild() &&
4842 T == E->getType() &&
4843 Constructor == E->getConstructor() &&
4844 !ArgumentChanged)
4845 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004846
Douglas Gregordb121ba2009-12-14 16:27:04 +00004847 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4848 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 move_arg(Args));
4850}
Mike Stump11289f42009-09-09 15:08:12 +00004851
Douglas Gregora16548e2009-08-11 05:31:07 +00004852/// \brief Transform a C++ temporary-binding expression.
4853///
Douglas Gregor363b1512009-12-24 18:51:59 +00004854/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4855/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004856template<typename Derived>
4857Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004859 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004860}
Mike Stump11289f42009-09-09 15:08:12 +00004861
Anders Carlssonba6c4372010-01-29 02:39:32 +00004862/// \brief Transform a C++ reference-binding expression.
4863///
4864/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4865/// transform the subexpression and return that.
4866template<typename Derived>
4867Sema::OwningExprResult
4868TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4869 return getDerived().TransformExpr(E->getSubExpr());
4870}
4871
Mike Stump11289f42009-09-09 15:08:12 +00004872/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004873/// be destroyed after the expression is evaluated.
4874///
Douglas Gregor363b1512009-12-24 18:51:59 +00004875/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4876/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004877template<typename Derived>
4878Sema::OwningExprResult
4879TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004880 CXXExprWithTemporaries *E) {
4881 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004882}
Mike Stump11289f42009-09-09 15:08:12 +00004883
Douglas Gregora16548e2009-08-11 05:31:07 +00004884template<typename Derived>
4885Sema::OwningExprResult
4886TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004887 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4889 QualType T = getDerived().TransformType(E->getType());
4890 if (T.isNull())
4891 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregora16548e2009-08-11 05:31:07 +00004893 CXXConstructorDecl *Constructor
4894 = cast_or_null<CXXConstructorDecl>(
4895 getDerived().TransformDecl(E->getConstructor()));
4896 if (!Constructor)
4897 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 bool ArgumentChanged = false;
4900 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4901 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004902 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 ArgEnd = E->arg_end();
4904 Arg != ArgEnd; ++Arg) {
4905 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4906 if (TransArg.isInvalid())
4907 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregora16548e2009-08-11 05:31:07 +00004909 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4910 Args.push_back((Expr *)TransArg.release());
4911 }
Mike Stump11289f42009-09-09 15:08:12 +00004912
Douglas Gregora16548e2009-08-11 05:31:07 +00004913 if (!getDerived().AlwaysRebuild() &&
4914 T == E->getType() &&
4915 Constructor == E->getConstructor() &&
4916 !ArgumentChanged)
4917 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004918
Douglas Gregora16548e2009-08-11 05:31:07 +00004919 // FIXME: Bogus location information
4920 SourceLocation CommaLoc;
4921 if (Args.size() > 1) {
4922 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004923 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4925 }
4926 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4927 T,
4928 /*FIXME:*/E->getTypeBeginLoc(),
4929 move_arg(Args),
4930 &CommaLoc,
4931 E->getLocEnd());
4932}
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregora16548e2009-08-11 05:31:07 +00004934template<typename Derived>
4935Sema::OwningExprResult
4936TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004937 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4939 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4940 if (T.isNull())
4941 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 bool ArgumentChanged = false;
4944 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4945 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4946 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4947 ArgEnd = E->arg_end();
4948 Arg != ArgEnd; ++Arg) {
4949 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4950 if (TransArg.isInvalid())
4951 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004952
Douglas Gregora16548e2009-08-11 05:31:07 +00004953 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4954 FakeCommaLocs.push_back(
4955 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4956 Args.push_back(TransArg.takeAs<Expr>());
4957 }
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 if (!getDerived().AlwaysRebuild() &&
4960 T == E->getTypeAsWritten() &&
4961 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004962 return SemaRef.Owned(E->Retain());
4963
Douglas Gregora16548e2009-08-11 05:31:07 +00004964 // FIXME: we're faking the locations of the commas
4965 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4966 T,
4967 E->getLParenLoc(),
4968 move_arg(Args),
4969 FakeCommaLocs.data(),
4970 E->getRParenLoc());
4971}
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973template<typename Derived>
4974Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004975TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004976 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004978 OwningExprResult Base(SemaRef, (Expr*) 0);
4979 Expr *OldBase;
4980 QualType BaseType;
4981 QualType ObjectType;
4982 if (!E->isImplicitAccess()) {
4983 OldBase = E->getBase();
4984 Base = getDerived().TransformExpr(OldBase);
4985 if (Base.isInvalid())
4986 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004987
John McCall2d74de92009-12-01 22:10:20 +00004988 // Start the member reference and compute the object's type.
4989 Sema::TypeTy *ObjectTy = 0;
4990 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4991 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004992 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004993 ObjectTy);
4994 if (Base.isInvalid())
4995 return SemaRef.ExprError();
4996
4997 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4998 BaseType = ((Expr*) Base.get())->getType();
4999 } else {
5000 OldBase = 0;
5001 BaseType = getDerived().TransformType(E->getBaseType());
5002 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5003 }
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005005 // Transform the first part of the nested-name-specifier that qualifies
5006 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005007 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005008 = getDerived().TransformFirstQualifierInScope(
5009 E->getFirstQualifierFoundInScope(),
5010 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005011
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005012 NestedNameSpecifier *Qualifier = 0;
5013 if (E->getQualifier()) {
5014 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5015 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005016 ObjectType,
5017 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005018 if (!Qualifier)
5019 return SemaRef.ExprError();
5020 }
Mike Stump11289f42009-09-09 15:08:12 +00005021
5022 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005023 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005024 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005025 if (!Name)
5026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005027
John McCall2d74de92009-12-01 22:10:20 +00005028 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005029 // This is a reference to a member without an explicitly-specified
5030 // template argument list. Optimize for this common case.
5031 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005032 Base.get() == OldBase &&
5033 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005034 Qualifier == E->getQualifier() &&
5035 Name == E->getMember() &&
5036 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005037 return SemaRef.Owned(E->Retain());
5038
John McCall8cd78132009-11-19 22:55:06 +00005039 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005040 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005041 E->isArrow(),
5042 E->getOperatorLoc(),
5043 Qualifier,
5044 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005045 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005046 Name,
5047 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005048 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005049 }
5050
John McCall6b51f282009-11-23 01:53:49 +00005051 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005052 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005053 TemplateArgumentLoc Loc;
5054 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005055 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005056 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005057 }
Mike Stump11289f42009-09-09 15:08:12 +00005058
John McCall8cd78132009-11-19 22:55:06 +00005059 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005060 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 E->isArrow(),
5062 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005063 Qualifier,
5064 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005065 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005066 Name,
5067 E->getMemberLoc(),
5068 &TransArgs);
5069}
5070
5071template<typename Derived>
5072Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005073TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005074 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005075 OwningExprResult Base(SemaRef, (Expr*) 0);
5076 QualType BaseType;
5077 if (!Old->isImplicitAccess()) {
5078 Base = getDerived().TransformExpr(Old->getBase());
5079 if (Base.isInvalid())
5080 return SemaRef.ExprError();
5081 BaseType = ((Expr*) Base.get())->getType();
5082 } else {
5083 BaseType = getDerived().TransformType(Old->getBaseType());
5084 }
John McCall10eae182009-11-30 22:42:35 +00005085
5086 NestedNameSpecifier *Qualifier = 0;
5087 if (Old->getQualifier()) {
5088 Qualifier
5089 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5090 Old->getQualifierRange());
5091 if (Qualifier == 0)
5092 return SemaRef.ExprError();
5093 }
5094
5095 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5096 Sema::LookupOrdinaryName);
5097
5098 // Transform all the decls.
5099 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5100 E = Old->decls_end(); I != E; ++I) {
5101 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005102 if (!InstD) {
5103 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5104 // This can happen because of dependent hiding.
5105 if (isa<UsingShadowDecl>(*I))
5106 continue;
5107 else
5108 return SemaRef.ExprError();
5109 }
John McCall10eae182009-11-30 22:42:35 +00005110
5111 // Expand using declarations.
5112 if (isa<UsingDecl>(InstD)) {
5113 UsingDecl *UD = cast<UsingDecl>(InstD);
5114 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5115 E = UD->shadow_end(); I != E; ++I)
5116 R.addDecl(*I);
5117 continue;
5118 }
5119
5120 R.addDecl(InstD);
5121 }
5122
5123 R.resolveKind();
5124
5125 TemplateArgumentListInfo TransArgs;
5126 if (Old->hasExplicitTemplateArgs()) {
5127 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5128 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5129 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5130 TemplateArgumentLoc Loc;
5131 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5132 Loc))
5133 return SemaRef.ExprError();
5134 TransArgs.addArgument(Loc);
5135 }
5136 }
John McCall38836f02010-01-15 08:34:02 +00005137
5138 // FIXME: to do this check properly, we will need to preserve the
5139 // first-qualifier-in-scope here, just in case we had a dependent
5140 // base (and therefore couldn't do the check) and a
5141 // nested-name-qualifier (and therefore could do the lookup).
5142 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005143
5144 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005145 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005146 Old->getOperatorLoc(),
5147 Old->isArrow(),
5148 Qualifier,
5149 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005150 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005151 R,
5152 (Old->hasExplicitTemplateArgs()
5153 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005154}
5155
5156template<typename Derived>
5157Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005158TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005159 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005160}
5161
Mike Stump11289f42009-09-09 15:08:12 +00005162template<typename Derived>
5163Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005165 // FIXME: poor source location
5166 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5167 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5168 if (EncodedType.isNull())
5169 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregora16548e2009-08-11 05:31:07 +00005171 if (!getDerived().AlwaysRebuild() &&
5172 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005173 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005174
5175 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5176 EncodedType,
5177 E->getRParenLoc());
5178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregora16548e2009-08-11 05:31:07 +00005180template<typename Derived>
5181Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005182TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 // FIXME: Implement this!
5184 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186}
5187
Mike Stump11289f42009-09-09 15:08:12 +00005188template<typename Derived>
5189Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005190TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005191 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005192}
5193
Mike Stump11289f42009-09-09 15:08:12 +00005194template<typename Derived>
5195Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005196TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005197 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 = cast_or_null<ObjCProtocolDecl>(
5199 getDerived().TransformDecl(E->getProtocol()));
5200 if (!Protocol)
5201 return SemaRef.ExprError();
5202
5203 if (!getDerived().AlwaysRebuild() &&
5204 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005205 return SemaRef.Owned(E->Retain());
5206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 return getDerived().RebuildObjCProtocolExpr(Protocol,
5208 E->getAtLoc(),
5209 /*FIXME:*/E->getAtLoc(),
5210 /*FIXME:*/E->getAtLoc(),
5211 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005212
Douglas Gregora16548e2009-08-11 05:31:07 +00005213}
5214
Mike Stump11289f42009-09-09 15:08:12 +00005215template<typename Derived>
5216Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 // FIXME: Implement this!
5219 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005220 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005221}
5222
Mike Stump11289f42009-09-09 15:08:12 +00005223template<typename Derived>
5224Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005225TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005226 // FIXME: Implement this!
5227 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005228 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005229}
5230
Mike Stump11289f42009-09-09 15:08:12 +00005231template<typename Derived>
5232Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005233TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005234 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005235 // FIXME: Implement this!
5236 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005237 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005238}
5239
Mike Stump11289f42009-09-09 15:08:12 +00005240template<typename Derived>
5241Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005242TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 // FIXME: Implement this!
5244 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005245 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005246}
5247
Mike Stump11289f42009-09-09 15:08:12 +00005248template<typename Derived>
5249Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005250TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005251 // FIXME: Implement this!
5252 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005253 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005254}
5255
Mike Stump11289f42009-09-09 15:08:12 +00005256template<typename Derived>
5257Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005258TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005259 bool ArgumentChanged = false;
5260 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5261 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5262 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5263 if (SubExpr.isInvalid())
5264 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregora16548e2009-08-11 05:31:07 +00005266 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5267 SubExprs.push_back(SubExpr.takeAs<Expr>());
5268 }
Mike Stump11289f42009-09-09 15:08:12 +00005269
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 if (!getDerived().AlwaysRebuild() &&
5271 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005272 return SemaRef.Owned(E->Retain());
5273
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5275 move_arg(SubExprs),
5276 E->getRParenLoc());
5277}
5278
Mike Stump11289f42009-09-09 15:08:12 +00005279template<typename Derived>
5280Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005281TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 // FIXME: Implement this!
5283 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005284 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005285}
5286
Mike Stump11289f42009-09-09 15:08:12 +00005287template<typename Derived>
5288Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005289TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 // FIXME: Implement this!
5291 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005292 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293}
Mike Stump11289f42009-09-09 15:08:12 +00005294
Douglas Gregora16548e2009-08-11 05:31:07 +00005295//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005296// Type reconstruction
5297//===----------------------------------------------------------------------===//
5298
Mike Stump11289f42009-09-09 15:08:12 +00005299template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005300QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5301 SourceLocation Star) {
5302 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005303 getDerived().getBaseEntity());
5304}
5305
Mike Stump11289f42009-09-09 15:08:12 +00005306template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005307QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5308 SourceLocation Star) {
5309 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310 getDerived().getBaseEntity());
5311}
5312
Mike Stump11289f42009-09-09 15:08:12 +00005313template<typename Derived>
5314QualType
John McCall70dd5f62009-10-30 00:06:24 +00005315TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5316 bool WrittenAsLValue,
5317 SourceLocation Sigil) {
5318 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5319 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005320}
5321
5322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005323QualType
John McCall70dd5f62009-10-30 00:06:24 +00005324TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5325 QualType ClassType,
5326 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005327 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005328 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005329}
5330
5331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005332QualType
John McCall70dd5f62009-10-30 00:06:24 +00005333TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5334 SourceLocation Sigil) {
5335 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005336 getDerived().getBaseEntity());
5337}
5338
5339template<typename Derived>
5340QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5342 ArrayType::ArraySizeModifier SizeMod,
5343 const llvm::APInt *Size,
5344 Expr *SizeExpr,
5345 unsigned IndexTypeQuals,
5346 SourceRange BracketsRange) {
5347 if (SizeExpr || !Size)
5348 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5349 IndexTypeQuals, BracketsRange,
5350 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005351
5352 QualType Types[] = {
5353 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5354 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5355 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005356 };
5357 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5358 QualType SizeType;
5359 for (unsigned I = 0; I != NumTypes; ++I)
5360 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5361 SizeType = Types[I];
5362 break;
5363 }
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregord6ff3322009-08-04 16:50:30 +00005365 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005366 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005367 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005368 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005369}
Mike Stump11289f42009-09-09 15:08:12 +00005370
Douglas Gregord6ff3322009-08-04 16:50:30 +00005371template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005372QualType
5373TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005374 ArrayType::ArraySizeModifier SizeMod,
5375 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005376 unsigned IndexTypeQuals,
5377 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005378 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005379 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380}
5381
5382template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005383QualType
Mike Stump11289f42009-09-09 15:08:12 +00005384TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005385 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005386 unsigned IndexTypeQuals,
5387 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005388 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005389 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005390}
Mike Stump11289f42009-09-09 15:08:12 +00005391
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005393QualType
5394TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005395 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005397 unsigned IndexTypeQuals,
5398 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005399 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005400 SizeExpr.takeAs<Expr>(),
5401 IndexTypeQuals, BracketsRange);
5402}
5403
5404template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005405QualType
5406TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005407 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005409 unsigned IndexTypeQuals,
5410 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005411 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005412 SizeExpr.takeAs<Expr>(),
5413 IndexTypeQuals, BracketsRange);
5414}
5415
5416template<typename Derived>
5417QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5418 unsigned NumElements) {
5419 // FIXME: semantic checking!
5420 return SemaRef.Context.getVectorType(ElementType, NumElements);
5421}
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregord6ff3322009-08-04 16:50:30 +00005423template<typename Derived>
5424QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5425 unsigned NumElements,
5426 SourceLocation AttributeLoc) {
5427 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5428 NumElements, true);
5429 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005430 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005431 AttributeLoc);
5432 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5433 AttributeLoc);
5434}
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005437QualType
5438TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005439 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005440 SourceLocation AttributeLoc) {
5441 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5442}
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregord6ff3322009-08-04 16:50:30 +00005444template<typename Derived>
5445QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005446 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005447 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005448 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005449 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005450 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005451 Quals,
5452 getDerived().getBaseLocation(),
5453 getDerived().getBaseEntity());
5454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregord6ff3322009-08-04 16:50:30 +00005456template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005457QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5458 return SemaRef.Context.getFunctionNoProtoType(T);
5459}
5460
5461template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005462QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5463 assert(D && "no decl found");
5464 if (D->isInvalidDecl()) return QualType();
5465
5466 TypeDecl *Ty;
5467 if (isa<UsingDecl>(D)) {
5468 UsingDecl *Using = cast<UsingDecl>(D);
5469 assert(Using->isTypeName() &&
5470 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5471
5472 // A valid resolved using typename decl points to exactly one type decl.
5473 assert(++Using->shadow_begin() == Using->shadow_end());
5474 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5475
5476 } else {
5477 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5478 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5479 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5480 }
5481
5482 return SemaRef.Context.getTypeDeclType(Ty);
5483}
5484
5485template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005486QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005487 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5488}
5489
5490template<typename Derived>
5491QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5492 return SemaRef.Context.getTypeOfType(Underlying);
5493}
5494
5495template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005496QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005497 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5498}
5499
5500template<typename Derived>
5501QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005502 TemplateName Template,
5503 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005504 const TemplateArgumentListInfo &TemplateArgs) {
5505 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005506}
Mike Stump11289f42009-09-09 15:08:12 +00005507
Douglas Gregor1135c352009-08-06 05:28:30 +00005508template<typename Derived>
5509NestedNameSpecifier *
5510TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5511 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005512 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005513 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005514 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005515 CXXScopeSpec SS;
5516 // FIXME: The source location information is all wrong.
5517 SS.setRange(Range);
5518 SS.setScopeRep(Prefix);
5519 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005520 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005521 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005522 ObjectType,
5523 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005524 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005525}
5526
5527template<typename Derived>
5528NestedNameSpecifier *
5529TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5530 SourceRange Range,
5531 NamespaceDecl *NS) {
5532 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5533}
5534
5535template<typename Derived>
5536NestedNameSpecifier *
5537TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5538 SourceRange Range,
5539 bool TemplateKW,
5540 QualType T) {
5541 if (T->isDependentType() || T->isRecordType() ||
5542 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005543 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005544 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5545 T.getTypePtr());
5546 }
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregor1135c352009-08-06 05:28:30 +00005548 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5549 return 0;
5550}
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregor71dc5092009-08-06 06:41:21 +00005552template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005553TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005554TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5555 bool TemplateKW,
5556 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005557 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005558 Template);
5559}
5560
5561template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005562TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005563TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005564 const IdentifierInfo &II,
5565 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005566 CXXScopeSpec SS;
5567 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005568 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005569 UnqualifiedId Name;
5570 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005571 return getSema().ActOnDependentTemplateName(
5572 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005573 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005574 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005575 ObjectType.getAsOpaquePtr(),
5576 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005577 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005578}
Mike Stump11289f42009-09-09 15:08:12 +00005579
Douglas Gregora16548e2009-08-11 05:31:07 +00005580template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005581TemplateName
5582TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5583 OverloadedOperatorKind Operator,
5584 QualType ObjectType) {
5585 CXXScopeSpec SS;
5586 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5587 SS.setScopeRep(Qualifier);
5588 UnqualifiedId Name;
5589 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5590 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5591 Operator, SymbolLocations);
5592 return getSema().ActOnDependentTemplateName(
5593 /*FIXME:*/getDerived().getBaseLocation(),
5594 SS,
5595 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005596 ObjectType.getAsOpaquePtr(),
5597 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005598 .template getAsVal<TemplateName>();
5599}
5600
5601template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005602Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005603TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5604 SourceLocation OpLoc,
5605 ExprArg Callee,
5606 ExprArg First,
5607 ExprArg Second) {
5608 Expr *FirstExpr = (Expr *)First.get();
5609 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005610 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005612
Douglas Gregora16548e2009-08-11 05:31:07 +00005613 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005614 if (Op == OO_Subscript) {
5615 if (!FirstExpr->getType()->isOverloadableType() &&
5616 !SecondExpr->getType()->isOverloadableType())
5617 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005618 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005619 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005620 } else if (Op == OO_Arrow) {
5621 // -> is never a builtin operation.
5622 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005623 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 if (!FirstExpr->getType()->isOverloadableType()) {
5625 // The argument is not of overloadable type, so try to create a
5626 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005627 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005629
Douglas Gregora16548e2009-08-11 05:31:07 +00005630 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5631 }
5632 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005633 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 !SecondExpr->getType()->isOverloadableType()) {
5635 // Neither of the arguments is an overloadable type, so try to
5636 // create a built-in binary operation.
5637 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005638 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5640 if (Result.isInvalid())
5641 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 First.release();
5644 Second.release();
5645 return move(Result);
5646 }
5647 }
Mike Stump11289f42009-09-09 15:08:12 +00005648
5649 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005651 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005652
John McCalld14a8642009-11-21 08:51:07 +00005653 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5654 assert(ULE->requiresADL());
5655
5656 // FIXME: Do we have to check
5657 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005658 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005659 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005660 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 // Add any functions found via argument-dependent lookup.
5664 Expr *Args[2] = { FirstExpr, SecondExpr };
5665 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 // Create the overloaded operator invocation for unary operators.
5668 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005669 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5671 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5672 }
Mike Stump11289f42009-09-09 15:08:12 +00005673
Sebastian Redladba46e2009-10-29 20:17:01 +00005674 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005675 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5676 OpLoc,
5677 move(First),
5678 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005679
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005681 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005683 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5685 if (Result.isInvalid())
5686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005687
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 First.release();
5689 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005690 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005691}
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregord6ff3322009-08-04 16:50:30 +00005693} // end namespace clang
5694
5695#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H