blob: b23a69860b7351c33aab50ee073fa1f80bdd702d [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)
1687#define EXPR(Node, Parent) case Stmt::Node##Class:
1688#include "clang/AST/StmtNodes.def"
1689 {
1690 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1691 if (E.isInvalid())
1692 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001693
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001694 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001695 }
Mike Stump11289f42009-09-09 15:08:12 +00001696 }
1697
Douglas Gregorebe10102009-08-20 07:17:43 +00001698 return SemaRef.Owned(S->Retain());
1699}
Mike Stump11289f42009-09-09 15:08:12 +00001700
1701
Douglas Gregore922c772009-08-04 22:27:00 +00001702template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001703Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 if (!E)
1705 return SemaRef.Owned(E);
1706
1707 switch (E->getStmtClass()) {
1708 case Stmt::NoStmtClass: break;
1709#define STMT(Node, Parent) case Stmt::Node##Class: break;
1710#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001711 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001712#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001713 }
1714
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001716}
1717
1718template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001719NestedNameSpecifier *
1720TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001721 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001722 QualType ObjectType,
1723 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001724 if (!NNS)
1725 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001726
Douglas Gregorebe10102009-08-20 07:17:43 +00001727 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001728 NestedNameSpecifier *Prefix = NNS->getPrefix();
1729 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001730 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001731 ObjectType,
1732 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001733 if (!Prefix)
1734 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001735
1736 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001737 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001738 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001739 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001740 }
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 switch (NNS->getKind()) {
1743 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001744 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001745 "Identifier nested-name-specifier with no prefix or object type");
1746 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1747 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001748 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001749
1750 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001751 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001752 ObjectType,
1753 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001754
Douglas Gregor1135c352009-08-06 05:28:30 +00001755 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001756 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 = cast_or_null<NamespaceDecl>(
1758 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001759 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001760 Prefix == NNS->getPrefix() &&
1761 NS == NNS->getAsNamespace())
1762 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001763
Douglas Gregor1135c352009-08-06 05:28:30 +00001764 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1765 }
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregor1135c352009-08-06 05:28:30 +00001767 case NestedNameSpecifier::Global:
1768 // There is no meaningful transformation that one could perform on the
1769 // global scope.
1770 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001771
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 case NestedNameSpecifier::TypeSpecWithTemplate:
1773 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001774 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001775 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001776 if (T.isNull())
1777 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregor1135c352009-08-06 05:28:30 +00001779 if (!getDerived().AlwaysRebuild() &&
1780 Prefix == NNS->getPrefix() &&
1781 T == QualType(NNS->getAsType(), 0))
1782 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001783
1784 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1785 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001786 T);
1787 }
1788 }
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregor1135c352009-08-06 05:28:30 +00001790 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001791 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001792}
1793
1794template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001795DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001796TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001797 SourceLocation Loc,
1798 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001799 if (!Name)
1800 return Name;
1801
1802 switch (Name.getNameKind()) {
1803 case DeclarationName::Identifier:
1804 case DeclarationName::ObjCZeroArgSelector:
1805 case DeclarationName::ObjCOneArgSelector:
1806 case DeclarationName::ObjCMultiArgSelector:
1807 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001808 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001809 case DeclarationName::CXXUsingDirective:
1810 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregorf816bd72009-09-03 22:13:48 +00001812 case DeclarationName::CXXConstructorName:
1813 case DeclarationName::CXXDestructorName:
1814 case DeclarationName::CXXConversionFunctionName: {
1815 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001816 QualType T;
1817 if (!ObjectType.isNull() &&
1818 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1819 TemplateSpecializationType *SpecType
1820 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1821 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1822 } else
1823 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001824 if (T.isNull())
1825 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001826
Douglas Gregorf816bd72009-09-03 22:13:48 +00001827 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001828 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001829 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001830 }
Mike Stump11289f42009-09-09 15:08:12 +00001831 }
1832
Douglas Gregorf816bd72009-09-03 22:13:48 +00001833 return DeclarationName();
1834}
1835
1836template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001837TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001838TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1839 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001841 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001842 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1843 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1844 if (!NNS)
1845 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001846
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001848 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1850 if (!TransTemplate)
1851 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001852
Douglas Gregor71dc5092009-08-06 06:41:21 +00001853 if (!getDerived().AlwaysRebuild() &&
1854 NNS == QTN->getQualifier() &&
1855 TransTemplate == Template)
1856 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1859 TransTemplate);
1860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
John McCalle66edc12009-11-24 19:00:30 +00001862 // These should be getting filtered out before they make it into the AST.
1863 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 }
Mike Stump11289f42009-09-09 15:08:12 +00001865
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001867 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1869 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001870 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001871 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001872
Douglas Gregor71dc5092009-08-06 06:41:21 +00001873 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001874 NNS == DTN->getQualifier() &&
1875 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001876 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregor71395fa2009-11-04 00:56:37 +00001878 if (DTN->isIdentifier())
1879 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1880 ObjectType);
1881
1882 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1883 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregor71dc5092009-08-06 06:41:21 +00001886 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001887 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001888 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1889 if (!TransTemplate)
1890 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001891
Douglas Gregor71dc5092009-08-06 06:41:21 +00001892 if (!getDerived().AlwaysRebuild() &&
1893 TransTemplate == Template)
1894 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregor71dc5092009-08-06 06:41:21 +00001896 return TemplateName(TransTemplate);
1897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
John McCalle66edc12009-11-24 19:00:30 +00001899 // These should be getting filtered out before they reach the AST.
1900 assert(false && "overloaded function decl survived to here");
1901 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001902}
1903
1904template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001905void TreeTransform<Derived>::InventTemplateArgumentLoc(
1906 const TemplateArgument &Arg,
1907 TemplateArgumentLoc &Output) {
1908 SourceLocation Loc = getDerived().getBaseLocation();
1909 switch (Arg.getKind()) {
1910 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001911 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001912 break;
1913
1914 case TemplateArgument::Type:
1915 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001916 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001917
1918 break;
1919
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001920 case TemplateArgument::Template:
1921 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1922 break;
1923
John McCall0ad16662009-10-29 08:12:44 +00001924 case TemplateArgument::Expression:
1925 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1926 break;
1927
1928 case TemplateArgument::Declaration:
1929 case TemplateArgument::Integral:
1930 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001931 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001932 break;
1933 }
1934}
1935
1936template<typename Derived>
1937bool TreeTransform<Derived>::TransformTemplateArgument(
1938 const TemplateArgumentLoc &Input,
1939 TemplateArgumentLoc &Output) {
1940 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001941 switch (Arg.getKind()) {
1942 case TemplateArgument::Null:
1943 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001944 Output = Input;
1945 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001946
Douglas Gregore922c772009-08-04 22:27:00 +00001947 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001948 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001949 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001950 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001951
1952 DI = getDerived().TransformType(DI);
1953 if (!DI) return true;
1954
1955 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1956 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregore922c772009-08-04 22:27:00 +00001959 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001960 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001961 DeclarationName Name;
1962 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1963 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001964 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001965 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001966 if (!D) return true;
1967
John McCall0d07eb32009-10-29 18:45:58 +00001968 Expr *SourceExpr = Input.getSourceDeclExpression();
1969 if (SourceExpr) {
1970 EnterExpressionEvaluationContext Unevaluated(getSema(),
1971 Action::Unevaluated);
1972 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1973 if (E.isInvalid())
1974 SourceExpr = NULL;
1975 else {
1976 SourceExpr = E.takeAs<Expr>();
1977 SourceExpr->Retain();
1978 }
1979 }
1980
1981 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001982 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001983 }
Mike Stump11289f42009-09-09 15:08:12 +00001984
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001985 case TemplateArgument::Template: {
1986 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1987 TemplateName Template
1988 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1989 if (Template.isNull())
1990 return true;
1991
1992 Output = TemplateArgumentLoc(TemplateArgument(Template),
1993 Input.getTemplateQualifierRange(),
1994 Input.getTemplateNameLoc());
1995 return false;
1996 }
1997
Douglas Gregore922c772009-08-04 22:27:00 +00001998 case TemplateArgument::Expression: {
1999 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002000 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002001 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002002
John McCall0ad16662009-10-29 08:12:44 +00002003 Expr *InputExpr = Input.getSourceExpression();
2004 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2005
2006 Sema::OwningExprResult E
2007 = getDerived().TransformExpr(InputExpr);
2008 if (E.isInvalid()) return true;
2009
2010 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002011 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002012 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2013 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002014 }
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregore922c772009-08-04 22:27:00 +00002016 case TemplateArgument::Pack: {
2017 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2018 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002019 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002020 AEnd = Arg.pack_end();
2021 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002022
John McCall0ad16662009-10-29 08:12:44 +00002023 // FIXME: preserve source information here when we start
2024 // caring about parameter packs.
2025
John McCall0d07eb32009-10-29 18:45:58 +00002026 TemplateArgumentLoc InputArg;
2027 TemplateArgumentLoc OutputArg;
2028 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2029 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002030 return true;
2031
John McCall0d07eb32009-10-29 18:45:58 +00002032 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002033 }
2034 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002035 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002036 true);
John McCall0d07eb32009-10-29 18:45:58 +00002037 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002038 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002039 }
2040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregore922c772009-08-04 22:27:00 +00002042 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002043 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002044}
2045
Douglas Gregord6ff3322009-08-04 16:50:30 +00002046//===----------------------------------------------------------------------===//
2047// Type transformation
2048//===----------------------------------------------------------------------===//
2049
2050template<typename Derived>
2051QualType TreeTransform<Derived>::TransformType(QualType T) {
2052 if (getDerived().AlreadyTransformed(T))
2053 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002054
John McCall550e0c22009-10-21 00:40:46 +00002055 // Temporary workaround. All of these transformations should
2056 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002057 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002058 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002059
John McCallbcd03502009-12-07 02:54:59 +00002060 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002061
John McCall550e0c22009-10-21 00:40:46 +00002062 if (!NewDI)
2063 return QualType();
2064
2065 return NewDI->getType();
2066}
2067
2068template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002069TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002070 if (getDerived().AlreadyTransformed(DI->getType()))
2071 return DI;
2072
2073 TypeLocBuilder TLB;
2074
2075 TypeLoc TL = DI->getTypeLoc();
2076 TLB.reserve(TL.getFullDataSize());
2077
2078 QualType Result = getDerived().TransformType(TLB, TL);
2079 if (Result.isNull())
2080 return 0;
2081
John McCallbcd03502009-12-07 02:54:59 +00002082 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002083}
2084
2085template<typename Derived>
2086QualType
2087TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2088 switch (T.getTypeLocClass()) {
2089#define ABSTRACT_TYPELOC(CLASS, PARENT)
2090#define TYPELOC(CLASS, PARENT) \
2091 case TypeLoc::CLASS: \
2092 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2093#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002096 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002097 return QualType();
2098}
2099
2100/// FIXME: By default, this routine adds type qualifiers only to types
2101/// that can have qualifiers, and silently suppresses those qualifiers
2102/// that are not permitted (e.g., qualifiers on reference or function
2103/// types). This is the right thing for template instantiation, but
2104/// probably not for other clients.
2105template<typename Derived>
2106QualType
2107TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2108 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002109 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002110
2111 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2112 if (Result.isNull())
2113 return QualType();
2114
2115 // Silently suppress qualifiers if the result type can't be qualified.
2116 // FIXME: this is the right thing for template instantiation, but
2117 // probably not for other clients.
2118 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002119 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002120
John McCall550e0c22009-10-21 00:40:46 +00002121 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2122
2123 TLB.push<QualifiedTypeLoc>(Result);
2124
2125 // No location information to preserve.
2126
2127 return Result;
2128}
2129
2130template <class TyLoc> static inline
2131QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2132 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2133 NewT.setNameLoc(T.getNameLoc());
2134 return T.getType();
2135}
2136
2137// Ugly metaprogramming macros because I couldn't be bothered to make
2138// the equivalent template version work.
2139#define TransformPointerLikeType(TypeClass) do { \
2140 QualType PointeeType \
2141 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2142 if (PointeeType.isNull()) \
2143 return QualType(); \
2144 \
2145 QualType Result = TL.getType(); \
2146 if (getDerived().AlwaysRebuild() || \
2147 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002148 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2149 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002150 if (Result.isNull()) \
2151 return QualType(); \
2152 } \
2153 \
2154 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2155 NewT.setSigilLoc(TL.getSigilLoc()); \
2156 \
2157 return Result; \
2158} while(0)
2159
John McCall550e0c22009-10-21 00:40:46 +00002160template<typename Derived>
2161QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2162 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002163 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2164 NewT.setBuiltinLoc(T.getBuiltinLoc());
2165 if (T.needsExtraLocalData())
2166 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2167 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002168}
Mike Stump11289f42009-09-09 15:08:12 +00002169
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002171QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2172 ComplexTypeLoc T) {
2173 // FIXME: recurse?
2174 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002175}
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002178QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2179 PointerTypeLoc TL) {
2180 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002181}
Mike Stump11289f42009-09-09 15:08:12 +00002182
2183template<typename Derived>
2184QualType
John McCall550e0c22009-10-21 00:40:46 +00002185TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2186 BlockPointerTypeLoc TL) {
2187 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002188}
2189
John McCall70dd5f62009-10-30 00:06:24 +00002190/// Transforms a reference type. Note that somewhat paradoxically we
2191/// don't care whether the type itself is an l-value type or an r-value
2192/// type; we only care if the type was *written* as an l-value type
2193/// or an r-value type.
2194template<typename Derived>
2195QualType
2196TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2197 ReferenceTypeLoc TL) {
2198 const ReferenceType *T = TL.getTypePtr();
2199
2200 // Note that this works with the pointee-as-written.
2201 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2202 if (PointeeType.isNull())
2203 return QualType();
2204
2205 QualType Result = TL.getType();
2206 if (getDerived().AlwaysRebuild() ||
2207 PointeeType != T->getPointeeTypeAsWritten()) {
2208 Result = getDerived().RebuildReferenceType(PointeeType,
2209 T->isSpelledAsLValue(),
2210 TL.getSigilLoc());
2211 if (Result.isNull())
2212 return QualType();
2213 }
2214
2215 // r-value references can be rebuilt as l-value references.
2216 ReferenceTypeLoc NewTL;
2217 if (isa<LValueReferenceType>(Result))
2218 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2219 else
2220 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2221 NewTL.setSigilLoc(TL.getSigilLoc());
2222
2223 return Result;
2224}
2225
Mike Stump11289f42009-09-09 15:08:12 +00002226template<typename Derived>
2227QualType
John McCall550e0c22009-10-21 00:40:46 +00002228TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2229 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002230 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002231}
2232
Mike Stump11289f42009-09-09 15:08:12 +00002233template<typename Derived>
2234QualType
John McCall550e0c22009-10-21 00:40:46 +00002235TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2236 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002237 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002238}
Mike Stump11289f42009-09-09 15:08:12 +00002239
Douglas Gregord6ff3322009-08-04 16:50:30 +00002240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002241QualType
John McCall550e0c22009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2243 MemberPointerTypeLoc TL) {
2244 MemberPointerType *T = TL.getTypePtr();
2245
2246 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002247 if (PointeeType.isNull())
2248 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002249
John McCall550e0c22009-10-21 00:40:46 +00002250 // TODO: preserve source information for this.
2251 QualType ClassType
2252 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002253 if (ClassType.isNull())
2254 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002255
John McCall550e0c22009-10-21 00:40:46 +00002256 QualType Result = TL.getType();
2257 if (getDerived().AlwaysRebuild() ||
2258 PointeeType != T->getPointeeType() ||
2259 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002260 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2261 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002262 if (Result.isNull())
2263 return QualType();
2264 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002265
John McCall550e0c22009-10-21 00:40:46 +00002266 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2267 NewTL.setSigilLoc(TL.getSigilLoc());
2268
2269 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002270}
2271
Mike Stump11289f42009-09-09 15:08:12 +00002272template<typename Derived>
2273QualType
John McCall550e0c22009-10-21 00:40:46 +00002274TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2275 ConstantArrayTypeLoc TL) {
2276 ConstantArrayType *T = TL.getTypePtr();
2277 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002278 if (ElementType.isNull())
2279 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002280
John McCall550e0c22009-10-21 00:40:46 +00002281 QualType Result = TL.getType();
2282 if (getDerived().AlwaysRebuild() ||
2283 ElementType != T->getElementType()) {
2284 Result = getDerived().RebuildConstantArrayType(ElementType,
2285 T->getSizeModifier(),
2286 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002287 T->getIndexTypeCVRQualifiers(),
2288 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002289 if (Result.isNull())
2290 return QualType();
2291 }
2292
2293 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2294 NewTL.setLBracketLoc(TL.getLBracketLoc());
2295 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002296
John McCall550e0c22009-10-21 00:40:46 +00002297 Expr *Size = TL.getSizeExpr();
2298 if (Size) {
2299 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2300 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2301 }
2302 NewTL.setSizeExpr(Size);
2303
2304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002305}
Mike Stump11289f42009-09-09 15:08:12 +00002306
Douglas Gregord6ff3322009-08-04 16:50:30 +00002307template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002308QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002309 TypeLocBuilder &TLB,
2310 IncompleteArrayTypeLoc TL) {
2311 IncompleteArrayType *T = TL.getTypePtr();
2312 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002313 if (ElementType.isNull())
2314 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002315
John McCall550e0c22009-10-21 00:40:46 +00002316 QualType Result = TL.getType();
2317 if (getDerived().AlwaysRebuild() ||
2318 ElementType != T->getElementType()) {
2319 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002320 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002321 T->getIndexTypeCVRQualifiers(),
2322 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002323 if (Result.isNull())
2324 return QualType();
2325 }
2326
2327 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2328 NewTL.setLBracketLoc(TL.getLBracketLoc());
2329 NewTL.setRBracketLoc(TL.getRBracketLoc());
2330 NewTL.setSizeExpr(0);
2331
2332 return Result;
2333}
2334
2335template<typename Derived>
2336QualType
2337TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2338 VariableArrayTypeLoc TL) {
2339 VariableArrayType *T = TL.getTypePtr();
2340 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2341 if (ElementType.isNull())
2342 return QualType();
2343
2344 // Array bounds are not potentially evaluated contexts
2345 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2346
2347 Sema::OwningExprResult SizeResult
2348 = getDerived().TransformExpr(T->getSizeExpr());
2349 if (SizeResult.isInvalid())
2350 return QualType();
2351
2352 Expr *Size = static_cast<Expr*>(SizeResult.get());
2353
2354 QualType Result = TL.getType();
2355 if (getDerived().AlwaysRebuild() ||
2356 ElementType != T->getElementType() ||
2357 Size != T->getSizeExpr()) {
2358 Result = getDerived().RebuildVariableArrayType(ElementType,
2359 T->getSizeModifier(),
2360 move(SizeResult),
2361 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002362 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002363 if (Result.isNull())
2364 return QualType();
2365 }
2366 else SizeResult.take();
2367
2368 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2369 NewTL.setLBracketLoc(TL.getLBracketLoc());
2370 NewTL.setRBracketLoc(TL.getRBracketLoc());
2371 NewTL.setSizeExpr(Size);
2372
2373 return Result;
2374}
2375
2376template<typename Derived>
2377QualType
2378TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2379 DependentSizedArrayTypeLoc TL) {
2380 DependentSizedArrayType *T = TL.getTypePtr();
2381 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2382 if (ElementType.isNull())
2383 return QualType();
2384
2385 // Array bounds are not potentially evaluated contexts
2386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2387
2388 Sema::OwningExprResult SizeResult
2389 = getDerived().TransformExpr(T->getSizeExpr());
2390 if (SizeResult.isInvalid())
2391 return QualType();
2392
2393 Expr *Size = static_cast<Expr*>(SizeResult.get());
2394
2395 QualType Result = TL.getType();
2396 if (getDerived().AlwaysRebuild() ||
2397 ElementType != T->getElementType() ||
2398 Size != T->getSizeExpr()) {
2399 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2400 T->getSizeModifier(),
2401 move(SizeResult),
2402 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002403 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002404 if (Result.isNull())
2405 return QualType();
2406 }
2407 else SizeResult.take();
2408
2409 // We might have any sort of array type now, but fortunately they
2410 // all have the same location layout.
2411 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2412 NewTL.setLBracketLoc(TL.getLBracketLoc());
2413 NewTL.setRBracketLoc(TL.getRBracketLoc());
2414 NewTL.setSizeExpr(Size);
2415
2416 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002417}
Mike Stump11289f42009-09-09 15:08:12 +00002418
2419template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002421 TypeLocBuilder &TLB,
2422 DependentSizedExtVectorTypeLoc TL) {
2423 DependentSizedExtVectorType *T = TL.getTypePtr();
2424
2425 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002426 QualType ElementType = getDerived().TransformType(T->getElementType());
2427 if (ElementType.isNull())
2428 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002429
Douglas Gregore922c772009-08-04 22:27:00 +00002430 // Vector sizes are not potentially evaluated contexts
2431 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2432
Douglas Gregord6ff3322009-08-04 16:50:30 +00002433 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2434 if (Size.isInvalid())
2435 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002436
John McCall550e0c22009-10-21 00:40:46 +00002437 QualType Result = TL.getType();
2438 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002439 ElementType != T->getElementType() ||
2440 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002441 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002442 move(Size),
2443 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002444 if (Result.isNull())
2445 return QualType();
2446 }
2447 else Size.take();
2448
2449 // Result might be dependent or not.
2450 if (isa<DependentSizedExtVectorType>(Result)) {
2451 DependentSizedExtVectorTypeLoc NewTL
2452 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2453 NewTL.setNameLoc(TL.getNameLoc());
2454 } else {
2455 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2456 NewTL.setNameLoc(TL.getNameLoc());
2457 }
2458
2459 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002460}
Mike Stump11289f42009-09-09 15:08:12 +00002461
2462template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002463QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2464 VectorTypeLoc TL) {
2465 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466 QualType ElementType = getDerived().TransformType(T->getElementType());
2467 if (ElementType.isNull())
2468 return QualType();
2469
John McCall550e0c22009-10-21 00:40:46 +00002470 QualType Result = TL.getType();
2471 if (getDerived().AlwaysRebuild() ||
2472 ElementType != T->getElementType()) {
2473 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2474 if (Result.isNull())
2475 return QualType();
2476 }
2477
2478 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2479 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002480
John McCall550e0c22009-10-21 00:40:46 +00002481 return Result;
2482}
2483
2484template<typename Derived>
2485QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2486 ExtVectorTypeLoc TL) {
2487 VectorType *T = TL.getTypePtr();
2488 QualType ElementType = getDerived().TransformType(T->getElementType());
2489 if (ElementType.isNull())
2490 return QualType();
2491
2492 QualType Result = TL.getType();
2493 if (getDerived().AlwaysRebuild() ||
2494 ElementType != T->getElementType()) {
2495 Result = getDerived().RebuildExtVectorType(ElementType,
2496 T->getNumElements(),
2497 /*FIXME*/ SourceLocation());
2498 if (Result.isNull())
2499 return QualType();
2500 }
2501
2502 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2503 NewTL.setNameLoc(TL.getNameLoc());
2504
2505 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002506}
Mike Stump11289f42009-09-09 15:08:12 +00002507
2508template<typename Derived>
2509QualType
John McCall550e0c22009-10-21 00:40:46 +00002510TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2511 FunctionProtoTypeLoc TL) {
2512 FunctionProtoType *T = TL.getTypePtr();
2513 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002514 if (ResultType.isNull())
2515 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002516
John McCall550e0c22009-10-21 00:40:46 +00002517 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002518 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002519 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2520 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2521 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002522
John McCall550e0c22009-10-21 00:40:46 +00002523 QualType NewType;
2524 ParmVarDecl *NewParm;
2525
2526 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002527 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002528 assert(OldDI->getType() == T->getArgType(i));
2529
John McCallbcd03502009-12-07 02:54:59 +00002530 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002531 if (!NewDI)
2532 return QualType();
2533
2534 if (NewDI == OldDI)
2535 NewParm = OldParm;
2536 else
2537 NewParm = ParmVarDecl::Create(SemaRef.Context,
2538 OldParm->getDeclContext(),
2539 OldParm->getLocation(),
2540 OldParm->getIdentifier(),
2541 NewDI->getType(),
2542 NewDI,
2543 OldParm->getStorageClass(),
2544 /* DefArg */ NULL);
2545 NewType = NewParm->getType();
2546
2547 // Deal with the possibility that we don't have a parameter
2548 // declaration for this parameter.
2549 } else {
2550 NewParm = 0;
2551
2552 QualType OldType = T->getArgType(i);
2553 NewType = getDerived().TransformType(OldType);
2554 if (NewType.isNull())
2555 return QualType();
2556 }
2557
2558 ParamTypes.push_back(NewType);
2559 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002560 }
Mike Stump11289f42009-09-09 15:08:12 +00002561
John McCall550e0c22009-10-21 00:40:46 +00002562 QualType Result = TL.getType();
2563 if (getDerived().AlwaysRebuild() ||
2564 ResultType != T->getResultType() ||
2565 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2566 Result = getDerived().RebuildFunctionProtoType(ResultType,
2567 ParamTypes.data(),
2568 ParamTypes.size(),
2569 T->isVariadic(),
2570 T->getTypeQuals());
2571 if (Result.isNull())
2572 return QualType();
2573 }
Mike Stump11289f42009-09-09 15:08:12 +00002574
John McCall550e0c22009-10-21 00:40:46 +00002575 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2576 NewTL.setLParenLoc(TL.getLParenLoc());
2577 NewTL.setRParenLoc(TL.getRParenLoc());
2578 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2579 NewTL.setArg(i, ParamDecls[i]);
2580
2581 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002582}
Mike Stump11289f42009-09-09 15:08:12 +00002583
Douglas Gregord6ff3322009-08-04 16:50:30 +00002584template<typename Derived>
2585QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002586 TypeLocBuilder &TLB,
2587 FunctionNoProtoTypeLoc TL) {
2588 FunctionNoProtoType *T = TL.getTypePtr();
2589 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2590 if (ResultType.isNull())
2591 return QualType();
2592
2593 QualType Result = TL.getType();
2594 if (getDerived().AlwaysRebuild() ||
2595 ResultType != T->getResultType())
2596 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2597
2598 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2599 NewTL.setLParenLoc(TL.getLParenLoc());
2600 NewTL.setRParenLoc(TL.getRParenLoc());
2601
2602 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002603}
Mike Stump11289f42009-09-09 15:08:12 +00002604
John McCallb96ec562009-12-04 22:46:56 +00002605template<typename Derived> QualType
2606TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2607 UnresolvedUsingTypeLoc TL) {
2608 UnresolvedUsingType *T = TL.getTypePtr();
2609 Decl *D = getDerived().TransformDecl(T->getDecl());
2610 if (!D)
2611 return QualType();
2612
2613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2615 Result = getDerived().RebuildUnresolvedUsingType(D);
2616 if (Result.isNull())
2617 return QualType();
2618 }
2619
2620 // We might get an arbitrary type spec type back. We should at
2621 // least always get a type spec type, though.
2622 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2623 NewTL.setNameLoc(TL.getNameLoc());
2624
2625 return Result;
2626}
2627
Douglas Gregord6ff3322009-08-04 16:50:30 +00002628template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002629QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2630 TypedefTypeLoc TL) {
2631 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632 TypedefDecl *Typedef
2633 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2634 if (!Typedef)
2635 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002636
John McCall550e0c22009-10-21 00:40:46 +00002637 QualType Result = TL.getType();
2638 if (getDerived().AlwaysRebuild() ||
2639 Typedef != T->getDecl()) {
2640 Result = getDerived().RebuildTypedefType(Typedef);
2641 if (Result.isNull())
2642 return QualType();
2643 }
Mike Stump11289f42009-09-09 15:08:12 +00002644
John McCall550e0c22009-10-21 00:40:46 +00002645 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2646 NewTL.setNameLoc(TL.getNameLoc());
2647
2648 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649}
Mike Stump11289f42009-09-09 15:08:12 +00002650
Douglas Gregord6ff3322009-08-04 16:50:30 +00002651template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002652QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2653 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00002654 // typeof expressions are not potentially evaluated contexts
2655 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002656
John McCalle8595032010-01-13 20:03:27 +00002657 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002658 if (E.isInvalid())
2659 return QualType();
2660
John McCall550e0c22009-10-21 00:40:46 +00002661 QualType Result = TL.getType();
2662 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002663 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002664 Result = getDerived().RebuildTypeOfExprType(move(E));
2665 if (Result.isNull())
2666 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002667 }
John McCall550e0c22009-10-21 00:40:46 +00002668 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002669
John McCall550e0c22009-10-21 00:40:46 +00002670 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002671 NewTL.setTypeofLoc(TL.getTypeofLoc());
2672 NewTL.setLParenLoc(TL.getLParenLoc());
2673 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002674
2675 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002676}
Mike Stump11289f42009-09-09 15:08:12 +00002677
2678template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002679QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2680 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002681 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2682 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2683 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002684 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002685
John McCall550e0c22009-10-21 00:40:46 +00002686 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002687 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2688 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002689 if (Result.isNull())
2690 return QualType();
2691 }
Mike Stump11289f42009-09-09 15:08:12 +00002692
John McCall550e0c22009-10-21 00:40:46 +00002693 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002694 NewTL.setTypeofLoc(TL.getTypeofLoc());
2695 NewTL.setLParenLoc(TL.getLParenLoc());
2696 NewTL.setRParenLoc(TL.getRParenLoc());
2697 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002698
2699 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002700}
Mike Stump11289f42009-09-09 15:08:12 +00002701
2702template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002703QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2704 DecltypeTypeLoc TL) {
2705 DecltypeType *T = TL.getTypePtr();
2706
Douglas Gregore922c772009-08-04 22:27:00 +00002707 // decltype expressions are not potentially evaluated contexts
2708 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002709
Douglas Gregord6ff3322009-08-04 16:50:30 +00002710 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2711 if (E.isInvalid())
2712 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002713
John McCall550e0c22009-10-21 00:40:46 +00002714 QualType Result = TL.getType();
2715 if (getDerived().AlwaysRebuild() ||
2716 E.get() != T->getUnderlyingExpr()) {
2717 Result = getDerived().RebuildDecltypeType(move(E));
2718 if (Result.isNull())
2719 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002720 }
John McCall550e0c22009-10-21 00:40:46 +00002721 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002722
John McCall550e0c22009-10-21 00:40:46 +00002723 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2724 NewTL.setNameLoc(TL.getNameLoc());
2725
2726 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002727}
2728
2729template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002730QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2731 RecordTypeLoc TL) {
2732 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002733 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002734 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002735 if (!Record)
2736 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002737
John McCall550e0c22009-10-21 00:40:46 +00002738 QualType Result = TL.getType();
2739 if (getDerived().AlwaysRebuild() ||
2740 Record != T->getDecl()) {
2741 Result = getDerived().RebuildRecordType(Record);
2742 if (Result.isNull())
2743 return QualType();
2744 }
Mike Stump11289f42009-09-09 15:08:12 +00002745
John McCall550e0c22009-10-21 00:40:46 +00002746 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2747 NewTL.setNameLoc(TL.getNameLoc());
2748
2749 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750}
Mike Stump11289f42009-09-09 15:08:12 +00002751
2752template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002753QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2754 EnumTypeLoc TL) {
2755 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002757 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758 if (!Enum)
2759 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002760
John McCall550e0c22009-10-21 00:40:46 +00002761 QualType Result = TL.getType();
2762 if (getDerived().AlwaysRebuild() ||
2763 Enum != T->getDecl()) {
2764 Result = getDerived().RebuildEnumType(Enum);
2765 if (Result.isNull())
2766 return QualType();
2767 }
Mike Stump11289f42009-09-09 15:08:12 +00002768
John McCall550e0c22009-10-21 00:40:46 +00002769 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2770 NewTL.setNameLoc(TL.getNameLoc());
2771
2772 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002773}
John McCallfcc33b02009-09-05 00:15:47 +00002774
2775template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002776QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2777 ElaboratedTypeLoc TL) {
2778 ElaboratedType *T = TL.getTypePtr();
2779
2780 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002781 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2782 if (Underlying.isNull())
2783 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002784
John McCall550e0c22009-10-21 00:40:46 +00002785 QualType Result = TL.getType();
2786 if (getDerived().AlwaysRebuild() ||
2787 Underlying != T->getUnderlyingType()) {
2788 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2789 if (Result.isNull())
2790 return QualType();
2791 }
Mike Stump11289f42009-09-09 15:08:12 +00002792
John McCall550e0c22009-10-21 00:40:46 +00002793 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2794 NewTL.setNameLoc(TL.getNameLoc());
2795
2796 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002797}
Mike Stump11289f42009-09-09 15:08:12 +00002798
2799
Douglas Gregord6ff3322009-08-04 16:50:30 +00002800template<typename Derived>
2801QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002802 TypeLocBuilder &TLB,
2803 TemplateTypeParmTypeLoc TL) {
2804 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002805}
2806
Mike Stump11289f42009-09-09 15:08:12 +00002807template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002808QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002809 TypeLocBuilder &TLB,
2810 SubstTemplateTypeParmTypeLoc TL) {
2811 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002812}
2813
2814template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002815inline QualType
2816TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002817 TypeLocBuilder &TLB,
2818 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002819 return TransformTemplateSpecializationType(TLB, TL, QualType());
2820}
John McCall550e0c22009-10-21 00:40:46 +00002821
John McCall0ad16662009-10-29 08:12:44 +00002822template<typename Derived>
2823QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2824 const TemplateSpecializationType *TST,
2825 QualType ObjectType) {
2826 // FIXME: this entire method is a temporary workaround; callers
2827 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002828
John McCall0ad16662009-10-29 08:12:44 +00002829 // Fake up a TemplateSpecializationTypeLoc.
2830 TypeLocBuilder TLB;
2831 TemplateSpecializationTypeLoc TL
2832 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2833
John McCall0d07eb32009-10-29 18:45:58 +00002834 SourceLocation BaseLoc = getDerived().getBaseLocation();
2835
2836 TL.setTemplateNameLoc(BaseLoc);
2837 TL.setLAngleLoc(BaseLoc);
2838 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002839 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2840 const TemplateArgument &TA = TST->getArg(i);
2841 TemplateArgumentLoc TAL;
2842 getDerived().InventTemplateArgumentLoc(TA, TAL);
2843 TL.setArgLocInfo(i, TAL.getLocInfo());
2844 }
2845
2846 TypeLocBuilder IgnoredTLB;
2847 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002848}
2849
2850template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002851QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002852 TypeLocBuilder &TLB,
2853 TemplateSpecializationTypeLoc TL,
2854 QualType ObjectType) {
2855 const TemplateSpecializationType *T = TL.getTypePtr();
2856
Mike Stump11289f42009-09-09 15:08:12 +00002857 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002858 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002859 if (Template.isNull())
2860 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002861
John McCall6b51f282009-11-23 01:53:49 +00002862 TemplateArgumentListInfo NewTemplateArgs;
2863 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2864 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2865
2866 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2867 TemplateArgumentLoc Loc;
2868 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002870 NewTemplateArgs.addArgument(Loc);
2871 }
Mike Stump11289f42009-09-09 15:08:12 +00002872
John McCall0ad16662009-10-29 08:12:44 +00002873 // FIXME: maybe don't rebuild if all the template arguments are the same.
2874
2875 QualType Result =
2876 getDerived().RebuildTemplateSpecializationType(Template,
2877 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002878 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002879
2880 if (!Result.isNull()) {
2881 TemplateSpecializationTypeLoc NewTL
2882 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2883 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2884 NewTL.setLAngleLoc(TL.getLAngleLoc());
2885 NewTL.setRAngleLoc(TL.getRAngleLoc());
2886 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2887 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002888 }
Mike Stump11289f42009-09-09 15:08:12 +00002889
John McCall0ad16662009-10-29 08:12:44 +00002890 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002891}
Mike Stump11289f42009-09-09 15:08:12 +00002892
2893template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002894QualType
2895TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2896 QualifiedNameTypeLoc TL) {
2897 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002898 NestedNameSpecifier *NNS
2899 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2900 SourceRange());
2901 if (!NNS)
2902 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002903
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904 QualType Named = getDerived().TransformType(T->getNamedType());
2905 if (Named.isNull())
2906 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002907
John McCall550e0c22009-10-21 00:40:46 +00002908 QualType Result = TL.getType();
2909 if (getDerived().AlwaysRebuild() ||
2910 NNS != T->getQualifier() ||
2911 Named != T->getNamedType()) {
2912 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2913 if (Result.isNull())
2914 return QualType();
2915 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916
John McCall550e0c22009-10-21 00:40:46 +00002917 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2918 NewTL.setNameLoc(TL.getNameLoc());
2919
2920 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002921}
Mike Stump11289f42009-09-09 15:08:12 +00002922
2923template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002924QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2925 TypenameTypeLoc TL) {
2926 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002927
2928 /* FIXME: preserve source information better than this */
2929 SourceRange SR(TL.getNameLoc());
2930
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002932 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933 if (!NNS)
2934 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002935
John McCall550e0c22009-10-21 00:40:46 +00002936 QualType Result;
2937
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002939 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940 = getDerived().TransformType(QualType(TemplateId, 0));
2941 if (NewTemplateId.isNull())
2942 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002943
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944 if (!getDerived().AlwaysRebuild() &&
2945 NNS == T->getQualifier() &&
2946 NewTemplateId == QualType(TemplateId, 0))
2947 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002948
John McCall550e0c22009-10-21 00:40:46 +00002949 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2950 } else {
John McCall0ad16662009-10-29 08:12:44 +00002951 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952 }
John McCall550e0c22009-10-21 00:40:46 +00002953 if (Result.isNull())
2954 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002955
John McCall550e0c22009-10-21 00:40:46 +00002956 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2957 NewTL.setNameLoc(TL.getNameLoc());
2958
2959 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002960}
Mike Stump11289f42009-09-09 15:08:12 +00002961
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002963QualType
2964TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2965 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002966 assert(false && "TransformObjCInterfaceType unimplemented");
2967 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002968}
Mike Stump11289f42009-09-09 15:08:12 +00002969
2970template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002971QualType
2972TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2973 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002974 assert(false && "TransformObjCObjectPointerType unimplemented");
2975 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002976}
2977
Douglas Gregord6ff3322009-08-04 16:50:30 +00002978//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002979// Statement transformation
2980//===----------------------------------------------------------------------===//
2981template<typename Derived>
2982Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002983TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2984 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002985}
2986
2987template<typename Derived>
2988Sema::OwningStmtResult
2989TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2990 return getDerived().TransformCompoundStmt(S, false);
2991}
2992
2993template<typename Derived>
2994Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002995TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002996 bool IsStmtExpr) {
2997 bool SubStmtChanged = false;
2998 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2999 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3000 B != BEnd; ++B) {
3001 OwningStmtResult Result = getDerived().TransformStmt(*B);
3002 if (Result.isInvalid())
3003 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003004
Douglas Gregorebe10102009-08-20 07:17:43 +00003005 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3006 Statements.push_back(Result.takeAs<Stmt>());
3007 }
Mike Stump11289f42009-09-09 15:08:12 +00003008
Douglas Gregorebe10102009-08-20 07:17:43 +00003009 if (!getDerived().AlwaysRebuild() &&
3010 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003011 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003012
3013 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3014 move_arg(Statements),
3015 S->getRBracLoc(),
3016 IsStmtExpr);
3017}
Mike Stump11289f42009-09-09 15:08:12 +00003018
Douglas Gregorebe10102009-08-20 07:17:43 +00003019template<typename Derived>
3020Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003021TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003022 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3023 {
3024 // The case value expressions are not potentially evaluated.
3025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003026
Eli Friedman06577382009-11-19 03:14:00 +00003027 // Transform the left-hand case value.
3028 LHS = getDerived().TransformExpr(S->getLHS());
3029 if (LHS.isInvalid())
3030 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003031
Eli Friedman06577382009-11-19 03:14:00 +00003032 // Transform the right-hand case value (for the GNU case-range extension).
3033 RHS = getDerived().TransformExpr(S->getRHS());
3034 if (RHS.isInvalid())
3035 return SemaRef.StmtError();
3036 }
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregorebe10102009-08-20 07:17:43 +00003038 // Build the case statement.
3039 // Case statements are always rebuilt so that they will attached to their
3040 // transformed switch statement.
3041 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3042 move(LHS),
3043 S->getEllipsisLoc(),
3044 move(RHS),
3045 S->getColonLoc());
3046 if (Case.isInvalid())
3047 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregorebe10102009-08-20 07:17:43 +00003049 // Transform the statement following the case
3050 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3051 if (SubStmt.isInvalid())
3052 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003053
Douglas Gregorebe10102009-08-20 07:17:43 +00003054 // Attach the body to the case statement
3055 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3056}
3057
3058template<typename Derived>
3059Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003060TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003061 // Transform the statement following the default case
3062 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3063 if (SubStmt.isInvalid())
3064 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003065
Douglas Gregorebe10102009-08-20 07:17:43 +00003066 // Default statements are always rebuilt
3067 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3068 move(SubStmt));
3069}
Mike Stump11289f42009-09-09 15:08:12 +00003070
Douglas Gregorebe10102009-08-20 07:17:43 +00003071template<typename Derived>
3072Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003073TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003074 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3075 if (SubStmt.isInvalid())
3076 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003077
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 // FIXME: Pass the real colon location in.
3079 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3080 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3081 move(SubStmt));
3082}
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003085Sema::OwningStmtResult
3086TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003087 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003088 OwningExprResult Cond(SemaRef);
3089 VarDecl *ConditionVar = 0;
3090 if (S->getConditionVariable()) {
3091 ConditionVar
3092 = cast_or_null<VarDecl>(
3093 getDerived().TransformDefinition(S->getConditionVariable()));
3094 if (!ConditionVar)
3095 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003096 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003097 Cond = getDerived().TransformExpr(S->getCond());
3098
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003099 if (Cond.isInvalid())
3100 return SemaRef.StmtError();
3101 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003102
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003103 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003104
Douglas Gregorebe10102009-08-20 07:17:43 +00003105 // Transform the "then" branch.
3106 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3107 if (Then.isInvalid())
3108 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003109
Douglas Gregorebe10102009-08-20 07:17:43 +00003110 // Transform the "else" branch.
3111 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3112 if (Else.isInvalid())
3113 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003114
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 if (!getDerived().AlwaysRebuild() &&
3116 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003117 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003118 Then.get() == S->getThen() &&
3119 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003120 return SemaRef.Owned(S->Retain());
3121
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003122 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3123 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003124 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003125}
3126
3127template<typename Derived>
3128Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003129TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003130 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003131 OwningExprResult Cond(SemaRef);
3132 VarDecl *ConditionVar = 0;
3133 if (S->getConditionVariable()) {
3134 ConditionVar
3135 = cast_or_null<VarDecl>(
3136 getDerived().TransformDefinition(S->getConditionVariable()));
3137 if (!ConditionVar)
3138 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003139 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003140 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003141
3142 if (Cond.isInvalid())
3143 return SemaRef.StmtError();
3144 }
Mike Stump11289f42009-09-09 15:08:12 +00003145
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003146 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003147
Douglas Gregorebe10102009-08-20 07:17:43 +00003148 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003149 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3150 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 if (Switch.isInvalid())
3152 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003153
Douglas Gregorebe10102009-08-20 07:17:43 +00003154 // Transform the body of the switch statement.
3155 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3156 if (Body.isInvalid())
3157 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 // Complete the switch statement.
3160 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3161 move(Body));
3162}
Mike Stump11289f42009-09-09 15:08:12 +00003163
Douglas Gregorebe10102009-08-20 07:17:43 +00003164template<typename Derived>
3165Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003166TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003167 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003168 OwningExprResult Cond(SemaRef);
3169 VarDecl *ConditionVar = 0;
3170 if (S->getConditionVariable()) {
3171 ConditionVar
3172 = cast_or_null<VarDecl>(
3173 getDerived().TransformDefinition(S->getConditionVariable()));
3174 if (!ConditionVar)
3175 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003176 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003177 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003178
3179 if (Cond.isInvalid())
3180 return SemaRef.StmtError();
3181 }
Mike Stump11289f42009-09-09 15:08:12 +00003182
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003183 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003184
Douglas Gregorebe10102009-08-20 07:17:43 +00003185 // Transform the body
3186 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3187 if (Body.isInvalid())
3188 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003189
Douglas Gregorebe10102009-08-20 07:17:43 +00003190 if (!getDerived().AlwaysRebuild() &&
3191 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003192 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003193 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003194 return SemaRef.Owned(S->Retain());
3195
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003196 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3197 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003198}
Mike Stump11289f42009-09-09 15:08:12 +00003199
Douglas Gregorebe10102009-08-20 07:17:43 +00003200template<typename Derived>
3201Sema::OwningStmtResult
3202TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3203 // Transform the condition
3204 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3205 if (Cond.isInvalid())
3206 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003207
Douglas Gregorebe10102009-08-20 07:17:43 +00003208 // Transform the body
3209 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3210 if (Body.isInvalid())
3211 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregorebe10102009-08-20 07:17:43 +00003213 if (!getDerived().AlwaysRebuild() &&
3214 Cond.get() == S->getCond() &&
3215 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003216 return SemaRef.Owned(S->Retain());
3217
Douglas Gregorebe10102009-08-20 07:17:43 +00003218 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3219 /*FIXME:*/S->getWhileLoc(), move(Cond),
3220 S->getRParenLoc());
3221}
Mike Stump11289f42009-09-09 15:08:12 +00003222
Douglas Gregorebe10102009-08-20 07:17:43 +00003223template<typename Derived>
3224Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003225TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003226 // Transform the initialization statement
3227 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3228 if (Init.isInvalid())
3229 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003230
Douglas Gregorebe10102009-08-20 07:17:43 +00003231 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003232 OwningExprResult Cond(SemaRef);
3233 VarDecl *ConditionVar = 0;
3234 if (S->getConditionVariable()) {
3235 ConditionVar
3236 = cast_or_null<VarDecl>(
3237 getDerived().TransformDefinition(S->getConditionVariable()));
3238 if (!ConditionVar)
3239 return SemaRef.StmtError();
3240 } else {
3241 Cond = getDerived().TransformExpr(S->getCond());
3242
3243 if (Cond.isInvalid())
3244 return SemaRef.StmtError();
3245 }
Mike Stump11289f42009-09-09 15:08:12 +00003246
Douglas Gregorebe10102009-08-20 07:17:43 +00003247 // Transform the increment
3248 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3249 if (Inc.isInvalid())
3250 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregorebe10102009-08-20 07:17:43 +00003252 // Transform the body
3253 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3254 if (Body.isInvalid())
3255 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003256
Douglas Gregorebe10102009-08-20 07:17:43 +00003257 if (!getDerived().AlwaysRebuild() &&
3258 Init.get() == S->getInit() &&
3259 Cond.get() == S->getCond() &&
3260 Inc.get() == S->getInc() &&
3261 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003262 return SemaRef.Owned(S->Retain());
3263
Douglas Gregorebe10102009-08-20 07:17:43 +00003264 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003265 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003266 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003267 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 S->getRParenLoc(), move(Body));
3269}
3270
3271template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003272Sema::OwningStmtResult
3273TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003274 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003275 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 S->getLabel());
3277}
3278
3279template<typename Derived>
3280Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003281TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003282 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3283 if (Target.isInvalid())
3284 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregorebe10102009-08-20 07:17:43 +00003286 if (!getDerived().AlwaysRebuild() &&
3287 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003288 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003289
3290 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3291 move(Target));
3292}
3293
3294template<typename Derived>
3295Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003296TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3297 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
Douglas Gregorebe10102009-08-20 07:17:43 +00003300template<typename Derived>
3301Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003302TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3303 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003304}
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregorebe10102009-08-20 07:17:43 +00003306template<typename Derived>
3307Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003308TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3310 if (Result.isInvalid())
3311 return SemaRef.StmtError();
3312
Mike Stump11289f42009-09-09 15:08:12 +00003313 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003314 // to tell whether the return type of the function has changed.
3315 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3316}
Mike Stump11289f42009-09-09 15:08:12 +00003317
Douglas Gregorebe10102009-08-20 07:17:43 +00003318template<typename Derived>
3319Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003320TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003321 bool DeclChanged = false;
3322 llvm::SmallVector<Decl *, 4> Decls;
3323 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3324 D != DEnd; ++D) {
3325 Decl *Transformed = getDerived().TransformDefinition(*D);
3326 if (!Transformed)
3327 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003328
Douglas Gregorebe10102009-08-20 07:17:43 +00003329 if (Transformed != *D)
3330 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregorebe10102009-08-20 07:17:43 +00003332 Decls.push_back(Transformed);
3333 }
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregorebe10102009-08-20 07:17:43 +00003335 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003336 return SemaRef.Owned(S->Retain());
3337
3338 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003339 S->getStartLoc(), S->getEndLoc());
3340}
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregorebe10102009-08-20 07:17:43 +00003342template<typename Derived>
3343Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003344TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003345 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003346 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003347}
3348
3349template<typename Derived>
3350Sema::OwningStmtResult
3351TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003352
3353 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3354 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003355 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003356
Anders Carlssonaaeef072010-01-24 05:50:09 +00003357 OwningExprResult AsmString(SemaRef);
3358 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3359
3360 bool ExprsChanged = false;
3361
3362 // Go through the outputs.
3363 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003364 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003365
Anders Carlssonaaeef072010-01-24 05:50:09 +00003366 // No need to transform the constraint literal.
3367 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3368
3369 // Transform the output expr.
3370 Expr *OutputExpr = S->getOutputExpr(I);
3371 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3372 if (Result.isInvalid())
3373 return SemaRef.StmtError();
3374
3375 ExprsChanged |= Result.get() != OutputExpr;
3376
3377 Exprs.push_back(Result.takeAs<Expr>());
3378 }
3379
3380 // Go through the inputs.
3381 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003382 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003383
Anders Carlssonaaeef072010-01-24 05:50:09 +00003384 // No need to transform the constraint literal.
3385 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3386
3387 // Transform the input expr.
3388 Expr *InputExpr = S->getInputExpr(I);
3389 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3390 if (Result.isInvalid())
3391 return SemaRef.StmtError();
3392
3393 ExprsChanged |= Result.get() != InputExpr;
3394
3395 Exprs.push_back(Result.takeAs<Expr>());
3396 }
3397
3398 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3399 return SemaRef.Owned(S->Retain());
3400
3401 // Go through the clobbers.
3402 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3403 Clobbers.push_back(S->getClobber(I)->Retain());
3404
3405 // No need to transform the asm string literal.
3406 AsmString = SemaRef.Owned(S->getAsmString());
3407
3408 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3409 S->isSimple(),
3410 S->isVolatile(),
3411 S->getNumOutputs(),
3412 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003413 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003414 move_arg(Constraints),
3415 move_arg(Exprs),
3416 move(AsmString),
3417 move_arg(Clobbers),
3418 S->getRParenLoc(),
3419 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003420}
3421
3422
3423template<typename Derived>
3424Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003425TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 // FIXME: Implement this
3427 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003428 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003429}
Mike Stump11289f42009-09-09 15:08:12 +00003430
Douglas Gregorebe10102009-08-20 07:17:43 +00003431template<typename Derived>
3432Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003433TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 // FIXME: Implement this
3435 assert(false && "Cannot transform an Objective-C @catch statement");
3436 return SemaRef.Owned(S->Retain());
3437}
Mike Stump11289f42009-09-09 15:08:12 +00003438
Douglas Gregorebe10102009-08-20 07:17:43 +00003439template<typename Derived>
3440Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003441TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 // FIXME: Implement this
3443 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003444 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003445}
Mike Stump11289f42009-09-09 15:08:12 +00003446
Douglas Gregorebe10102009-08-20 07:17:43 +00003447template<typename Derived>
3448Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003449TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003450 // FIXME: Implement this
3451 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003452 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003453}
Mike Stump11289f42009-09-09 15:08:12 +00003454
Douglas Gregorebe10102009-08-20 07:17:43 +00003455template<typename Derived>
3456Sema::OwningStmtResult
3457TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003458 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003459 // FIXME: Implement this
3460 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003461 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003462}
3463
3464template<typename Derived>
3465Sema::OwningStmtResult
3466TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003467 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003468 // FIXME: Implement this
3469 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003470 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003471}
3472
3473
3474template<typename Derived>
3475Sema::OwningStmtResult
3476TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3477 // Transform the exception declaration, if any.
3478 VarDecl *Var = 0;
3479 if (S->getExceptionDecl()) {
3480 VarDecl *ExceptionDecl = S->getExceptionDecl();
3481 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3482 ExceptionDecl->getDeclName());
3483
3484 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3485 if (T.isNull())
3486 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003487
Douglas Gregorebe10102009-08-20 07:17:43 +00003488 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3489 T,
John McCallbcd03502009-12-07 02:54:59 +00003490 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003491 ExceptionDecl->getIdentifier(),
3492 ExceptionDecl->getLocation(),
3493 /*FIXME: Inaccurate*/
3494 SourceRange(ExceptionDecl->getLocation()));
3495 if (!Var || Var->isInvalidDecl()) {
3496 if (Var)
3497 Var->Destroy(SemaRef.Context);
3498 return SemaRef.StmtError();
3499 }
3500 }
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 // Transform the actual exception handler.
3503 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3504 if (Handler.isInvalid()) {
3505 if (Var)
3506 Var->Destroy(SemaRef.Context);
3507 return SemaRef.StmtError();
3508 }
Mike Stump11289f42009-09-09 15:08:12 +00003509
Douglas Gregorebe10102009-08-20 07:17:43 +00003510 if (!getDerived().AlwaysRebuild() &&
3511 !Var &&
3512 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003513 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003514
3515 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3516 Var,
3517 move(Handler));
3518}
Mike Stump11289f42009-09-09 15:08:12 +00003519
Douglas Gregorebe10102009-08-20 07:17:43 +00003520template<typename Derived>
3521Sema::OwningStmtResult
3522TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3523 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003524 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 = getDerived().TransformCompoundStmt(S->getTryBlock());
3526 if (TryBlock.isInvalid())
3527 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 // Transform the handlers.
3530 bool HandlerChanged = false;
3531 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3532 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003533 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3535 if (Handler.isInvalid())
3536 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3539 Handlers.push_back(Handler.takeAs<Stmt>());
3540 }
Mike Stump11289f42009-09-09 15:08:12 +00003541
Douglas Gregorebe10102009-08-20 07:17:43 +00003542 if (!getDerived().AlwaysRebuild() &&
3543 TryBlock.get() == S->getTryBlock() &&
3544 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003545 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003546
3547 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003548 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003549}
Mike Stump11289f42009-09-09 15:08:12 +00003550
Douglas Gregorebe10102009-08-20 07:17:43 +00003551//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003552// Expression transformation
3553//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003554template<typename Derived>
3555Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003556TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003557 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003558}
Mike Stump11289f42009-09-09 15:08:12 +00003559
3560template<typename Derived>
3561Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003562TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003563 NestedNameSpecifier *Qualifier = 0;
3564 if (E->getQualifier()) {
3565 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3566 E->getQualifierRange());
3567 if (!Qualifier)
3568 return SemaRef.ExprError();
3569 }
John McCallce546572009-12-08 09:08:17 +00003570
3571 ValueDecl *ND
3572 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003573 if (!ND)
3574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003576 if (!getDerived().AlwaysRebuild() &&
3577 Qualifier == E->getQualifier() &&
3578 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003579 !E->hasExplicitTemplateArgumentList()) {
3580
3581 // Mark it referenced in the new context regardless.
3582 // FIXME: this is a bit instantiation-specific.
3583 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3584
Mike Stump11289f42009-09-09 15:08:12 +00003585 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003586 }
John McCallce546572009-12-08 09:08:17 +00003587
3588 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3589 if (E->hasExplicitTemplateArgumentList()) {
3590 TemplateArgs = &TransArgs;
3591 TransArgs.setLAngleLoc(E->getLAngleLoc());
3592 TransArgs.setRAngleLoc(E->getRAngleLoc());
3593 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3594 TemplateArgumentLoc Loc;
3595 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3596 return SemaRef.ExprError();
3597 TransArgs.addArgument(Loc);
3598 }
3599 }
3600
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003601 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003602 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003603}
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregora16548e2009-08-11 05:31:07 +00003605template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003606Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003607TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003608 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003609}
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregora16548e2009-08-11 05:31:07 +00003611template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003612Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003613TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003614 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003615}
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregora16548e2009-08-11 05:31:07 +00003617template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003618Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003619TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003620 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003621}
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregora16548e2009-08-11 05:31:07 +00003623template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003624Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003625TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003626 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003627}
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregora16548e2009-08-11 05:31:07 +00003629template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003630Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003631TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003632 return SemaRef.Owned(E->Retain());
3633}
3634
3635template<typename Derived>
3636Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003637TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003638 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3639 if (SubExpr.isInvalid())
3640 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregora16548e2009-08-11 05:31:07 +00003642 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003643 return SemaRef.Owned(E->Retain());
3644
3645 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003646 E->getRParen());
3647}
3648
Mike Stump11289f42009-09-09 15:08:12 +00003649template<typename Derived>
3650Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003651TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3652 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003653 if (SubExpr.isInvalid())
3654 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003655
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003657 return SemaRef.Owned(E->Retain());
3658
Douglas Gregora16548e2009-08-11 05:31:07 +00003659 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3660 E->getOpcode(),
3661 move(SubExpr));
3662}
Mike Stump11289f42009-09-09 15:08:12 +00003663
Douglas Gregora16548e2009-08-11 05:31:07 +00003664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003665Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003666TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003667 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003668 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003669
John McCallbcd03502009-12-07 02:54:59 +00003670 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003671 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003672 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003673
John McCall4c98fd82009-11-04 07:28:41 +00003674 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003675 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003676
John McCall4c98fd82009-11-04 07:28:41 +00003677 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003678 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003679 E->getSourceRange());
3680 }
Mike Stump11289f42009-09-09 15:08:12 +00003681
Douglas Gregora16548e2009-08-11 05:31:07 +00003682 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003683 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 // C++0x [expr.sizeof]p1:
3685 // The operand is either an expression, which is an unevaluated operand
3686 // [...]
3687 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003688
Douglas Gregora16548e2009-08-11 05:31:07 +00003689 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3690 if (SubExpr.isInvalid())
3691 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregora16548e2009-08-11 05:31:07 +00003693 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3694 return SemaRef.Owned(E->Retain());
3695 }
Mike Stump11289f42009-09-09 15:08:12 +00003696
Douglas Gregora16548e2009-08-11 05:31:07 +00003697 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3698 E->isSizeOf(),
3699 E->getSourceRange());
3700}
Mike Stump11289f42009-09-09 15:08:12 +00003701
Douglas Gregora16548e2009-08-11 05:31:07 +00003702template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003703Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003704TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003705 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3706 if (LHS.isInvalid())
3707 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003708
Douglas Gregora16548e2009-08-11 05:31:07 +00003709 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3710 if (RHS.isInvalid())
3711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003712
3713
Douglas Gregora16548e2009-08-11 05:31:07 +00003714 if (!getDerived().AlwaysRebuild() &&
3715 LHS.get() == E->getLHS() &&
3716 RHS.get() == E->getRHS())
3717 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregora16548e2009-08-11 05:31:07 +00003719 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3720 /*FIXME:*/E->getLHS()->getLocStart(),
3721 move(RHS),
3722 E->getRBracketLoc());
3723}
Mike Stump11289f42009-09-09 15:08:12 +00003724
3725template<typename Derived>
3726Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003727TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003728 // Transform the callee.
3729 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3730 if (Callee.isInvalid())
3731 return SemaRef.ExprError();
3732
3733 // Transform arguments.
3734 bool ArgChanged = false;
3735 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3736 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3737 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3738 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3739 if (Arg.isInvalid())
3740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003741
Douglas Gregora16548e2009-08-11 05:31:07 +00003742 // FIXME: Wrong source location information for the ','.
3743 FakeCommaLocs.push_back(
3744 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003745
3746 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003747 Args.push_back(Arg.takeAs<Expr>());
3748 }
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregora16548e2009-08-11 05:31:07 +00003750 if (!getDerived().AlwaysRebuild() &&
3751 Callee.get() == E->getCallee() &&
3752 !ArgChanged)
3753 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003756 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3758 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3759 move_arg(Args),
3760 FakeCommaLocs.data(),
3761 E->getRParenLoc());
3762}
Mike Stump11289f42009-09-09 15:08:12 +00003763
3764template<typename Derived>
3765Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003766TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003767 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3768 if (Base.isInvalid())
3769 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003770
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003771 NestedNameSpecifier *Qualifier = 0;
3772 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003773 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003774 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3775 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003776 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003777 return SemaRef.ExprError();
3778 }
Mike Stump11289f42009-09-09 15:08:12 +00003779
Eli Friedman2cfcef62009-12-04 06:40:45 +00003780 ValueDecl *Member
3781 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 if (!Member)
3783 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregora16548e2009-08-11 05:31:07 +00003785 if (!getDerived().AlwaysRebuild() &&
3786 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003787 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003788 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003789 !E->hasExplicitTemplateArgumentList()) {
3790
3791 // Mark it referenced in the new context regardless.
3792 // FIXME: this is a bit instantiation-specific.
3793 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003794 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003795 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003796
John McCall6b51f282009-11-23 01:53:49 +00003797 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003798 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003799 TransArgs.setLAngleLoc(E->getLAngleLoc());
3800 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003801 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003802 TemplateArgumentLoc Loc;
3803 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003804 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003805 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003806 }
3807 }
3808
Douglas Gregora16548e2009-08-11 05:31:07 +00003809 // FIXME: Bogus source location for the operator
3810 SourceLocation FakeOperatorLoc
3811 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3812
John McCall38836f02010-01-15 08:34:02 +00003813 // FIXME: to do this check properly, we will need to preserve the
3814 // first-qualifier-in-scope here, just in case we had a dependent
3815 // base (and therefore couldn't do the check) and a
3816 // nested-name-qualifier (and therefore could do the lookup).
3817 NamedDecl *FirstQualifierInScope = 0;
3818
Douglas Gregora16548e2009-08-11 05:31:07 +00003819 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3820 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003821 Qualifier,
3822 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003823 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003824 Member,
John McCall6b51f282009-11-23 01:53:49 +00003825 (E->hasExplicitTemplateArgumentList()
3826 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003827 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003828}
Mike Stump11289f42009-09-09 15:08:12 +00003829
Douglas Gregora16548e2009-08-11 05:31:07 +00003830template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003831Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003832TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003833 assert(false && "Cannot transform abstract class");
3834 return SemaRef.Owned(E->Retain());
3835}
3836
3837template<typename Derived>
3838Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003839TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003840 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3841 if (LHS.isInvalid())
3842 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3845 if (RHS.isInvalid())
3846 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003847
Douglas Gregora16548e2009-08-11 05:31:07 +00003848 if (!getDerived().AlwaysRebuild() &&
3849 LHS.get() == E->getLHS() &&
3850 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003851 return SemaRef.Owned(E->Retain());
3852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3854 move(LHS), move(RHS));
3855}
3856
Mike Stump11289f42009-09-09 15:08:12 +00003857template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003858Sema::OwningExprResult
3859TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003860 CompoundAssignOperator *E) {
3861 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003862}
Mike Stump11289f42009-09-09 15:08:12 +00003863
Douglas Gregora16548e2009-08-11 05:31:07 +00003864template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003865Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003866TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003867 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3868 if (Cond.isInvalid())
3869 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003870
Douglas Gregora16548e2009-08-11 05:31:07 +00003871 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3872 if (LHS.isInvalid())
3873 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003874
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3876 if (RHS.isInvalid())
3877 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 if (!getDerived().AlwaysRebuild() &&
3880 Cond.get() == E->getCond() &&
3881 LHS.get() == E->getLHS() &&
3882 RHS.get() == E->getRHS())
3883 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003884
3885 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003886 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003887 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003888 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003889 move(RHS));
3890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
3892template<typename Derived>
3893Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003894TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003895 // Implicit casts are eliminated during transformation, since they
3896 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003897 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003898}
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900template<typename Derived>
3901Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003902TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003903 assert(false && "Cannot transform abstract class");
3904 return SemaRef.Owned(E->Retain());
3905}
3906
3907template<typename Derived>
3908Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003909TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003910 TypeSourceInfo *OldT;
3911 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 {
3913 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003914 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003915 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3916 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003917
John McCall97513962010-01-15 18:39:57 +00003918 OldT = E->getTypeInfoAsWritten();
3919 NewT = getDerived().TransformType(OldT);
3920 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003921 return SemaRef.ExprError();
3922 }
Mike Stump11289f42009-09-09 15:08:12 +00003923
Douglas Gregor6131b442009-12-12 18:16:41 +00003924 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003925 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 if (SubExpr.isInvalid())
3927 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003930 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003931 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003932 return SemaRef.Owned(E->Retain());
3933
John McCall97513962010-01-15 18:39:57 +00003934 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3935 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 E->getRParenLoc(),
3937 move(SubExpr));
3938}
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003941Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003942TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003943 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3944 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3945 if (!NewT)
3946 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003947
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3949 if (Init.isInvalid())
3950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003953 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003955 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003956
John McCall5d7aa7f2010-01-19 22:33:45 +00003957 // Note: the expression type doesn't necessarily match the
3958 // type-as-written, but that's okay, because it should always be
3959 // derivable from the initializer.
3960
John McCalle15bbff2010-01-18 19:35:47 +00003961 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 /*FIXME:*/E->getInitializer()->getLocEnd(),
3963 move(Init));
3964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966template<typename Derived>
3967Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003968TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3970 if (Base.isInvalid())
3971 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 if (!getDerived().AlwaysRebuild() &&
3974 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003975 return SemaRef.Owned(E->Retain());
3976
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003978 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003979 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3980 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3981 E->getAccessorLoc(),
3982 E->getAccessor());
3983}
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003986Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003987TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3991 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3992 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3993 if (Init.isInvalid())
3994 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003995
Douglas Gregora16548e2009-08-11 05:31:07 +00003996 InitChanged = InitChanged || Init.get() != E->getInit(I);
3997 Inits.push_back(Init.takeAs<Expr>());
3998 }
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004001 return SemaRef.Owned(E->Retain());
4002
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004004 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004005}
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007template<typename Derived>
4008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004009TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregorebe10102009-08-20 07:17:43 +00004012 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004013 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4014 if (Init.isInvalid())
4015 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregorebe10102009-08-20 07:17:43 +00004017 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4019 bool ExprChanged = false;
4020 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4021 DEnd = E->designators_end();
4022 D != DEnd; ++D) {
4023 if (D->isFieldDesignator()) {
4024 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4025 D->getDotLoc(),
4026 D->getFieldLoc()));
4027 continue;
4028 }
Mike Stump11289f42009-09-09 15:08:12 +00004029
Douglas Gregora16548e2009-08-11 05:31:07 +00004030 if (D->isArrayDesignator()) {
4031 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4032 if (Index.isInvalid())
4033 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004034
4035 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregora16548e2009-08-11 05:31:07 +00004038 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4039 ArrayExprs.push_back(Index.release());
4040 continue;
4041 }
Mike Stump11289f42009-09-09 15:08:12 +00004042
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004044 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004045 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4046 if (Start.isInvalid())
4047 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregora16548e2009-08-11 05:31:07 +00004049 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4050 if (End.isInvalid())
4051 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004052
4053 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 End.get(),
4055 D->getLBracketLoc(),
4056 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004057
Douglas Gregora16548e2009-08-11 05:31:07 +00004058 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4059 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004060
Douglas Gregora16548e2009-08-11 05:31:07 +00004061 ArrayExprs.push_back(Start.release());
4062 ArrayExprs.push_back(End.release());
4063 }
Mike Stump11289f42009-09-09 15:08:12 +00004064
Douglas Gregora16548e2009-08-11 05:31:07 +00004065 if (!getDerived().AlwaysRebuild() &&
4066 Init.get() == E->getInit() &&
4067 !ExprChanged)
4068 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4071 E->getEqualOrColonLoc(),
4072 E->usesGNUSyntax(), move(Init));
4073}
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004076Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004077TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004078 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004079 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4080
4081 // FIXME: Will we ever have proper type location here? Will we actually
4082 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 QualType T = getDerived().TransformType(E->getType());
4084 if (T.isNull())
4085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 if (!getDerived().AlwaysRebuild() &&
4088 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004089 return SemaRef.Owned(E->Retain());
4090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 return getDerived().RebuildImplicitValueInitExpr(T);
4092}
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregora16548e2009-08-11 05:31:07 +00004094template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004095Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004096TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 // FIXME: Do we want the type as written?
4098 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004099
Douglas Gregora16548e2009-08-11 05:31:07 +00004100 {
4101 // FIXME: Source location isn't quite accurate.
4102 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4103 T = getDerived().TransformType(E->getType());
4104 if (T.isNull())
4105 return SemaRef.ExprError();
4106 }
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4109 if (SubExpr.isInvalid())
4110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 if (!getDerived().AlwaysRebuild() &&
4113 T == E->getType() &&
4114 SubExpr.get() == E->getSubExpr())
4115 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4118 T, E->getRParenLoc());
4119}
4120
4121template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004122Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004123TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 bool ArgumentChanged = false;
4125 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4126 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4127 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4128 if (Init.isInvalid())
4129 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004130
Douglas Gregora16548e2009-08-11 05:31:07 +00004131 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4132 Inits.push_back(Init.takeAs<Expr>());
4133 }
Mike Stump11289f42009-09-09 15:08:12 +00004134
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4136 move_arg(Inits),
4137 E->getRParenLoc());
4138}
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregora16548e2009-08-11 05:31:07 +00004140/// \brief Transform an address-of-label expression.
4141///
4142/// By default, the transformation of an address-of-label expression always
4143/// rebuilds the expression, so that the label identifier can be resolved to
4144/// the corresponding label statement by semantic analysis.
4145template<typename Derived>
4146Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004147TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004148 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4149 E->getLabel());
4150}
Mike Stump11289f42009-09-09 15:08:12 +00004151
4152template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004153Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004154TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004155 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4157 if (SubStmt.isInvalid())
4158 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004159
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 if (!getDerived().AlwaysRebuild() &&
4161 SubStmt.get() == E->getSubStmt())
4162 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004163
4164 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004165 move(SubStmt),
4166 E->getRParenLoc());
4167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169template<typename Derived>
4170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 QualType T1, T2;
4173 {
4174 // FIXME: Source location isn't quite accurate.
4175 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004176
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 T1 = getDerived().TransformType(E->getArgType1());
4178 if (T1.isNull())
4179 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 T2 = getDerived().TransformType(E->getArgType2());
4182 if (T2.isNull())
4183 return SemaRef.ExprError();
4184 }
4185
4186 if (!getDerived().AlwaysRebuild() &&
4187 T1 == E->getArgType1() &&
4188 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004189 return SemaRef.Owned(E->Retain());
4190
Douglas Gregora16548e2009-08-11 05:31:07 +00004191 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4192 T1, T2, E->getRParenLoc());
4193}
Mike Stump11289f42009-09-09 15:08:12 +00004194
Douglas Gregora16548e2009-08-11 05:31:07 +00004195template<typename Derived>
4196Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004197TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4199 if (Cond.isInvalid())
4200 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4203 if (LHS.isInvalid())
4204 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4207 if (RHS.isInvalid())
4208 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004209
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 if (!getDerived().AlwaysRebuild() &&
4211 Cond.get() == E->getCond() &&
4212 LHS.get() == E->getLHS() &&
4213 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004214 return SemaRef.Owned(E->Retain());
4215
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4217 move(Cond), move(LHS), move(RHS),
4218 E->getRParenLoc());
4219}
Mike Stump11289f42009-09-09 15:08:12 +00004220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004222Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004223TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004224 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004225}
4226
4227template<typename Derived>
4228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004229TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004230 switch (E->getOperator()) {
4231 case OO_New:
4232 case OO_Delete:
4233 case OO_Array_New:
4234 case OO_Array_Delete:
4235 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4236 return SemaRef.ExprError();
4237
4238 case OO_Call: {
4239 // This is a call to an object's operator().
4240 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4241
4242 // Transform the object itself.
4243 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4244 if (Object.isInvalid())
4245 return SemaRef.ExprError();
4246
4247 // FIXME: Poor location information
4248 SourceLocation FakeLParenLoc
4249 = SemaRef.PP.getLocForEndOfToken(
4250 static_cast<Expr *>(Object.get())->getLocEnd());
4251
4252 // Transform the call arguments.
4253 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4254 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4255 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004256 if (getDerived().DropCallArgument(E->getArg(I)))
4257 break;
4258
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004259 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4260 if (Arg.isInvalid())
4261 return SemaRef.ExprError();
4262
4263 // FIXME: Poor source location information.
4264 SourceLocation FakeCommaLoc
4265 = SemaRef.PP.getLocForEndOfToken(
4266 static_cast<Expr *>(Arg.get())->getLocEnd());
4267 FakeCommaLocs.push_back(FakeCommaLoc);
4268 Args.push_back(Arg.release());
4269 }
4270
4271 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4272 move_arg(Args),
4273 FakeCommaLocs.data(),
4274 E->getLocEnd());
4275 }
4276
4277#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4278 case OO_##Name:
4279#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4280#include "clang/Basic/OperatorKinds.def"
4281 case OO_Subscript:
4282 // Handled below.
4283 break;
4284
4285 case OO_Conditional:
4286 llvm_unreachable("conditional operator is not actually overloadable");
4287 return SemaRef.ExprError();
4288
4289 case OO_None:
4290 case NUM_OVERLOADED_OPERATORS:
4291 llvm_unreachable("not an overloaded operator?");
4292 return SemaRef.ExprError();
4293 }
4294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4296 if (Callee.isInvalid())
4297 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004298
John McCall47f29ea2009-12-08 09:21:05 +00004299 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 if (First.isInvalid())
4301 return SemaRef.ExprError();
4302
4303 OwningExprResult Second(SemaRef);
4304 if (E->getNumArgs() == 2) {
4305 Second = getDerived().TransformExpr(E->getArg(1));
4306 if (Second.isInvalid())
4307 return SemaRef.ExprError();
4308 }
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 if (!getDerived().AlwaysRebuild() &&
4311 Callee.get() == E->getCallee() &&
4312 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004313 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4314 return SemaRef.Owned(E->Retain());
4315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4317 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004318 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 move(First),
4320 move(Second));
4321}
Mike Stump11289f42009-09-09 15:08:12 +00004322
Douglas Gregora16548e2009-08-11 05:31:07 +00004323template<typename Derived>
4324Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004325TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4326 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004327}
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004330Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004331TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004332 TypeSourceInfo *OldT;
4333 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 {
4335 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004336 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4338 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004339
John McCall97513962010-01-15 18:39:57 +00004340 OldT = E->getTypeInfoAsWritten();
4341 NewT = getDerived().TransformType(OldT);
4342 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 return SemaRef.ExprError();
4344 }
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregor6131b442009-12-12 18:16:41 +00004346 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004347 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 if (SubExpr.isInvalid())
4349 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004352 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004354 return SemaRef.Owned(E->Retain());
4355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004357 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4359 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4360 SourceLocation FakeRParenLoc
4361 = SemaRef.PP.getLocForEndOfToken(
4362 E->getSubExpr()->getSourceRange().getEnd());
4363 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004364 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004366 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 FakeRAngleLoc,
4368 FakeRAngleLoc,
4369 move(SubExpr),
4370 FakeRParenLoc);
4371}
Mike Stump11289f42009-09-09 15:08:12 +00004372
Douglas Gregora16548e2009-08-11 05:31:07 +00004373template<typename Derived>
4374Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004375TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4376 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004377}
Mike Stump11289f42009-09-09 15:08:12 +00004378
4379template<typename Derived>
4380Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004381TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4382 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004383}
4384
Douglas Gregora16548e2009-08-11 05:31:07 +00004385template<typename Derived>
4386Sema::OwningExprResult
4387TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004388 CXXReinterpretCastExpr *E) {
4389 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004390}
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392template<typename Derived>
4393Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004394TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4395 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004396}
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398template<typename Derived>
4399Sema::OwningExprResult
4400TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004401 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004402 TypeSourceInfo *OldT;
4403 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 {
4405 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004406
John McCall97513962010-01-15 18:39:57 +00004407 OldT = E->getTypeInfoAsWritten();
4408 NewT = getDerived().TransformType(OldT);
4409 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004410 return SemaRef.ExprError();
4411 }
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregor6131b442009-12-12 18:16:41 +00004413 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004414 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 if (SubExpr.isInvalid())
4416 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004417
Douglas Gregora16548e2009-08-11 05:31:07 +00004418 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004419 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004421 return SemaRef.Owned(E->Retain());
4422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 // FIXME: The end of the type's source range is wrong
4424 return getDerived().RebuildCXXFunctionalCastExpr(
4425 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004426 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 /*FIXME:*/E->getSubExpr()->getLocStart(),
4428 move(SubExpr),
4429 E->getRParenLoc());
4430}
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432template<typename Derived>
4433Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004434TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004435 if (E->isTypeOperand()) {
4436 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004437
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 QualType T = getDerived().TransformType(E->getTypeOperand());
4439 if (T.isNull())
4440 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 if (!getDerived().AlwaysRebuild() &&
4443 T == E->getTypeOperand())
4444 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4447 /*FIXME:*/E->getLocStart(),
4448 T,
4449 E->getLocEnd());
4450 }
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 // We don't know whether the expression is potentially evaluated until
4453 // after we perform semantic analysis, so the expression is potentially
4454 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004455 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004457
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4459 if (SubExpr.isInvalid())
4460 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 if (!getDerived().AlwaysRebuild() &&
4463 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004464 return SemaRef.Owned(E->Retain());
4465
Douglas Gregora16548e2009-08-11 05:31:07 +00004466 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4467 /*FIXME:*/E->getLocStart(),
4468 move(SubExpr),
4469 E->getLocEnd());
4470}
4471
4472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004473Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004474TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004475 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004476}
Mike Stump11289f42009-09-09 15:08:12 +00004477
Douglas Gregora16548e2009-08-11 05:31:07 +00004478template<typename Derived>
4479Sema::OwningExprResult
4480TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004481 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004482 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004483}
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485template<typename Derived>
4486Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004487TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004488 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 QualType T = getDerived().TransformType(E->getType());
4491 if (T.isNull())
4492 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004493
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 if (!getDerived().AlwaysRebuild() &&
4495 T == E->getType())
4496 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004497
Douglas Gregorb15af892010-01-07 23:12:05 +00004498 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004499}
Mike Stump11289f42009-09-09 15:08:12 +00004500
Douglas Gregora16548e2009-08-11 05:31:07 +00004501template<typename Derived>
4502Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004503TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4505 if (SubExpr.isInvalid())
4506 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 if (!getDerived().AlwaysRebuild() &&
4509 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004510 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004511
4512 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4513}
Mike Stump11289f42009-09-09 15:08:12 +00004514
Douglas Gregora16548e2009-08-11 05:31:07 +00004515template<typename Derived>
4516Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004517TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004518 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4520 if (!Param)
4521 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregora16548e2009-08-11 05:31:07 +00004523 if (getDerived().AlwaysRebuild() &&
4524 Param == E->getParam())
4525 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregor033f6752009-12-23 23:03:06 +00004527 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004528}
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530template<typename Derived>
4531Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004532TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004533 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4534
4535 QualType T = getDerived().TransformType(E->getType());
4536 if (T.isNull())
4537 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregora16548e2009-08-11 05:31:07 +00004539 if (!getDerived().AlwaysRebuild() &&
4540 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004541 return SemaRef.Owned(E->Retain());
4542
4543 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 /*FIXME:*/E->getTypeBeginLoc(),
4545 T,
4546 E->getRParenLoc());
4547}
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549template<typename Derived>
4550Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004551TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 // Transform the type that we're allocating
4553 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4554 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4555 if (AllocType.isNull())
4556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004557
Douglas Gregora16548e2009-08-11 05:31:07 +00004558 // Transform the size of the array we're allocating (if any).
4559 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4560 if (ArraySize.isInvalid())
4561 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 // Transform the placement arguments (if any).
4564 bool ArgumentChanged = false;
4565 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4566 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4567 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4568 if (Arg.isInvalid())
4569 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4572 PlacementArgs.push_back(Arg.take());
4573 }
Mike Stump11289f42009-09-09 15:08:12 +00004574
Douglas Gregorebe10102009-08-20 07:17:43 +00004575 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4577 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4578 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4579 if (Arg.isInvalid())
4580 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4583 ConstructorArgs.push_back(Arg.take());
4584 }
Mike Stump11289f42009-09-09 15:08:12 +00004585
Douglas Gregora16548e2009-08-11 05:31:07 +00004586 if (!getDerived().AlwaysRebuild() &&
4587 AllocType == E->getAllocatedType() &&
4588 ArraySize.get() == E->getArraySize() &&
4589 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004590 return SemaRef.Owned(E->Retain());
4591
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004592 if (!ArraySize.get()) {
4593 // If no array size was specified, but the new expression was
4594 // instantiated with an array type (e.g., "new T" where T is
4595 // instantiated with "int[4]"), extract the outer bound from the
4596 // array type as our array size. We do this with constant and
4597 // dependently-sized array types.
4598 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4599 if (!ArrayT) {
4600 // Do nothing
4601 } else if (const ConstantArrayType *ConsArrayT
4602 = dyn_cast<ConstantArrayType>(ArrayT)) {
4603 ArraySize
4604 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4605 ConsArrayT->getSize(),
4606 SemaRef.Context.getSizeType(),
4607 /*FIXME:*/E->getLocStart()));
4608 AllocType = ConsArrayT->getElementType();
4609 } else if (const DependentSizedArrayType *DepArrayT
4610 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4611 if (DepArrayT->getSizeExpr()) {
4612 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4613 AllocType = DepArrayT->getElementType();
4614 }
4615 }
4616 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004617 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4618 E->isGlobalNew(),
4619 /*FIXME:*/E->getLocStart(),
4620 move_arg(PlacementArgs),
4621 /*FIXME:*/E->getLocStart(),
4622 E->isParenTypeId(),
4623 AllocType,
4624 /*FIXME:*/E->getLocStart(),
4625 /*FIXME:*/SourceRange(),
4626 move(ArraySize),
4627 /*FIXME:*/E->getLocStart(),
4628 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004629 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004630}
Mike Stump11289f42009-09-09 15:08:12 +00004631
Douglas Gregora16548e2009-08-11 05:31:07 +00004632template<typename Derived>
4633Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004634TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4636 if (Operand.isInvalid())
4637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004640 Operand.get() == E->getArgument())
4641 return SemaRef.Owned(E->Retain());
4642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4644 E->isGlobalDelete(),
4645 E->isArrayForm(),
4646 move(Operand));
4647}
Mike Stump11289f42009-09-09 15:08:12 +00004648
Douglas Gregora16548e2009-08-11 05:31:07 +00004649template<typename Derived>
4650Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004651TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004652 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004653 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4654 if (Base.isInvalid())
4655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregorad8a3362009-09-04 17:36:40 +00004657 NestedNameSpecifier *Qualifier
4658 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4659 E->getQualifierRange());
4660 if (E->getQualifier() && !Qualifier)
4661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregorad8a3362009-09-04 17:36:40 +00004663 QualType DestroyedType;
4664 {
4665 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4666 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4667 if (DestroyedType.isNull())
4668 return SemaRef.ExprError();
4669 }
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregorad8a3362009-09-04 17:36:40 +00004671 if (!getDerived().AlwaysRebuild() &&
4672 Base.get() == E->getBase() &&
4673 Qualifier == E->getQualifier() &&
4674 DestroyedType == E->getDestroyedType())
4675 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004676
Douglas Gregorad8a3362009-09-04 17:36:40 +00004677 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4678 E->getOperatorLoc(),
4679 E->isArrow(),
4680 E->getDestroyedTypeLoc(),
4681 DestroyedType,
4682 Qualifier,
4683 E->getQualifierRange());
4684}
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregorad8a3362009-09-04 17:36:40 +00004686template<typename Derived>
4687Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004688TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004689 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004690 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4691
4692 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4693 Sema::LookupOrdinaryName);
4694
4695 // Transform all the decls.
4696 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4697 E = Old->decls_end(); I != E; ++I) {
4698 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004699 if (!InstD) {
4700 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4701 // This can happen because of dependent hiding.
4702 if (isa<UsingShadowDecl>(*I))
4703 continue;
4704 else
4705 return SemaRef.ExprError();
4706 }
John McCalle66edc12009-11-24 19:00:30 +00004707
4708 // Expand using declarations.
4709 if (isa<UsingDecl>(InstD)) {
4710 UsingDecl *UD = cast<UsingDecl>(InstD);
4711 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4712 E = UD->shadow_end(); I != E; ++I)
4713 R.addDecl(*I);
4714 continue;
4715 }
4716
4717 R.addDecl(InstD);
4718 }
4719
4720 // Resolve a kind, but don't do any further analysis. If it's
4721 // ambiguous, the callee needs to deal with it.
4722 R.resolveKind();
4723
4724 // Rebuild the nested-name qualifier, if present.
4725 CXXScopeSpec SS;
4726 NestedNameSpecifier *Qualifier = 0;
4727 if (Old->getQualifier()) {
4728 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4729 Old->getQualifierRange());
4730 if (!Qualifier)
4731 return SemaRef.ExprError();
4732
4733 SS.setScopeRep(Qualifier);
4734 SS.setRange(Old->getQualifierRange());
4735 }
4736
4737 // If we have no template arguments, it's a normal declaration name.
4738 if (!Old->hasExplicitTemplateArgs())
4739 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4740
4741 // If we have template arguments, rebuild them, then rebuild the
4742 // templateid expression.
4743 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4744 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4745 TemplateArgumentLoc Loc;
4746 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4747 return SemaRef.ExprError();
4748 TransArgs.addArgument(Loc);
4749 }
4750
4751 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4752 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004753}
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755template<typename Derived>
4756Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004757TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760 QualType T = getDerived().TransformType(E->getQueriedType());
4761 if (T.isNull())
4762 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 if (!getDerived().AlwaysRebuild() &&
4765 T == E->getQueriedType())
4766 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregora16548e2009-08-11 05:31:07 +00004768 // FIXME: Bad location information
4769 SourceLocation FakeLParenLoc
4770 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004771
4772 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 E->getLocStart(),
4774 /*FIXME:*/FakeLParenLoc,
4775 T,
4776 E->getLocEnd());
4777}
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779template<typename Derived>
4780Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004781TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004782 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004784 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4785 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 if (!NNS)
4787 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004788
4789 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004790 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4791 if (!Name)
4792 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004793
John McCalle66edc12009-11-24 19:00:30 +00004794 if (!E->hasExplicitTemplateArgs()) {
4795 if (!getDerived().AlwaysRebuild() &&
4796 NNS == E->getQualifier() &&
4797 Name == E->getDeclName())
4798 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004799
John McCalle66edc12009-11-24 19:00:30 +00004800 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4801 E->getQualifierRange(),
4802 Name, E->getLocation(),
4803 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004804 }
John McCall6b51f282009-11-23 01:53:49 +00004805
4806 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004808 TemplateArgumentLoc Loc;
4809 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004811 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004812 }
4813
John McCalle66edc12009-11-24 19:00:30 +00004814 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4815 E->getQualifierRange(),
4816 Name, E->getLocation(),
4817 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004818}
4819
4820template<typename Derived>
4821Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004822TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004823 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4824
4825 QualType T = getDerived().TransformType(E->getType());
4826 if (T.isNull())
4827 return SemaRef.ExprError();
4828
4829 CXXConstructorDecl *Constructor
4830 = cast_or_null<CXXConstructorDecl>(
4831 getDerived().TransformDecl(E->getConstructor()));
4832 if (!Constructor)
4833 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004834
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 bool ArgumentChanged = false;
4836 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004837 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 ArgEnd = E->arg_end();
4839 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004840 if (getDerived().DropCallArgument(*Arg)) {
4841 ArgumentChanged = true;
4842 break;
4843 }
4844
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4846 if (TransArg.isInvalid())
4847 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4850 Args.push_back(TransArg.takeAs<Expr>());
4851 }
4852
4853 if (!getDerived().AlwaysRebuild() &&
4854 T == E->getType() &&
4855 Constructor == E->getConstructor() &&
4856 !ArgumentChanged)
4857 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregordb121ba2009-12-14 16:27:04 +00004859 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4860 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004861 move_arg(Args));
4862}
Mike Stump11289f42009-09-09 15:08:12 +00004863
Douglas Gregora16548e2009-08-11 05:31:07 +00004864/// \brief Transform a C++ temporary-binding expression.
4865///
Douglas Gregor363b1512009-12-24 18:51:59 +00004866/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4867/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004868template<typename Derived>
4869Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004870TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004871 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004872}
Mike Stump11289f42009-09-09 15:08:12 +00004873
Anders Carlssonba6c4372010-01-29 02:39:32 +00004874/// \brief Transform a C++ reference-binding expression.
4875///
4876/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4877/// transform the subexpression and return that.
4878template<typename Derived>
4879Sema::OwningExprResult
4880TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4881 return getDerived().TransformExpr(E->getSubExpr());
4882}
4883
Mike Stump11289f42009-09-09 15:08:12 +00004884/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004885/// be destroyed after the expression is evaluated.
4886///
Douglas Gregor363b1512009-12-24 18:51:59 +00004887/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4888/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004889template<typename Derived>
4890Sema::OwningExprResult
4891TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004892 CXXExprWithTemporaries *E) {
4893 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896template<typename Derived>
4897Sema::OwningExprResult
4898TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004899 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4901 QualType T = getDerived().TransformType(E->getType());
4902 if (T.isNull())
4903 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004904
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 CXXConstructorDecl *Constructor
4906 = cast_or_null<CXXConstructorDecl>(
4907 getDerived().TransformDecl(E->getConstructor()));
4908 if (!Constructor)
4909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 bool ArgumentChanged = false;
4912 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4913 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004914 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004915 ArgEnd = E->arg_end();
4916 Arg != ArgEnd; ++Arg) {
4917 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4918 if (TransArg.isInvalid())
4919 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004920
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4922 Args.push_back((Expr *)TransArg.release());
4923 }
Mike Stump11289f42009-09-09 15:08:12 +00004924
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (!getDerived().AlwaysRebuild() &&
4926 T == E->getType() &&
4927 Constructor == E->getConstructor() &&
4928 !ArgumentChanged)
4929 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004930
Douglas Gregora16548e2009-08-11 05:31:07 +00004931 // FIXME: Bogus location information
4932 SourceLocation CommaLoc;
4933 if (Args.size() > 1) {
4934 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004935 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4937 }
4938 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4939 T,
4940 /*FIXME:*/E->getTypeBeginLoc(),
4941 move_arg(Args),
4942 &CommaLoc,
4943 E->getLocEnd());
4944}
Mike Stump11289f42009-09-09 15:08:12 +00004945
Douglas Gregora16548e2009-08-11 05:31:07 +00004946template<typename Derived>
4947Sema::OwningExprResult
4948TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004949 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004950 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4951 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4952 if (T.isNull())
4953 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregora16548e2009-08-11 05:31:07 +00004955 bool ArgumentChanged = false;
4956 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4957 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4958 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4959 ArgEnd = E->arg_end();
4960 Arg != ArgEnd; ++Arg) {
4961 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4962 if (TransArg.isInvalid())
4963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004964
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4966 FakeCommaLocs.push_back(
4967 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4968 Args.push_back(TransArg.takeAs<Expr>());
4969 }
Mike Stump11289f42009-09-09 15:08:12 +00004970
Douglas Gregora16548e2009-08-11 05:31:07 +00004971 if (!getDerived().AlwaysRebuild() &&
4972 T == E->getTypeAsWritten() &&
4973 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004974 return SemaRef.Owned(E->Retain());
4975
Douglas Gregora16548e2009-08-11 05:31:07 +00004976 // FIXME: we're faking the locations of the commas
4977 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4978 T,
4979 E->getLParenLoc(),
4980 move_arg(Args),
4981 FakeCommaLocs.data(),
4982 E->getRParenLoc());
4983}
Mike Stump11289f42009-09-09 15:08:12 +00004984
Douglas Gregora16548e2009-08-11 05:31:07 +00004985template<typename Derived>
4986Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004987TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004988 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004990 OwningExprResult Base(SemaRef, (Expr*) 0);
4991 Expr *OldBase;
4992 QualType BaseType;
4993 QualType ObjectType;
4994 if (!E->isImplicitAccess()) {
4995 OldBase = E->getBase();
4996 Base = getDerived().TransformExpr(OldBase);
4997 if (Base.isInvalid())
4998 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCall2d74de92009-12-01 22:10:20 +00005000 // Start the member reference and compute the object's type.
5001 Sema::TypeTy *ObjectTy = 0;
5002 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5003 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005004 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00005005 ObjectTy);
5006 if (Base.isInvalid())
5007 return SemaRef.ExprError();
5008
5009 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5010 BaseType = ((Expr*) Base.get())->getType();
5011 } else {
5012 OldBase = 0;
5013 BaseType = getDerived().TransformType(E->getBaseType());
5014 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5015 }
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005017 // Transform the first part of the nested-name-specifier that qualifies
5018 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005019 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005020 = getDerived().TransformFirstQualifierInScope(
5021 E->getFirstQualifierFoundInScope(),
5022 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005024 NestedNameSpecifier *Qualifier = 0;
5025 if (E->getQualifier()) {
5026 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5027 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005028 ObjectType,
5029 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005030 if (!Qualifier)
5031 return SemaRef.ExprError();
5032 }
Mike Stump11289f42009-09-09 15:08:12 +00005033
5034 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005035 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005036 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005037 if (!Name)
5038 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005039
John McCall2d74de92009-12-01 22:10:20 +00005040 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005041 // This is a reference to a member without an explicitly-specified
5042 // template argument list. Optimize for this common case.
5043 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005044 Base.get() == OldBase &&
5045 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005046 Qualifier == E->getQualifier() &&
5047 Name == E->getMember() &&
5048 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005049 return SemaRef.Owned(E->Retain());
5050
John McCall8cd78132009-11-19 22:55:06 +00005051 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005052 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005053 E->isArrow(),
5054 E->getOperatorLoc(),
5055 Qualifier,
5056 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005057 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005058 Name,
5059 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005060 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005061 }
5062
John McCall6b51f282009-11-23 01:53:49 +00005063 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005064 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005065 TemplateArgumentLoc Loc;
5066 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005067 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005068 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005069 }
Mike Stump11289f42009-09-09 15:08:12 +00005070
John McCall8cd78132009-11-19 22:55:06 +00005071 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005072 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 E->isArrow(),
5074 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005075 Qualifier,
5076 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005077 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005078 Name,
5079 E->getMemberLoc(),
5080 &TransArgs);
5081}
5082
5083template<typename Derived>
5084Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005085TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005086 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005087 OwningExprResult Base(SemaRef, (Expr*) 0);
5088 QualType BaseType;
5089 if (!Old->isImplicitAccess()) {
5090 Base = getDerived().TransformExpr(Old->getBase());
5091 if (Base.isInvalid())
5092 return SemaRef.ExprError();
5093 BaseType = ((Expr*) Base.get())->getType();
5094 } else {
5095 BaseType = getDerived().TransformType(Old->getBaseType());
5096 }
John McCall10eae182009-11-30 22:42:35 +00005097
5098 NestedNameSpecifier *Qualifier = 0;
5099 if (Old->getQualifier()) {
5100 Qualifier
5101 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5102 Old->getQualifierRange());
5103 if (Qualifier == 0)
5104 return SemaRef.ExprError();
5105 }
5106
5107 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5108 Sema::LookupOrdinaryName);
5109
5110 // Transform all the decls.
5111 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5112 E = Old->decls_end(); I != E; ++I) {
5113 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005114 if (!InstD) {
5115 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5116 // This can happen because of dependent hiding.
5117 if (isa<UsingShadowDecl>(*I))
5118 continue;
5119 else
5120 return SemaRef.ExprError();
5121 }
John McCall10eae182009-11-30 22:42:35 +00005122
5123 // Expand using declarations.
5124 if (isa<UsingDecl>(InstD)) {
5125 UsingDecl *UD = cast<UsingDecl>(InstD);
5126 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5127 E = UD->shadow_end(); I != E; ++I)
5128 R.addDecl(*I);
5129 continue;
5130 }
5131
5132 R.addDecl(InstD);
5133 }
5134
5135 R.resolveKind();
5136
5137 TemplateArgumentListInfo TransArgs;
5138 if (Old->hasExplicitTemplateArgs()) {
5139 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5140 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5141 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5142 TemplateArgumentLoc Loc;
5143 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5144 Loc))
5145 return SemaRef.ExprError();
5146 TransArgs.addArgument(Loc);
5147 }
5148 }
John McCall38836f02010-01-15 08:34:02 +00005149
5150 // FIXME: to do this check properly, we will need to preserve the
5151 // first-qualifier-in-scope here, just in case we had a dependent
5152 // base (and therefore couldn't do the check) and a
5153 // nested-name-qualifier (and therefore could do the lookup).
5154 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005155
5156 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005157 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005158 Old->getOperatorLoc(),
5159 Old->isArrow(),
5160 Qualifier,
5161 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005162 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005163 R,
5164 (Old->hasExplicitTemplateArgs()
5165 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005166}
5167
5168template<typename Derived>
5169Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005170TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005171 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005172}
5173
Mike Stump11289f42009-09-09 15:08:12 +00005174template<typename Derived>
5175Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005176TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 // FIXME: poor source location
5178 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5179 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5180 if (EncodedType.isNull())
5181 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 if (!getDerived().AlwaysRebuild() &&
5184 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005185 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005186
5187 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5188 EncodedType,
5189 E->getRParenLoc());
5190}
Mike Stump11289f42009-09-09 15:08:12 +00005191
Douglas Gregora16548e2009-08-11 05:31:07 +00005192template<typename Derived>
5193Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005194TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005195 // FIXME: Implement this!
5196 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005197 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005198}
5199
Mike Stump11289f42009-09-09 15:08:12 +00005200template<typename Derived>
5201Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005202TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005203 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204}
5205
Mike Stump11289f42009-09-09 15:08:12 +00005206template<typename Derived>
5207Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005208TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005209 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 = cast_or_null<ObjCProtocolDecl>(
5211 getDerived().TransformDecl(E->getProtocol()));
5212 if (!Protocol)
5213 return SemaRef.ExprError();
5214
5215 if (!getDerived().AlwaysRebuild() &&
5216 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005217 return SemaRef.Owned(E->Retain());
5218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219 return getDerived().RebuildObjCProtocolExpr(Protocol,
5220 E->getAtLoc(),
5221 /*FIXME:*/E->getAtLoc(),
5222 /*FIXME:*/E->getAtLoc(),
5223 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregora16548e2009-08-11 05:31:07 +00005225}
5226
Mike Stump11289f42009-09-09 15:08:12 +00005227template<typename Derived>
5228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005230 // FIXME: Implement this!
5231 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005232 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005233}
5234
Mike Stump11289f42009-09-09 15:08:12 +00005235template<typename Derived>
5236Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005237TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005238 // FIXME: Implement this!
5239 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005240 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005241}
5242
Mike Stump11289f42009-09-09 15:08:12 +00005243template<typename Derived>
5244Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005245TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005246 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 // FIXME: Implement this!
5248 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005249 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005250}
5251
Mike Stump11289f42009-09-09 15:08:12 +00005252template<typename Derived>
5253Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005255 // FIXME: Implement this!
5256 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005257 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005258}
5259
Mike Stump11289f42009-09-09 15:08:12 +00005260template<typename Derived>
5261Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005262TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 // FIXME: Implement this!
5264 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005265 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005266}
5267
Mike Stump11289f42009-09-09 15:08:12 +00005268template<typename Derived>
5269Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005270TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005271 bool ArgumentChanged = false;
5272 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5273 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5274 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5275 if (SubExpr.isInvalid())
5276 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005277
Douglas Gregora16548e2009-08-11 05:31:07 +00005278 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5279 SubExprs.push_back(SubExpr.takeAs<Expr>());
5280 }
Mike Stump11289f42009-09-09 15:08:12 +00005281
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 if (!getDerived().AlwaysRebuild() &&
5283 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005284 return SemaRef.Owned(E->Retain());
5285
Douglas Gregora16548e2009-08-11 05:31:07 +00005286 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5287 move_arg(SubExprs),
5288 E->getRParenLoc());
5289}
5290
Mike Stump11289f42009-09-09 15:08:12 +00005291template<typename Derived>
5292Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005293TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 // FIXME: Implement this!
5295 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005296 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005297}
5298
Mike Stump11289f42009-09-09 15:08:12 +00005299template<typename Derived>
5300Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005301TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 // FIXME: Implement this!
5303 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005304 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005305}
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregora16548e2009-08-11 05:31:07 +00005307//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005308// Type reconstruction
5309//===----------------------------------------------------------------------===//
5310
Mike Stump11289f42009-09-09 15:08:12 +00005311template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005312QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5313 SourceLocation Star) {
5314 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005315 getDerived().getBaseEntity());
5316}
5317
Mike Stump11289f42009-09-09 15:08:12 +00005318template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005319QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5320 SourceLocation Star) {
5321 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005322 getDerived().getBaseEntity());
5323}
5324
Mike Stump11289f42009-09-09 15:08:12 +00005325template<typename Derived>
5326QualType
John McCall70dd5f62009-10-30 00:06:24 +00005327TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5328 bool WrittenAsLValue,
5329 SourceLocation Sigil) {
5330 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5331 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005332}
5333
5334template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005335QualType
John McCall70dd5f62009-10-30 00:06:24 +00005336TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5337 QualType ClassType,
5338 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005339 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005340 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341}
5342
5343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005344QualType
John McCall70dd5f62009-10-30 00:06:24 +00005345TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5346 SourceLocation Sigil) {
5347 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005348 getDerived().getBaseEntity());
5349}
5350
5351template<typename Derived>
5352QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005353TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5354 ArrayType::ArraySizeModifier SizeMod,
5355 const llvm::APInt *Size,
5356 Expr *SizeExpr,
5357 unsigned IndexTypeQuals,
5358 SourceRange BracketsRange) {
5359 if (SizeExpr || !Size)
5360 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5361 IndexTypeQuals, BracketsRange,
5362 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005363
5364 QualType Types[] = {
5365 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5366 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5367 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005368 };
5369 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5370 QualType SizeType;
5371 for (unsigned I = 0; I != NumTypes; ++I)
5372 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5373 SizeType = Types[I];
5374 break;
5375 }
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregord6ff3322009-08-04 16:50:30 +00005377 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005378 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005379 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005380 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005381}
Mike Stump11289f42009-09-09 15:08:12 +00005382
Douglas Gregord6ff3322009-08-04 16:50:30 +00005383template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005384QualType
5385TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005386 ArrayType::ArraySizeModifier SizeMod,
5387 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005388 unsigned IndexTypeQuals,
5389 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005390 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005391 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005392}
5393
5394template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005395QualType
Mike Stump11289f42009-09-09 15:08:12 +00005396TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005397 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005398 unsigned IndexTypeQuals,
5399 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005400 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005401 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregord6ff3322009-08-04 16:50:30 +00005404template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005405QualType
5406TreeTransform<Derived>::RebuildVariableArrayType(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>
Mike Stump11289f42009-09-09 15:08:12 +00005417QualType
5418TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005420 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005421 unsigned IndexTypeQuals,
5422 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005423 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005424 SizeExpr.takeAs<Expr>(),
5425 IndexTypeQuals, BracketsRange);
5426}
5427
5428template<typename Derived>
5429QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5430 unsigned NumElements) {
5431 // FIXME: semantic checking!
5432 return SemaRef.Context.getVectorType(ElementType, NumElements);
5433}
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregord6ff3322009-08-04 16:50:30 +00005435template<typename Derived>
5436QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5437 unsigned NumElements,
5438 SourceLocation AttributeLoc) {
5439 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5440 NumElements, true);
5441 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005442 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443 AttributeLoc);
5444 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5445 AttributeLoc);
5446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregord6ff3322009-08-04 16:50:30 +00005448template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005449QualType
5450TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005452 SourceLocation AttributeLoc) {
5453 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregord6ff3322009-08-04 16:50:30 +00005456template<typename Derived>
5457QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005458 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005459 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005460 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005461 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005462 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005463 Quals,
5464 getDerived().getBaseLocation(),
5465 getDerived().getBaseEntity());
5466}
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregord6ff3322009-08-04 16:50:30 +00005468template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005469QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5470 return SemaRef.Context.getFunctionNoProtoType(T);
5471}
5472
5473template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005474QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5475 assert(D && "no decl found");
5476 if (D->isInvalidDecl()) return QualType();
5477
5478 TypeDecl *Ty;
5479 if (isa<UsingDecl>(D)) {
5480 UsingDecl *Using = cast<UsingDecl>(D);
5481 assert(Using->isTypeName() &&
5482 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5483
5484 // A valid resolved using typename decl points to exactly one type decl.
5485 assert(++Using->shadow_begin() == Using->shadow_end());
5486 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5487
5488 } else {
5489 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5490 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5491 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5492 }
5493
5494 return SemaRef.Context.getTypeDeclType(Ty);
5495}
5496
5497template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005498QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005499 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5500}
5501
5502template<typename Derived>
5503QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5504 return SemaRef.Context.getTypeOfType(Underlying);
5505}
5506
5507template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005508QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005509 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5510}
5511
5512template<typename Derived>
5513QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005514 TemplateName Template,
5515 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005516 const TemplateArgumentListInfo &TemplateArgs) {
5517 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005518}
Mike Stump11289f42009-09-09 15:08:12 +00005519
Douglas Gregor1135c352009-08-06 05:28:30 +00005520template<typename Derived>
5521NestedNameSpecifier *
5522TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5523 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005524 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005525 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005526 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005527 CXXScopeSpec SS;
5528 // FIXME: The source location information is all wrong.
5529 SS.setRange(Range);
5530 SS.setScopeRep(Prefix);
5531 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005532 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005533 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005534 ObjectType,
5535 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005536 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005537}
5538
5539template<typename Derived>
5540NestedNameSpecifier *
5541TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5542 SourceRange Range,
5543 NamespaceDecl *NS) {
5544 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5545}
5546
5547template<typename Derived>
5548NestedNameSpecifier *
5549TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5550 SourceRange Range,
5551 bool TemplateKW,
5552 QualType T) {
5553 if (T->isDependentType() || T->isRecordType() ||
5554 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005555 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005556 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5557 T.getTypePtr());
5558 }
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregor1135c352009-08-06 05:28:30 +00005560 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5561 return 0;
5562}
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregor71dc5092009-08-06 06:41:21 +00005564template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005565TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005566TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5567 bool TemplateKW,
5568 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005569 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005570 Template);
5571}
5572
5573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005574TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005575TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005576 const IdentifierInfo &II,
5577 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005578 CXXScopeSpec SS;
5579 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005580 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005581 UnqualifiedId Name;
5582 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005583 return getSema().ActOnDependentTemplateName(
5584 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005585 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005586 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005587 ObjectType.getAsOpaquePtr(),
5588 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005589 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005590}
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005593TemplateName
5594TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5595 OverloadedOperatorKind Operator,
5596 QualType ObjectType) {
5597 CXXScopeSpec SS;
5598 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5599 SS.setScopeRep(Qualifier);
5600 UnqualifiedId Name;
5601 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5602 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5603 Operator, SymbolLocations);
5604 return getSema().ActOnDependentTemplateName(
5605 /*FIXME:*/getDerived().getBaseLocation(),
5606 SS,
5607 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005608 ObjectType.getAsOpaquePtr(),
5609 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005610 .template getAsVal<TemplateName>();
5611}
5612
5613template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005614Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005615TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5616 SourceLocation OpLoc,
5617 ExprArg Callee,
5618 ExprArg First,
5619 ExprArg Second) {
5620 Expr *FirstExpr = (Expr *)First.get();
5621 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005622 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005626 if (Op == OO_Subscript) {
5627 if (!FirstExpr->getType()->isOverloadableType() &&
5628 !SecondExpr->getType()->isOverloadableType())
5629 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005630 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005631 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005632 } else if (Op == OO_Arrow) {
5633 // -> is never a builtin operation.
5634 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005635 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 if (!FirstExpr->getType()->isOverloadableType()) {
5637 // The argument is not of overloadable type, so try to create a
5638 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005639 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005640 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5643 }
5644 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005645 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 !SecondExpr->getType()->isOverloadableType()) {
5647 // Neither of the arguments is an overloadable type, so try to
5648 // create a built-in binary operation.
5649 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005650 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005651 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5652 if (Result.isInvalid())
5653 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 First.release();
5656 Second.release();
5657 return move(Result);
5658 }
5659 }
Mike Stump11289f42009-09-09 15:08:12 +00005660
5661 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005662 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005663 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005664
John McCalld14a8642009-11-21 08:51:07 +00005665 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5666 assert(ULE->requiresADL());
5667
5668 // FIXME: Do we have to check
5669 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005670 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005671 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005672 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005673 }
Mike Stump11289f42009-09-09 15:08:12 +00005674
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 // Add any functions found via argument-dependent lookup.
5676 Expr *Args[2] = { FirstExpr, SecondExpr };
5677 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 // Create the overloaded operator invocation for unary operators.
5680 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005681 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5683 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5684 }
Mike Stump11289f42009-09-09 15:08:12 +00005685
Sebastian Redladba46e2009-10-29 20:17:01 +00005686 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005687 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5688 OpLoc,
5689 move(First),
5690 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005691
Douglas Gregora16548e2009-08-11 05:31:07 +00005692 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005693 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005694 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005695 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5697 if (Result.isInvalid())
5698 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005699
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 First.release();
5701 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005702 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005703}
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregord6ff3322009-08-04 16:50:30 +00005705} // end namespace clang
5706
5707#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H