blob: 41f465f595caa0240f1e1aa147b6e813640dc129 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregor577f75a2009-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 McCallf7a1a742009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCalla2becad2009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump1eb44332009-09-09 15:08:12 +000034
Douglas Gregor577f75a2009-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 Stump1eb44332009-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 Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-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 Gregor43959a92009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-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 Gregor577f75a2009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump1eb44332009-09-09 15:08:12 +000090
91public:
Douglas Gregorb98b1992009-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 Gregor43959a92009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregor577f75a2009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000114
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000121
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Douglas Gregor577f75a2009-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 Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000143
Douglas Gregorb98b1992009-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 Stump1eb44332009-09-09 15:08:12 +0000150
Douglas Gregorb98b1992009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Douglas Gregorb98b1992009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump1eb44332009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-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 Gregor6eef5192009-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 Gregor577f75a2009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCalla2becad2009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-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 McCalla93c9342009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
194 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000195
John McCalla2becad2009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000198 ///
John McCalla2becad2009-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 McCalla93c9342009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-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 Stump1eb44332009-09-09 15:08:12 +0000211
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000213 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-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 Gregorb98b1992009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregorb98b1992009-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 McCall454feb92009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000232
Douglas Gregor577f75a2009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregordcee1a12009-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 Gregor43959a92009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000245
Douglas Gregor6cd21982009-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 Gregor577f75a2009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Douglas Gregor81499bb2009-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 Gregordd62b152009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Douglas Gregor577f75a2009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000280 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Douglas Gregor577f75a2009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump1eb44332009-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 Gregor670444e2009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall833ca992009-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 McCalla93c9342009-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 McCall833ca992009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump1eb44332009-09-09 15:08:12 +0000307
John McCalla2becad2009-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 Gregor577f75a2009-08-04 16:50:30 +0000312
John McCall85737a72009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregordd62b152009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +0000323
Douglas Gregor43959a92009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000325
Douglas Gregor43959a92009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000344
John McCall85737a72009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000346 ///
John McCall85737a72009-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 Gregor577f75a2009-08-04 16:50:30 +0000350 ///
John McCall85737a72009-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 Stump1eb44332009-09-09 15:08:12 +0000356
Douglas Gregor577f75a2009-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 McCall85737a72009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000364
John McCalla2becad2009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000368
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000382
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000393
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000403
Mike Stump1eb44332009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump1eb44332009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000432
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000449
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000458
John McCalla2becad2009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCalled976492009-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 Gregor577f75a2009-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 McCall7da24312009-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 Stump1eb44332009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-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 Gregorb98b1992009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000491
Mike Stump1eb44332009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-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 Gregorb98b1992009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000502
Douglas Gregor577f75a2009-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 McCall833ca992009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump1eb44332009-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 Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000519 }
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
527 if (NNS->isDependent())
Mike Stump1eb44332009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000532 }
Douglas Gregor577f75a2009-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 Stump1eb44332009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000543 }
Mike Stump1eb44332009-09-09 15:08:12 +0000544
Douglas Gregordcee1a12009-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 Gregora38c6872009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-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 Gregord1067e52009-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 Gregord1067e52009-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 Gregor3b6afbb2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000598
Douglas Gregorca1bdd72009-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 Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump1eb44332009-09-09 15:08:12 +0000634
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump1eb44332009-09-09 15:08:12 +0000654
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000665
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-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 Gregor43959a92009-08-20 07:17:43 +0000675 }
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Douglas Gregor43959a92009-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 Gregor99e9b4d2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000684 }
Mike Stump1eb44332009-09-09 15:08:12 +0000685
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-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 Gregor99e9b4d2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000706 }
Mike Stump1eb44332009-09-09 15:08:12 +0000707
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 }
Mike Stump1eb44332009-09-09 15:08:12 +0000734
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000754
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump1eb44332009-09-09 15:08:12 +0000764
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregor43959a92009-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 Stump1eb44332009-09-09 15:08:12 +0000778
Douglas Gregor43959a92009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000784 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump1eb44332009-09-09 15:08:12 +0000803
Douglas Gregor43959a92009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump1eb44332009-09-09 15:08:12 +0000813
Douglas Gregorb98b1992009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000818 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
819 LookupResult &R,
820 bool RequiresADL) {
821 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
822 }
823
824
825 /// \brief Build a new expression that references a declaration.
826 ///
827 /// By default, performs semantic analysis to build the new expression.
828 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000829 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
830 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000831 ValueDecl *VD, SourceLocation Loc,
832 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000833 CXXScopeSpec SS;
834 SS.setScopeRep(Qualifier);
835 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000836
837 // FIXME: loses template args.
838
839 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000840 }
Mike Stump1eb44332009-09-09 15:08:12 +0000841
Douglas Gregorb98b1992009-08-11 05:31:07 +0000842 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000843 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
847 SourceLocation RParen) {
848 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
849 }
850
Douglas Gregora71d8192009-09-04 17:36:40 +0000851 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000852 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
856 SourceLocation OperatorLoc,
857 bool isArrow,
858 SourceLocation DestroyedTypeLoc,
859 QualType DestroyedType,
860 NestedNameSpecifier *Qualifier,
861 SourceRange QualifierRange) {
862 CXXScopeSpec SS;
863 if (Qualifier) {
864 SS.setRange(QualifierRange);
865 SS.setScopeRep(Qualifier);
866 }
867
John McCallaa81e162009-12-01 22:10:20 +0000868 QualType BaseType = ((Expr*) Base.get())->getType();
869
Mike Stump1eb44332009-09-09 15:08:12 +0000870 DeclarationName Name
Douglas Gregora71d8192009-09-04 17:36:40 +0000871 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
872 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump1eb44332009-09-09 15:08:12 +0000873
John McCallaa81e162009-12-01 22:10:20 +0000874 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
875 OperatorLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000876 SS, /*FIXME: FirstQualifier*/ 0,
877 Name, DestroyedTypeLoc,
878 /*TemplateArgs*/ 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000879 }
880
Douglas Gregorb98b1992009-08-11 05:31:07 +0000881 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000882 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
885 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
886 UnaryOperator::Opcode Opc,
887 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000888 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000889 }
Mike Stump1eb44332009-09-09 15:08:12 +0000890
Douglas Gregorb98b1992009-08-11 05:31:07 +0000891 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000892 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000895 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000896 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000897 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000898 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000899 }
900
Mike Stump1eb44332009-09-09 15:08:12 +0000901 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000902 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000903 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000904 /// By default, performs semantic analysis to build the new expression.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
907 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000908 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000909 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
910 OpLoc, isSizeOf, R);
911 if (Result.isInvalid())
912 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000913
Douglas Gregorb98b1992009-08-11 05:31:07 +0000914 SubExpr.release();
915 return move(Result);
916 }
Mike Stump1eb44332009-09-09 15:08:12 +0000917
Douglas Gregorb98b1992009-08-11 05:31:07 +0000918 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000919 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000922 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000923 SourceLocation LBracketLoc,
924 ExprArg RHS,
925 SourceLocation RBracketLoc) {
926 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000927 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000928 RBracketLoc);
929 }
930
931 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000932 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
935 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
936 MultiExprArg Args,
937 SourceLocation *CommaLocs,
938 SourceLocation RParenLoc) {
939 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
940 move(Args), CommaLocs, RParenLoc);
941 }
942
943 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000944 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000948 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000949 NestedNameSpecifier *Qualifier,
950 SourceRange QualifierRange,
951 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000952 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000953 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000954 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000955 if (!Member->getDeclName()) {
956 // We have a reference to an unnamed field.
957 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000958
Douglas Gregor83a56c42009-12-24 20:02:50 +0000959 Expr *BaseExpr = Base.takeAs<Expr>();
960 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
961 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000962
Mike Stump1eb44332009-09-09 15:08:12 +0000963 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000964 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000965 Member, MemberLoc,
966 cast<FieldDecl>(Member)->getType());
967 return getSema().Owned(ME);
968 }
Mike Stump1eb44332009-09-09 15:08:12 +0000969
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000970 CXXScopeSpec SS;
971 if (Qualifier) {
972 SS.setRange(QualifierRange);
973 SS.setScopeRep(Qualifier);
974 }
975
John McCallaa81e162009-12-01 22:10:20 +0000976 QualType BaseType = ((Expr*) Base.get())->getType();
977
John McCallc2233c52010-01-15 08:34:02 +0000978 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
979 Sema::LookupMemberName);
980 R.addDecl(Member);
981 R.resolveKind();
982
John McCallaa81e162009-12-01 22:10:20 +0000983 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
984 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000985 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +0000986 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregorb98b1992009-08-11 05:31:07 +0000989 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000990 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000991 /// By default, performs semantic analysis to build the new expression.
992 /// Subclasses may override this routine to provide different behavior.
993 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
994 BinaryOperator::Opcode Opc,
995 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000996 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
997 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +0000998 }
999
1000 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001001 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001002 /// By default, performs semantic analysis to build the new expression.
1003 /// Subclasses may override this routine to provide different behavior.
1004 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1005 SourceLocation QuestionLoc,
1006 ExprArg LHS,
1007 SourceLocation ColonLoc,
1008 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001009 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 move(LHS), move(RHS));
1011 }
1012
Douglas Gregorb98b1992009-08-11 05:31:07 +00001013 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001014 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001015 /// By default, performs semantic analysis to build the new expression.
1016 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001017 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1018 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001019 SourceLocation RParenLoc,
1020 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001021 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1022 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001026 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1030 QualType T,
1031 SourceLocation RParenLoc,
1032 ExprArg Init) {
1033 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1034 RParenLoc, move(Init));
1035 }
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001038 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001041 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001042 SourceLocation OpLoc,
1043 SourceLocation AccessorLoc,
1044 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001045
John McCall129e2df2009-11-30 22:42:35 +00001046 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001047 QualType BaseType = ((Expr*) Base.get())->getType();
1048 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001049 OpLoc, /*IsArrow*/ false,
1050 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001051 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001052 AccessorLoc,
1053 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001054 }
Mike Stump1eb44332009-09-09 15:08:12 +00001055
Douglas Gregorb98b1992009-08-11 05:31:07 +00001056 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001057 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1061 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001062 SourceLocation RBraceLoc,
1063 QualType ResultTy) {
1064 OwningExprResult Result
1065 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1066 if (Result.isInvalid() || ResultTy->isDependentType())
1067 return move(Result);
1068
1069 // Patch in the result type we were given, which may have been computed
1070 // when the initial InitListExpr was built.
1071 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1072 ILE->setType(ResultTy);
1073 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregorb98b1992009-08-11 05:31:07 +00001076 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001077 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
1080 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1081 MultiExprArg ArrayExprs,
1082 SourceLocation EqualOrColonLoc,
1083 bool GNUSyntax,
1084 ExprArg Init) {
1085 OwningExprResult Result
1086 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1087 move(Init));
1088 if (Result.isInvalid())
1089 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001090
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 ArrayExprs.release();
1092 return move(Result);
1093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregorb98b1992009-08-11 05:31:07 +00001095 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001096 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001097 /// By default, builds the implicit value initialization without performing
1098 /// any semantic analysis. Subclasses may override this routine to provide
1099 /// different behavior.
1100 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1101 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1102 }
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001105 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
1108 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1109 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001110 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001111 RParenLoc);
1112 }
1113
1114 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001115 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001116 /// By default, performs semantic analysis to build the new expression.
1117 /// Subclasses may override this routine to provide different behavior.
1118 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1119 MultiExprArg SubExprs,
1120 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001121 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1122 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 }
Mike Stump1eb44332009-09-09 15:08:12 +00001124
Douglas Gregorb98b1992009-08-11 05:31:07 +00001125 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001126 ///
1127 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// rather than attempting to map the label statement itself.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1131 SourceLocation LabelLoc,
1132 LabelStmt *Label) {
1133 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1134 }
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregorb98b1992009-08-11 05:31:07 +00001136 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001137 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1141 StmtArg SubStmt,
1142 SourceLocation RParenLoc) {
1143 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1144 }
Mike Stump1eb44332009-09-09 15:08:12 +00001145
Douglas Gregorb98b1992009-08-11 05:31:07 +00001146 /// \brief Build a new __builtin_types_compatible_p expression.
1147 ///
1148 /// By default, performs semantic analysis to build the new expression.
1149 /// Subclasses may override this routine to provide different behavior.
1150 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1151 QualType T1, QualType T2,
1152 SourceLocation RParenLoc) {
1153 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1154 T1.getAsOpaquePtr(),
1155 T2.getAsOpaquePtr(),
1156 RParenLoc);
1157 }
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregorb98b1992009-08-11 05:31:07 +00001159 /// \brief Build a new __builtin_choose_expr expression.
1160 ///
1161 /// By default, performs semantic analysis to build the new expression.
1162 /// Subclasses may override this routine to provide different behavior.
1163 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1164 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1165 SourceLocation RParenLoc) {
1166 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1167 move(Cond), move(LHS), move(RHS),
1168 RParenLoc);
1169 }
Mike Stump1eb44332009-09-09 15:08:12 +00001170
Douglas Gregorb98b1992009-08-11 05:31:07 +00001171 /// \brief Build a new overloaded operator call expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// The semantic analysis provides the behavior of template instantiation,
1175 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001176 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001177 /// argument-dependent lookup, etc. Subclasses may override this routine to
1178 /// provide different behavior.
1179 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1180 SourceLocation OpLoc,
1181 ExprArg Callee,
1182 ExprArg First,
1183 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001184
1185 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001186 /// reinterpret_cast.
1187 ///
1188 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001189 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001190 /// Subclasses may override this routine to provide different behavior.
1191 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1192 Stmt::StmtClass Class,
1193 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001194 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001195 SourceLocation RAngleLoc,
1196 SourceLocation LParenLoc,
1197 ExprArg SubExpr,
1198 SourceLocation RParenLoc) {
1199 switch (Class) {
1200 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001201 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001202 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 move(SubExpr), RParenLoc);
1204
1205 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001206 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001207 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001209
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001211 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001212 RAngleLoc, LParenLoc,
1213 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001214 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001215
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001217 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001218 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001219 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001220
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 default:
1222 assert(false && "Invalid C++ named cast");
1223 break;
1224 }
Mike Stump1eb44332009-09-09 15:08:12 +00001225
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 return getSema().ExprError();
1227 }
Mike Stump1eb44332009-09-09 15:08:12 +00001228
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 /// \brief Build a new C++ static_cast expression.
1230 ///
1231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
1233 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1234 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001235 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001236 SourceLocation RAngleLoc,
1237 SourceLocation LParenLoc,
1238 ExprArg SubExpr,
1239 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001240 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1241 TInfo, move(SubExpr),
1242 SourceRange(LAngleLoc, RAngleLoc),
1243 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001244 }
1245
1246 /// \brief Build a new C++ dynamic_cast expression.
1247 ///
1248 /// By default, performs semantic analysis to build the new expression.
1249 /// Subclasses may override this routine to provide different behavior.
1250 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1251 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001252 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001253 SourceLocation RAngleLoc,
1254 SourceLocation LParenLoc,
1255 ExprArg SubExpr,
1256 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001257 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1258 TInfo, move(SubExpr),
1259 SourceRange(LAngleLoc, RAngleLoc),
1260 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001261 }
1262
1263 /// \brief Build a new C++ reinterpret_cast expression.
1264 ///
1265 /// By default, performs semantic analysis to build the new expression.
1266 /// Subclasses may override this routine to provide different behavior.
1267 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1268 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001269 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001270 SourceLocation RAngleLoc,
1271 SourceLocation LParenLoc,
1272 ExprArg SubExpr,
1273 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001274 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1275 TInfo, move(SubExpr),
1276 SourceRange(LAngleLoc, RAngleLoc),
1277 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 }
1279
1280 /// \brief Build a new C++ const_cast expression.
1281 ///
1282 /// By default, performs semantic analysis to build the new expression.
1283 /// Subclasses may override this routine to provide different behavior.
1284 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1285 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001286 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001287 SourceLocation RAngleLoc,
1288 SourceLocation LParenLoc,
1289 ExprArg SubExpr,
1290 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001291 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1292 TInfo, move(SubExpr),
1293 SourceRange(LAngleLoc, RAngleLoc),
1294 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001295 }
Mike Stump1eb44332009-09-09 15:08:12 +00001296
Douglas Gregorb98b1992009-08-11 05:31:07 +00001297 /// \brief Build a new C++ functional-style cast expression.
1298 ///
1299 /// By default, performs semantic analysis to build the new expression.
1300 /// Subclasses may override this routine to provide different behavior.
1301 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001302 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 SourceLocation LParenLoc,
1304 ExprArg SubExpr,
1305 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001306 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001308 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001310 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001311 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 RParenLoc);
1313 }
Mike Stump1eb44332009-09-09 15:08:12 +00001314
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 /// \brief Build a new C++ typeid(type) expression.
1316 ///
1317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
1319 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1320 SourceLocation LParenLoc,
1321 QualType T,
1322 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001323 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 T.getAsOpaquePtr(), RParenLoc);
1325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// \brief Build a new C++ typeid(expr) expression.
1328 ///
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1332 SourceLocation LParenLoc,
1333 ExprArg Operand,
1334 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001335 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1337 RParenLoc);
1338 if (Result.isInvalid())
1339 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001340
Douglas Gregorb98b1992009-08-11 05:31:07 +00001341 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1342 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001343 }
1344
Douglas Gregorb98b1992009-08-11 05:31:07 +00001345 /// \brief Build a new C++ "this" expression.
1346 ///
1347 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001348 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001350 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001351 QualType ThisType,
1352 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001354 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1355 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001356 }
1357
1358 /// \brief Build a new C++ throw expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
1362 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1363 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1364 }
1365
1366 /// \brief Build a new C++ default-argument expression.
1367 ///
1368 /// By default, builds a new default-argument expression, which does not
1369 /// require any semantic analysis. Subclasses may override this routine to
1370 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001371 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1372 ParmVarDecl *Param) {
1373 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1374 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 }
1376
1377 /// \brief Build a new C++ zero-initialization expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001381 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 SourceLocation LParenLoc,
1383 QualType T,
1384 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001385 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1386 T.getAsOpaquePtr(), LParenLoc,
1387 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 0, RParenLoc);
1389 }
Mike Stump1eb44332009-09-09 15:08:12 +00001390
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 /// \brief Build a new C++ "new" expression.
1392 ///
1393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001395 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 bool UseGlobal,
1397 SourceLocation PlacementLParen,
1398 MultiExprArg PlacementArgs,
1399 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001400 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 QualType AllocType,
1402 SourceLocation TypeLoc,
1403 SourceRange TypeRange,
1404 ExprArg ArraySize,
1405 SourceLocation ConstructorLParen,
1406 MultiExprArg ConstructorArgs,
1407 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001408 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 PlacementLParen,
1410 move(PlacementArgs),
1411 PlacementRParen,
1412 ParenTypeId,
1413 AllocType,
1414 TypeLoc,
1415 TypeRange,
1416 move(ArraySize),
1417 ConstructorLParen,
1418 move(ConstructorArgs),
1419 ConstructorRParen);
1420 }
Mike Stump1eb44332009-09-09 15:08:12 +00001421
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 /// \brief Build a new C++ "delete" expression.
1423 ///
1424 /// By default, performs semantic analysis to build the new expression.
1425 /// Subclasses may override this routine to provide different behavior.
1426 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1427 bool IsGlobalDelete,
1428 bool IsArrayForm,
1429 ExprArg Operand) {
1430 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1431 move(Operand));
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new unary type trait expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1439 SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 QualType T,
1442 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001443 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 T.getAsOpaquePtr(), RParenLoc);
1445 }
1446
Mike Stump1eb44332009-09-09 15:08:12 +00001447 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 /// expression.
1449 ///
1450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001452 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001453 SourceRange QualifierRange,
1454 DeclarationName Name,
1455 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001456 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 CXXScopeSpec SS;
1458 SS.setRange(QualifierRange);
1459 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001460
1461 if (TemplateArgs)
1462 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1463 *TemplateArgs);
1464
1465 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new template-id expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001472 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1473 LookupResult &R,
1474 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001475 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001476 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001477 }
1478
1479 /// \brief Build a new object-construction expression.
1480 ///
1481 /// By default, performs semantic analysis to build the new expression.
1482 /// Subclasses may override this routine to provide different behavior.
1483 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001484 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001485 CXXConstructorDecl *Constructor,
1486 bool IsElidable,
1487 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001488 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1489 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1490 ConvertedArgs))
1491 return getSema().ExprError();
1492
1493 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1494 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 }
1496
1497 /// \brief Build a new object-construction expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1502 QualType T,
1503 SourceLocation LParenLoc,
1504 MultiExprArg Args,
1505 SourceLocation *Commas,
1506 SourceLocation RParenLoc) {
1507 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1508 T.getAsOpaquePtr(),
1509 LParenLoc,
1510 move(Args),
1511 Commas,
1512 RParenLoc);
1513 }
1514
1515 /// \brief Build a new object-construction expression.
1516 ///
1517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
1519 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1520 QualType T,
1521 SourceLocation LParenLoc,
1522 MultiExprArg Args,
1523 SourceLocation *Commas,
1524 SourceLocation RParenLoc) {
1525 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1526 /*FIXME*/LParenLoc),
1527 T.getAsOpaquePtr(),
1528 LParenLoc,
1529 move(Args),
1530 Commas,
1531 RParenLoc);
1532 }
Mike Stump1eb44332009-09-09 15:08:12 +00001533
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 /// \brief Build a new member reference expression.
1535 ///
1536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001538 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001539 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 bool IsArrow,
1541 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001542 NestedNameSpecifier *Qualifier,
1543 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001544 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001546 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001547 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001549 SS.setRange(QualifierRange);
1550 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001551
John McCallaa81e162009-12-01 22:10:20 +00001552 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1553 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001554 SS, FirstQualifierInScope,
1555 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 }
1557
John McCall129e2df2009-11-30 22:42:35 +00001558 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001562 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001563 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001564 SourceLocation OperatorLoc,
1565 bool IsArrow,
1566 NestedNameSpecifier *Qualifier,
1567 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001568 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001569 LookupResult &R,
1570 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001571 CXXScopeSpec SS;
1572 SS.setRange(QualifierRange);
1573 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001574
John McCallaa81e162009-12-01 22:10:20 +00001575 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1576 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001577 SS, FirstQualifierInScope,
1578 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001579 }
Mike Stump1eb44332009-09-09 15:08:12 +00001580
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// \brief Build a new Objective-C @encode expression.
1582 ///
1583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
1585 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1586 QualType T,
1587 SourceLocation RParenLoc) {
1588 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1589 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001590 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591
1592 /// \brief Build a new Objective-C protocol expression.
1593 ///
1594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
1596 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1597 SourceLocation AtLoc,
1598 SourceLocation ProtoLoc,
1599 SourceLocation LParenLoc,
1600 SourceLocation RParenLoc) {
1601 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1602 Protocol->getIdentifier(),
1603 AtLoc,
1604 ProtoLoc,
1605 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001606 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 }
Mike Stump1eb44332009-09-09 15:08:12 +00001608
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 /// \brief Build a new shuffle vector expression.
1610 ///
1611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
1613 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1614 MultiExprArg SubExprs,
1615 SourceLocation RParenLoc) {
1616 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001617 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1619 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1620 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1621 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001622
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 // Build a reference to the __builtin_shufflevector builtin
1624 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001625 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001627 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001629
1630 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 unsigned NumSubExprs = SubExprs.size();
1632 Expr **Subs = (Expr **)SubExprs.release();
1633 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1634 Subs, NumSubExprs,
1635 Builtin->getResultType(),
1636 RParenLoc);
1637 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001638
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 // Type-check the __builtin_shufflevector expression.
1640 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1641 if (Result.isInvalid())
1642 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001643
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001645 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001647};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648
Douglas Gregor43959a92009-08-20 07:17:43 +00001649template<typename Derived>
1650Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1651 if (!S)
1652 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001653
Douglas Gregor43959a92009-08-20 07:17:43 +00001654 switch (S->getStmtClass()) {
1655 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregor43959a92009-08-20 07:17:43 +00001657 // Transform individual statement nodes
1658#define STMT(Node, Parent) \
1659 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1660#define EXPR(Node, Parent)
1661#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001662
Douglas Gregor43959a92009-08-20 07:17:43 +00001663 // Transform expressions by calling TransformExpr.
1664#define STMT(Node, Parent)
1665#define EXPR(Node, Parent) case Stmt::Node##Class:
1666#include "clang/AST/StmtNodes.def"
1667 {
1668 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1669 if (E.isInvalid())
1670 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001671
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001672 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674 }
1675
Douglas Gregor43959a92009-08-20 07:17:43 +00001676 return SemaRef.Owned(S->Retain());
1677}
Mike Stump1eb44332009-09-09 15:08:12 +00001678
1679
Douglas Gregor670444e2009-08-04 22:27:00 +00001680template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001681Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 if (!E)
1683 return SemaRef.Owned(E);
1684
1685 switch (E->getStmtClass()) {
1686 case Stmt::NoStmtClass: break;
1687#define STMT(Node, Parent) case Stmt::Node##Class: break;
1688#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001689 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001690#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001691 }
1692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001694}
1695
1696template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001697NestedNameSpecifier *
1698TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001699 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001700 QualType ObjectType,
1701 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001702 if (!NNS)
1703 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001704
Douglas Gregor43959a92009-08-20 07:17:43 +00001705 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001706 NestedNameSpecifier *Prefix = NNS->getPrefix();
1707 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001708 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001709 ObjectType,
1710 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001711 if (!Prefix)
1712 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001713
1714 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001715 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001716 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001717 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001718 }
Mike Stump1eb44332009-09-09 15:08:12 +00001719
Douglas Gregordcee1a12009-08-06 05:28:30 +00001720 switch (NNS->getKind()) {
1721 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001722 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001723 "Identifier nested-name-specifier with no prefix or object type");
1724 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1725 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001726 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001727
1728 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001729 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001730 ObjectType,
1731 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001732
Douglas Gregordcee1a12009-08-06 05:28:30 +00001733 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001734 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001735 = cast_or_null<NamespaceDecl>(
1736 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001737 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001738 Prefix == NNS->getPrefix() &&
1739 NS == NNS->getAsNamespace())
1740 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregordcee1a12009-08-06 05:28:30 +00001742 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1743 }
Mike Stump1eb44332009-09-09 15:08:12 +00001744
Douglas Gregordcee1a12009-08-06 05:28:30 +00001745 case NestedNameSpecifier::Global:
1746 // There is no meaningful transformation that one could perform on the
1747 // global scope.
1748 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001749
Douglas Gregordcee1a12009-08-06 05:28:30 +00001750 case NestedNameSpecifier::TypeSpecWithTemplate:
1751 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001752 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregordcee1a12009-08-06 05:28:30 +00001753 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregord1067e52009-08-06 06:41:21 +00001754 if (T.isNull())
1755 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001756
Douglas Gregordcee1a12009-08-06 05:28:30 +00001757 if (!getDerived().AlwaysRebuild() &&
1758 Prefix == NNS->getPrefix() &&
1759 T == QualType(NNS->getAsType(), 0))
1760 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001761
1762 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1763 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregordcee1a12009-08-06 05:28:30 +00001764 T);
1765 }
1766 }
Mike Stump1eb44332009-09-09 15:08:12 +00001767
Douglas Gregordcee1a12009-08-06 05:28:30 +00001768 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001769 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001770}
1771
1772template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001773DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001774TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001775 SourceLocation Loc,
1776 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001777 if (!Name)
1778 return Name;
1779
1780 switch (Name.getNameKind()) {
1781 case DeclarationName::Identifier:
1782 case DeclarationName::ObjCZeroArgSelector:
1783 case DeclarationName::ObjCOneArgSelector:
1784 case DeclarationName::ObjCMultiArgSelector:
1785 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001786 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001787 case DeclarationName::CXXUsingDirective:
1788 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregor81499bb2009-09-03 22:13:48 +00001790 case DeclarationName::CXXConstructorName:
1791 case DeclarationName::CXXDestructorName:
1792 case DeclarationName::CXXConversionFunctionName: {
1793 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregordd62b152009-10-19 22:04:39 +00001794 QualType T;
1795 if (!ObjectType.isNull() &&
1796 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1797 TemplateSpecializationType *SpecType
1798 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1799 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1800 } else
1801 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregor81499bb2009-09-03 22:13:48 +00001802 if (T.isNull())
1803 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001804
Douglas Gregor81499bb2009-09-03 22:13:48 +00001805 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001806 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001807 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001808 }
Mike Stump1eb44332009-09-09 15:08:12 +00001809 }
1810
Douglas Gregor81499bb2009-09-03 22:13:48 +00001811 return DeclarationName();
1812}
1813
1814template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001815TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001816TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1817 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001818 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001819 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001820 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1821 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1822 if (!NNS)
1823 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001824
Douglas Gregord1067e52009-08-06 06:41:21 +00001825 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001826 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001827 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1828 if (!TransTemplate)
1829 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001830
Douglas Gregord1067e52009-08-06 06:41:21 +00001831 if (!getDerived().AlwaysRebuild() &&
1832 NNS == QTN->getQualifier() &&
1833 TransTemplate == Template)
1834 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001835
Douglas Gregord1067e52009-08-06 06:41:21 +00001836 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1837 TransTemplate);
1838 }
Mike Stump1eb44332009-09-09 15:08:12 +00001839
John McCallf7a1a742009-11-24 19:00:30 +00001840 // These should be getting filtered out before they make it into the AST.
1841 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001842 }
Mike Stump1eb44332009-09-09 15:08:12 +00001843
Douglas Gregord1067e52009-08-06 06:41:21 +00001844 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001845 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001846 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1847 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001848 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001849 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001850
Douglas Gregord1067e52009-08-06 06:41:21 +00001851 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001852 NNS == DTN->getQualifier() &&
1853 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001854 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001855
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001856 if (DTN->isIdentifier())
1857 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1858 ObjectType);
1859
1860 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1861 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001862 }
Mike Stump1eb44332009-09-09 15:08:12 +00001863
Douglas Gregord1067e52009-08-06 06:41:21 +00001864 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001865 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001866 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1867 if (!TransTemplate)
1868 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001869
Douglas Gregord1067e52009-08-06 06:41:21 +00001870 if (!getDerived().AlwaysRebuild() &&
1871 TransTemplate == Template)
1872 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001873
Douglas Gregord1067e52009-08-06 06:41:21 +00001874 return TemplateName(TransTemplate);
1875 }
Mike Stump1eb44332009-09-09 15:08:12 +00001876
John McCallf7a1a742009-11-24 19:00:30 +00001877 // These should be getting filtered out before they reach the AST.
1878 assert(false && "overloaded function decl survived to here");
1879 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001880}
1881
1882template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001883void TreeTransform<Derived>::InventTemplateArgumentLoc(
1884 const TemplateArgument &Arg,
1885 TemplateArgumentLoc &Output) {
1886 SourceLocation Loc = getDerived().getBaseLocation();
1887 switch (Arg.getKind()) {
1888 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001889 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001890 break;
1891
1892 case TemplateArgument::Type:
1893 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001894 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001895
1896 break;
1897
Douglas Gregor788cd062009-11-11 01:00:40 +00001898 case TemplateArgument::Template:
1899 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1900 break;
1901
John McCall833ca992009-10-29 08:12:44 +00001902 case TemplateArgument::Expression:
1903 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1904 break;
1905
1906 case TemplateArgument::Declaration:
1907 case TemplateArgument::Integral:
1908 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001909 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001910 break;
1911 }
1912}
1913
1914template<typename Derived>
1915bool TreeTransform<Derived>::TransformTemplateArgument(
1916 const TemplateArgumentLoc &Input,
1917 TemplateArgumentLoc &Output) {
1918 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001919 switch (Arg.getKind()) {
1920 case TemplateArgument::Null:
1921 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001922 Output = Input;
1923 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001924
Douglas Gregor670444e2009-08-04 22:27:00 +00001925 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001926 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001927 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001928 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001929
1930 DI = getDerived().TransformType(DI);
1931 if (!DI) return true;
1932
1933 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1934 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001935 }
Mike Stump1eb44332009-09-09 15:08:12 +00001936
Douglas Gregor670444e2009-08-04 22:27:00 +00001937 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001938 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001939 DeclarationName Name;
1940 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1941 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001942 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001943 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001944 if (!D) return true;
1945
John McCall828bff22009-10-29 18:45:58 +00001946 Expr *SourceExpr = Input.getSourceDeclExpression();
1947 if (SourceExpr) {
1948 EnterExpressionEvaluationContext Unevaluated(getSema(),
1949 Action::Unevaluated);
1950 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1951 if (E.isInvalid())
1952 SourceExpr = NULL;
1953 else {
1954 SourceExpr = E.takeAs<Expr>();
1955 SourceExpr->Retain();
1956 }
1957 }
1958
1959 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001960 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001961 }
Mike Stump1eb44332009-09-09 15:08:12 +00001962
Douglas Gregor788cd062009-11-11 01:00:40 +00001963 case TemplateArgument::Template: {
1964 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1965 TemplateName Template
1966 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1967 if (Template.isNull())
1968 return true;
1969
1970 Output = TemplateArgumentLoc(TemplateArgument(Template),
1971 Input.getTemplateQualifierRange(),
1972 Input.getTemplateNameLoc());
1973 return false;
1974 }
1975
Douglas Gregor670444e2009-08-04 22:27:00 +00001976 case TemplateArgument::Expression: {
1977 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00001978 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001979 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00001980
John McCall833ca992009-10-29 08:12:44 +00001981 Expr *InputExpr = Input.getSourceExpression();
1982 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1983
1984 Sema::OwningExprResult E
1985 = getDerived().TransformExpr(InputExpr);
1986 if (E.isInvalid()) return true;
1987
1988 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00001989 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00001990 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1991 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001992 }
Mike Stump1eb44332009-09-09 15:08:12 +00001993
Douglas Gregor670444e2009-08-04 22:27:00 +00001994 case TemplateArgument::Pack: {
1995 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1996 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00001997 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001998 AEnd = Arg.pack_end();
1999 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002000
John McCall833ca992009-10-29 08:12:44 +00002001 // FIXME: preserve source information here when we start
2002 // caring about parameter packs.
2003
John McCall828bff22009-10-29 18:45:58 +00002004 TemplateArgumentLoc InputArg;
2005 TemplateArgumentLoc OutputArg;
2006 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2007 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002008 return true;
2009
John McCall828bff22009-10-29 18:45:58 +00002010 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002011 }
2012 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002013 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002014 true);
John McCall828bff22009-10-29 18:45:58 +00002015 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002016 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002017 }
2018 }
Mike Stump1eb44332009-09-09 15:08:12 +00002019
Douglas Gregor670444e2009-08-04 22:27:00 +00002020 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002021 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002022}
2023
Douglas Gregor577f75a2009-08-04 16:50:30 +00002024//===----------------------------------------------------------------------===//
2025// Type transformation
2026//===----------------------------------------------------------------------===//
2027
2028template<typename Derived>
2029QualType TreeTransform<Derived>::TransformType(QualType T) {
2030 if (getDerived().AlreadyTransformed(T))
2031 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002032
John McCalla2becad2009-10-21 00:40:46 +00002033 // Temporary workaround. All of these transformations should
2034 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002035 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002036 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002037
John McCalla93c9342009-12-07 02:54:59 +00002038 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002039
John McCalla2becad2009-10-21 00:40:46 +00002040 if (!NewDI)
2041 return QualType();
2042
2043 return NewDI->getType();
2044}
2045
2046template<typename Derived>
John McCalla93c9342009-12-07 02:54:59 +00002047TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002048 if (getDerived().AlreadyTransformed(DI->getType()))
2049 return DI;
2050
2051 TypeLocBuilder TLB;
2052
2053 TypeLoc TL = DI->getTypeLoc();
2054 TLB.reserve(TL.getFullDataSize());
2055
2056 QualType Result = getDerived().TransformType(TLB, TL);
2057 if (Result.isNull())
2058 return 0;
2059
John McCalla93c9342009-12-07 02:54:59 +00002060 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002061}
2062
2063template<typename Derived>
2064QualType
2065TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2066 switch (T.getTypeLocClass()) {
2067#define ABSTRACT_TYPELOC(CLASS, PARENT)
2068#define TYPELOC(CLASS, PARENT) \
2069 case TypeLoc::CLASS: \
2070 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2071#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002072 }
Mike Stump1eb44332009-09-09 15:08:12 +00002073
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002074 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002075 return QualType();
2076}
2077
2078/// FIXME: By default, this routine adds type qualifiers only to types
2079/// that can have qualifiers, and silently suppresses those qualifiers
2080/// that are not permitted (e.g., qualifiers on reference or function
2081/// types). This is the right thing for template instantiation, but
2082/// probably not for other clients.
2083template<typename Derived>
2084QualType
2085TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2086 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002087 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002088
2089 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2090 if (Result.isNull())
2091 return QualType();
2092
2093 // Silently suppress qualifiers if the result type can't be qualified.
2094 // FIXME: this is the right thing for template instantiation, but
2095 // probably not for other clients.
2096 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002097 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002098
John McCalla2becad2009-10-21 00:40:46 +00002099 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2100
2101 TLB.push<QualifiedTypeLoc>(Result);
2102
2103 // No location information to preserve.
2104
2105 return Result;
2106}
2107
2108template <class TyLoc> static inline
2109QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2110 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2111 NewT.setNameLoc(T.getNameLoc());
2112 return T.getType();
2113}
2114
2115// Ugly metaprogramming macros because I couldn't be bothered to make
2116// the equivalent template version work.
2117#define TransformPointerLikeType(TypeClass) do { \
2118 QualType PointeeType \
2119 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2120 if (PointeeType.isNull()) \
2121 return QualType(); \
2122 \
2123 QualType Result = TL.getType(); \
2124 if (getDerived().AlwaysRebuild() || \
2125 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002126 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2127 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002128 if (Result.isNull()) \
2129 return QualType(); \
2130 } \
2131 \
2132 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2133 NewT.setSigilLoc(TL.getSigilLoc()); \
2134 \
2135 return Result; \
2136} while(0)
2137
John McCalla2becad2009-10-21 00:40:46 +00002138template<typename Derived>
2139QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2140 BuiltinTypeLoc T) {
2141 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002142}
Mike Stump1eb44332009-09-09 15:08:12 +00002143
Douglas Gregor577f75a2009-08-04 16:50:30 +00002144template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002145QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2146 ComplexTypeLoc T) {
2147 // FIXME: recurse?
2148 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002149}
Mike Stump1eb44332009-09-09 15:08:12 +00002150
Douglas Gregor577f75a2009-08-04 16:50:30 +00002151template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002152QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2153 PointerTypeLoc TL) {
2154 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002155}
Mike Stump1eb44332009-09-09 15:08:12 +00002156
2157template<typename Derived>
2158QualType
John McCalla2becad2009-10-21 00:40:46 +00002159TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2160 BlockPointerTypeLoc TL) {
2161 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002162}
2163
John McCall85737a72009-10-30 00:06:24 +00002164/// Transforms a reference type. Note that somewhat paradoxically we
2165/// don't care whether the type itself is an l-value type or an r-value
2166/// type; we only care if the type was *written* as an l-value type
2167/// or an r-value type.
2168template<typename Derived>
2169QualType
2170TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2171 ReferenceTypeLoc TL) {
2172 const ReferenceType *T = TL.getTypePtr();
2173
2174 // Note that this works with the pointee-as-written.
2175 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2176 if (PointeeType.isNull())
2177 return QualType();
2178
2179 QualType Result = TL.getType();
2180 if (getDerived().AlwaysRebuild() ||
2181 PointeeType != T->getPointeeTypeAsWritten()) {
2182 Result = getDerived().RebuildReferenceType(PointeeType,
2183 T->isSpelledAsLValue(),
2184 TL.getSigilLoc());
2185 if (Result.isNull())
2186 return QualType();
2187 }
2188
2189 // r-value references can be rebuilt as l-value references.
2190 ReferenceTypeLoc NewTL;
2191 if (isa<LValueReferenceType>(Result))
2192 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2193 else
2194 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2195 NewTL.setSigilLoc(TL.getSigilLoc());
2196
2197 return Result;
2198}
2199
Mike Stump1eb44332009-09-09 15:08:12 +00002200template<typename Derived>
2201QualType
John McCalla2becad2009-10-21 00:40:46 +00002202TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2203 LValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002204 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002205}
2206
Mike Stump1eb44332009-09-09 15:08:12 +00002207template<typename Derived>
2208QualType
John McCalla2becad2009-10-21 00:40:46 +00002209TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2210 RValueReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00002211 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002212}
Mike Stump1eb44332009-09-09 15:08:12 +00002213
Douglas Gregor577f75a2009-08-04 16:50:30 +00002214template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002215QualType
John McCalla2becad2009-10-21 00:40:46 +00002216TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2217 MemberPointerTypeLoc TL) {
2218 MemberPointerType *T = TL.getTypePtr();
2219
2220 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002221 if (PointeeType.isNull())
2222 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002223
John McCalla2becad2009-10-21 00:40:46 +00002224 // TODO: preserve source information for this.
2225 QualType ClassType
2226 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002227 if (ClassType.isNull())
2228 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002229
John McCalla2becad2009-10-21 00:40:46 +00002230 QualType Result = TL.getType();
2231 if (getDerived().AlwaysRebuild() ||
2232 PointeeType != T->getPointeeType() ||
2233 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002234 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2235 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002236 if (Result.isNull())
2237 return QualType();
2238 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002239
John McCalla2becad2009-10-21 00:40:46 +00002240 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2241 NewTL.setSigilLoc(TL.getSigilLoc());
2242
2243 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002244}
2245
Mike Stump1eb44332009-09-09 15:08:12 +00002246template<typename Derived>
2247QualType
John McCalla2becad2009-10-21 00:40:46 +00002248TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2249 ConstantArrayTypeLoc TL) {
2250 ConstantArrayType *T = TL.getTypePtr();
2251 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002252 if (ElementType.isNull())
2253 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002254
John McCalla2becad2009-10-21 00:40:46 +00002255 QualType Result = TL.getType();
2256 if (getDerived().AlwaysRebuild() ||
2257 ElementType != T->getElementType()) {
2258 Result = getDerived().RebuildConstantArrayType(ElementType,
2259 T->getSizeModifier(),
2260 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002261 T->getIndexTypeCVRQualifiers(),
2262 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002263 if (Result.isNull())
2264 return QualType();
2265 }
2266
2267 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2268 NewTL.setLBracketLoc(TL.getLBracketLoc());
2269 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002270
John McCalla2becad2009-10-21 00:40:46 +00002271 Expr *Size = TL.getSizeExpr();
2272 if (Size) {
2273 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2274 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2275 }
2276 NewTL.setSizeExpr(Size);
2277
2278 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002279}
Mike Stump1eb44332009-09-09 15:08:12 +00002280
Douglas Gregor577f75a2009-08-04 16:50:30 +00002281template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002282QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002283 TypeLocBuilder &TLB,
2284 IncompleteArrayTypeLoc TL) {
2285 IncompleteArrayType *T = TL.getTypePtr();
2286 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002287 if (ElementType.isNull())
2288 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002289
John McCalla2becad2009-10-21 00:40:46 +00002290 QualType Result = TL.getType();
2291 if (getDerived().AlwaysRebuild() ||
2292 ElementType != T->getElementType()) {
2293 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002294 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002295 T->getIndexTypeCVRQualifiers(),
2296 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002297 if (Result.isNull())
2298 return QualType();
2299 }
2300
2301 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2302 NewTL.setLBracketLoc(TL.getLBracketLoc());
2303 NewTL.setRBracketLoc(TL.getRBracketLoc());
2304 NewTL.setSizeExpr(0);
2305
2306 return Result;
2307}
2308
2309template<typename Derived>
2310QualType
2311TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2312 VariableArrayTypeLoc TL) {
2313 VariableArrayType *T = TL.getTypePtr();
2314 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2315 if (ElementType.isNull())
2316 return QualType();
2317
2318 // Array bounds are not potentially evaluated contexts
2319 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2320
2321 Sema::OwningExprResult SizeResult
2322 = getDerived().TransformExpr(T->getSizeExpr());
2323 if (SizeResult.isInvalid())
2324 return QualType();
2325
2326 Expr *Size = static_cast<Expr*>(SizeResult.get());
2327
2328 QualType Result = TL.getType();
2329 if (getDerived().AlwaysRebuild() ||
2330 ElementType != T->getElementType() ||
2331 Size != T->getSizeExpr()) {
2332 Result = getDerived().RebuildVariableArrayType(ElementType,
2333 T->getSizeModifier(),
2334 move(SizeResult),
2335 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002336 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002337 if (Result.isNull())
2338 return QualType();
2339 }
2340 else SizeResult.take();
2341
2342 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2343 NewTL.setLBracketLoc(TL.getLBracketLoc());
2344 NewTL.setRBracketLoc(TL.getRBracketLoc());
2345 NewTL.setSizeExpr(Size);
2346
2347 return Result;
2348}
2349
2350template<typename Derived>
2351QualType
2352TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2353 DependentSizedArrayTypeLoc TL) {
2354 DependentSizedArrayType *T = TL.getTypePtr();
2355 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2356 if (ElementType.isNull())
2357 return QualType();
2358
2359 // Array bounds are not potentially evaluated contexts
2360 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2361
2362 Sema::OwningExprResult SizeResult
2363 = getDerived().TransformExpr(T->getSizeExpr());
2364 if (SizeResult.isInvalid())
2365 return QualType();
2366
2367 Expr *Size = static_cast<Expr*>(SizeResult.get());
2368
2369 QualType Result = TL.getType();
2370 if (getDerived().AlwaysRebuild() ||
2371 ElementType != T->getElementType() ||
2372 Size != T->getSizeExpr()) {
2373 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2374 T->getSizeModifier(),
2375 move(SizeResult),
2376 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002377 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002378 if (Result.isNull())
2379 return QualType();
2380 }
2381 else SizeResult.take();
2382
2383 // We might have any sort of array type now, but fortunately they
2384 // all have the same location layout.
2385 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2386 NewTL.setLBracketLoc(TL.getLBracketLoc());
2387 NewTL.setRBracketLoc(TL.getRBracketLoc());
2388 NewTL.setSizeExpr(Size);
2389
2390 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002391}
Mike Stump1eb44332009-09-09 15:08:12 +00002392
2393template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002394QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002395 TypeLocBuilder &TLB,
2396 DependentSizedExtVectorTypeLoc TL) {
2397 DependentSizedExtVectorType *T = TL.getTypePtr();
2398
2399 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002400 QualType ElementType = getDerived().TransformType(T->getElementType());
2401 if (ElementType.isNull())
2402 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002403
Douglas Gregor670444e2009-08-04 22:27:00 +00002404 // Vector sizes are not potentially evaluated contexts
2405 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2406
Douglas Gregor577f75a2009-08-04 16:50:30 +00002407 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2408 if (Size.isInvalid())
2409 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002410
John McCalla2becad2009-10-21 00:40:46 +00002411 QualType Result = TL.getType();
2412 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002413 ElementType != T->getElementType() ||
2414 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002415 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002416 move(Size),
2417 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002418 if (Result.isNull())
2419 return QualType();
2420 }
2421 else Size.take();
2422
2423 // Result might be dependent or not.
2424 if (isa<DependentSizedExtVectorType>(Result)) {
2425 DependentSizedExtVectorTypeLoc NewTL
2426 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2427 NewTL.setNameLoc(TL.getNameLoc());
2428 } else {
2429 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2430 NewTL.setNameLoc(TL.getNameLoc());
2431 }
2432
2433 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002434}
Mike Stump1eb44332009-09-09 15:08:12 +00002435
2436template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002437QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2438 VectorTypeLoc TL) {
2439 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002440 QualType ElementType = getDerived().TransformType(T->getElementType());
2441 if (ElementType.isNull())
2442 return QualType();
2443
John McCalla2becad2009-10-21 00:40:46 +00002444 QualType Result = TL.getType();
2445 if (getDerived().AlwaysRebuild() ||
2446 ElementType != T->getElementType()) {
2447 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2448 if (Result.isNull())
2449 return QualType();
2450 }
2451
2452 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2453 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002454
John McCalla2becad2009-10-21 00:40:46 +00002455 return Result;
2456}
2457
2458template<typename Derived>
2459QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2460 ExtVectorTypeLoc TL) {
2461 VectorType *T = TL.getTypePtr();
2462 QualType ElementType = getDerived().TransformType(T->getElementType());
2463 if (ElementType.isNull())
2464 return QualType();
2465
2466 QualType Result = TL.getType();
2467 if (getDerived().AlwaysRebuild() ||
2468 ElementType != T->getElementType()) {
2469 Result = getDerived().RebuildExtVectorType(ElementType,
2470 T->getNumElements(),
2471 /*FIXME*/ SourceLocation());
2472 if (Result.isNull())
2473 return QualType();
2474 }
2475
2476 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2477 NewTL.setNameLoc(TL.getNameLoc());
2478
2479 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002480}
Mike Stump1eb44332009-09-09 15:08:12 +00002481
2482template<typename Derived>
2483QualType
John McCalla2becad2009-10-21 00:40:46 +00002484TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2485 FunctionProtoTypeLoc TL) {
2486 FunctionProtoType *T = TL.getTypePtr();
2487 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002488 if (ResultType.isNull())
2489 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002490
John McCalla2becad2009-10-21 00:40:46 +00002491 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002492 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002493 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2494 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2495 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002496
John McCalla2becad2009-10-21 00:40:46 +00002497 QualType NewType;
2498 ParmVarDecl *NewParm;
2499
2500 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002501 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002502 assert(OldDI->getType() == T->getArgType(i));
2503
John McCalla93c9342009-12-07 02:54:59 +00002504 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002505 if (!NewDI)
2506 return QualType();
2507
2508 if (NewDI == OldDI)
2509 NewParm = OldParm;
2510 else
2511 NewParm = ParmVarDecl::Create(SemaRef.Context,
2512 OldParm->getDeclContext(),
2513 OldParm->getLocation(),
2514 OldParm->getIdentifier(),
2515 NewDI->getType(),
2516 NewDI,
2517 OldParm->getStorageClass(),
2518 /* DefArg */ NULL);
2519 NewType = NewParm->getType();
2520
2521 // Deal with the possibility that we don't have a parameter
2522 // declaration for this parameter.
2523 } else {
2524 NewParm = 0;
2525
2526 QualType OldType = T->getArgType(i);
2527 NewType = getDerived().TransformType(OldType);
2528 if (NewType.isNull())
2529 return QualType();
2530 }
2531
2532 ParamTypes.push_back(NewType);
2533 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002534 }
Mike Stump1eb44332009-09-09 15:08:12 +00002535
John McCalla2becad2009-10-21 00:40:46 +00002536 QualType Result = TL.getType();
2537 if (getDerived().AlwaysRebuild() ||
2538 ResultType != T->getResultType() ||
2539 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2540 Result = getDerived().RebuildFunctionProtoType(ResultType,
2541 ParamTypes.data(),
2542 ParamTypes.size(),
2543 T->isVariadic(),
2544 T->getTypeQuals());
2545 if (Result.isNull())
2546 return QualType();
2547 }
Mike Stump1eb44332009-09-09 15:08:12 +00002548
John McCalla2becad2009-10-21 00:40:46 +00002549 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2550 NewTL.setLParenLoc(TL.getLParenLoc());
2551 NewTL.setRParenLoc(TL.getRParenLoc());
2552 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2553 NewTL.setArg(i, ParamDecls[i]);
2554
2555 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002556}
Mike Stump1eb44332009-09-09 15:08:12 +00002557
Douglas Gregor577f75a2009-08-04 16:50:30 +00002558template<typename Derived>
2559QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002560 TypeLocBuilder &TLB,
2561 FunctionNoProtoTypeLoc TL) {
2562 FunctionNoProtoType *T = TL.getTypePtr();
2563 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2564 if (ResultType.isNull())
2565 return QualType();
2566
2567 QualType Result = TL.getType();
2568 if (getDerived().AlwaysRebuild() ||
2569 ResultType != T->getResultType())
2570 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2571
2572 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2573 NewTL.setLParenLoc(TL.getLParenLoc());
2574 NewTL.setRParenLoc(TL.getRParenLoc());
2575
2576 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002577}
Mike Stump1eb44332009-09-09 15:08:12 +00002578
John McCalled976492009-12-04 22:46:56 +00002579template<typename Derived> QualType
2580TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2581 UnresolvedUsingTypeLoc TL) {
2582 UnresolvedUsingType *T = TL.getTypePtr();
2583 Decl *D = getDerived().TransformDecl(T->getDecl());
2584 if (!D)
2585 return QualType();
2586
2587 QualType Result = TL.getType();
2588 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2589 Result = getDerived().RebuildUnresolvedUsingType(D);
2590 if (Result.isNull())
2591 return QualType();
2592 }
2593
2594 // We might get an arbitrary type spec type back. We should at
2595 // least always get a type spec type, though.
2596 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2597 NewTL.setNameLoc(TL.getNameLoc());
2598
2599 return Result;
2600}
2601
Douglas Gregor577f75a2009-08-04 16:50:30 +00002602template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002603QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2604 TypedefTypeLoc TL) {
2605 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002606 TypedefDecl *Typedef
2607 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2608 if (!Typedef)
2609 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002610
John McCalla2becad2009-10-21 00:40:46 +00002611 QualType Result = TL.getType();
2612 if (getDerived().AlwaysRebuild() ||
2613 Typedef != T->getDecl()) {
2614 Result = getDerived().RebuildTypedefType(Typedef);
2615 if (Result.isNull())
2616 return QualType();
2617 }
Mike Stump1eb44332009-09-09 15:08:12 +00002618
John McCalla2becad2009-10-21 00:40:46 +00002619 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2620 NewTL.setNameLoc(TL.getNameLoc());
2621
2622 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002623}
Mike Stump1eb44332009-09-09 15:08:12 +00002624
Douglas Gregor577f75a2009-08-04 16:50:30 +00002625template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002626QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2627 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002628 // typeof expressions are not potentially evaluated contexts
2629 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002630
John McCallcfb708c2010-01-13 20:03:27 +00002631 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002632 if (E.isInvalid())
2633 return QualType();
2634
John McCalla2becad2009-10-21 00:40:46 +00002635 QualType Result = TL.getType();
2636 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002637 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002638 Result = getDerived().RebuildTypeOfExprType(move(E));
2639 if (Result.isNull())
2640 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002641 }
John McCalla2becad2009-10-21 00:40:46 +00002642 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002643
John McCalla2becad2009-10-21 00:40:46 +00002644 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002645 NewTL.setTypeofLoc(TL.getTypeofLoc());
2646 NewTL.setLParenLoc(TL.getLParenLoc());
2647 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002648
2649 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002650}
Mike Stump1eb44332009-09-09 15:08:12 +00002651
2652template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002653QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2654 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00002655 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2656 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2657 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002658 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002659
John McCalla2becad2009-10-21 00:40:46 +00002660 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002661 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2662 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002663 if (Result.isNull())
2664 return QualType();
2665 }
Mike Stump1eb44332009-09-09 15:08:12 +00002666
John McCalla2becad2009-10-21 00:40:46 +00002667 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002668 NewTL.setTypeofLoc(TL.getTypeofLoc());
2669 NewTL.setLParenLoc(TL.getLParenLoc());
2670 NewTL.setRParenLoc(TL.getRParenLoc());
2671 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002672
2673 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002674}
Mike Stump1eb44332009-09-09 15:08:12 +00002675
2676template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002677QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2678 DecltypeTypeLoc TL) {
2679 DecltypeType *T = TL.getTypePtr();
2680
Douglas Gregor670444e2009-08-04 22:27:00 +00002681 // decltype expressions are not potentially evaluated contexts
2682 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002683
Douglas Gregor577f75a2009-08-04 16:50:30 +00002684 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2685 if (E.isInvalid())
2686 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002687
John McCalla2becad2009-10-21 00:40:46 +00002688 QualType Result = TL.getType();
2689 if (getDerived().AlwaysRebuild() ||
2690 E.get() != T->getUnderlyingExpr()) {
2691 Result = getDerived().RebuildDecltypeType(move(E));
2692 if (Result.isNull())
2693 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002694 }
John McCalla2becad2009-10-21 00:40:46 +00002695 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002696
John McCalla2becad2009-10-21 00:40:46 +00002697 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2698 NewTL.setNameLoc(TL.getNameLoc());
2699
2700 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002701}
2702
2703template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002704QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2705 RecordTypeLoc TL) {
2706 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002707 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002708 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002709 if (!Record)
2710 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002711
John McCalla2becad2009-10-21 00:40:46 +00002712 QualType Result = TL.getType();
2713 if (getDerived().AlwaysRebuild() ||
2714 Record != T->getDecl()) {
2715 Result = getDerived().RebuildRecordType(Record);
2716 if (Result.isNull())
2717 return QualType();
2718 }
Mike Stump1eb44332009-09-09 15:08:12 +00002719
John McCalla2becad2009-10-21 00:40:46 +00002720 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2721 NewTL.setNameLoc(TL.getNameLoc());
2722
2723 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002724}
Mike Stump1eb44332009-09-09 15:08:12 +00002725
2726template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002727QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2728 EnumTypeLoc TL) {
2729 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002730 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002731 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002732 if (!Enum)
2733 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002734
John McCalla2becad2009-10-21 00:40:46 +00002735 QualType Result = TL.getType();
2736 if (getDerived().AlwaysRebuild() ||
2737 Enum != T->getDecl()) {
2738 Result = getDerived().RebuildEnumType(Enum);
2739 if (Result.isNull())
2740 return QualType();
2741 }
Mike Stump1eb44332009-09-09 15:08:12 +00002742
John McCalla2becad2009-10-21 00:40:46 +00002743 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2744 NewTL.setNameLoc(TL.getNameLoc());
2745
2746 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002747}
John McCall7da24312009-09-05 00:15:47 +00002748
2749template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002750QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2751 ElaboratedTypeLoc TL) {
2752 ElaboratedType *T = TL.getTypePtr();
2753
2754 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002755 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2756 if (Underlying.isNull())
2757 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002758
John McCalla2becad2009-10-21 00:40:46 +00002759 QualType Result = TL.getType();
2760 if (getDerived().AlwaysRebuild() ||
2761 Underlying != T->getUnderlyingType()) {
2762 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2763 if (Result.isNull())
2764 return QualType();
2765 }
Mike Stump1eb44332009-09-09 15:08:12 +00002766
John McCalla2becad2009-10-21 00:40:46 +00002767 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2768 NewTL.setNameLoc(TL.getNameLoc());
2769
2770 return Result;
John McCall7da24312009-09-05 00:15:47 +00002771}
Mike Stump1eb44332009-09-09 15:08:12 +00002772
2773
Douglas Gregor577f75a2009-08-04 16:50:30 +00002774template<typename Derived>
2775QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002776 TypeLocBuilder &TLB,
2777 TemplateTypeParmTypeLoc TL) {
2778 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002779}
2780
Mike Stump1eb44332009-09-09 15:08:12 +00002781template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002782QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002783 TypeLocBuilder &TLB,
2784 SubstTemplateTypeParmTypeLoc TL) {
2785 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002786}
2787
2788template<typename Derived>
Douglas Gregordd62b152009-10-19 22:04:39 +00002789inline QualType
2790TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCalla2becad2009-10-21 00:40:46 +00002791 TypeLocBuilder &TLB,
2792 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00002793 return TransformTemplateSpecializationType(TLB, TL, QualType());
2794}
John McCalla2becad2009-10-21 00:40:46 +00002795
John McCall833ca992009-10-29 08:12:44 +00002796template<typename Derived>
2797QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2798 const TemplateSpecializationType *TST,
2799 QualType ObjectType) {
2800 // FIXME: this entire method is a temporary workaround; callers
2801 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002802
John McCall833ca992009-10-29 08:12:44 +00002803 // Fake up a TemplateSpecializationTypeLoc.
2804 TypeLocBuilder TLB;
2805 TemplateSpecializationTypeLoc TL
2806 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2807
John McCall828bff22009-10-29 18:45:58 +00002808 SourceLocation BaseLoc = getDerived().getBaseLocation();
2809
2810 TL.setTemplateNameLoc(BaseLoc);
2811 TL.setLAngleLoc(BaseLoc);
2812 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002813 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2814 const TemplateArgument &TA = TST->getArg(i);
2815 TemplateArgumentLoc TAL;
2816 getDerived().InventTemplateArgumentLoc(TA, TAL);
2817 TL.setArgLocInfo(i, TAL.getLocInfo());
2818 }
2819
2820 TypeLocBuilder IgnoredTLB;
2821 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002822}
2823
2824template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002825QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002826 TypeLocBuilder &TLB,
2827 TemplateSpecializationTypeLoc TL,
2828 QualType ObjectType) {
2829 const TemplateSpecializationType *T = TL.getTypePtr();
2830
Mike Stump1eb44332009-09-09 15:08:12 +00002831 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002832 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002833 if (Template.isNull())
2834 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002835
John McCalld5532b62009-11-23 01:53:49 +00002836 TemplateArgumentListInfo NewTemplateArgs;
2837 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2838 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2839
2840 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2841 TemplateArgumentLoc Loc;
2842 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002843 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002844 NewTemplateArgs.addArgument(Loc);
2845 }
Mike Stump1eb44332009-09-09 15:08:12 +00002846
John McCall833ca992009-10-29 08:12:44 +00002847 // FIXME: maybe don't rebuild if all the template arguments are the same.
2848
2849 QualType Result =
2850 getDerived().RebuildTemplateSpecializationType(Template,
2851 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002852 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002853
2854 if (!Result.isNull()) {
2855 TemplateSpecializationTypeLoc NewTL
2856 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2857 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2858 NewTL.setLAngleLoc(TL.getLAngleLoc());
2859 NewTL.setRAngleLoc(TL.getRAngleLoc());
2860 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2861 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002862 }
Mike Stump1eb44332009-09-09 15:08:12 +00002863
John McCall833ca992009-10-29 08:12:44 +00002864 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002865}
Mike Stump1eb44332009-09-09 15:08:12 +00002866
2867template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002868QualType
2869TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2870 QualifiedNameTypeLoc TL) {
2871 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002872 NestedNameSpecifier *NNS
2873 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2874 SourceRange());
2875 if (!NNS)
2876 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002877
Douglas Gregor577f75a2009-08-04 16:50:30 +00002878 QualType Named = getDerived().TransformType(T->getNamedType());
2879 if (Named.isNull())
2880 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002881
John McCalla2becad2009-10-21 00:40:46 +00002882 QualType Result = TL.getType();
2883 if (getDerived().AlwaysRebuild() ||
2884 NNS != T->getQualifier() ||
2885 Named != T->getNamedType()) {
2886 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2887 if (Result.isNull())
2888 return QualType();
2889 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002890
John McCalla2becad2009-10-21 00:40:46 +00002891 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2892 NewTL.setNameLoc(TL.getNameLoc());
2893
2894 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002895}
Mike Stump1eb44332009-09-09 15:08:12 +00002896
2897template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002898QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2899 TypenameTypeLoc TL) {
2900 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002901
2902 /* FIXME: preserve source information better than this */
2903 SourceRange SR(TL.getNameLoc());
2904
Douglas Gregor577f75a2009-08-04 16:50:30 +00002905 NestedNameSpecifier *NNS
John McCall833ca992009-10-29 08:12:44 +00002906 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002907 if (!NNS)
2908 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002909
John McCalla2becad2009-10-21 00:40:46 +00002910 QualType Result;
2911
Douglas Gregor577f75a2009-08-04 16:50:30 +00002912 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002913 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002914 = getDerived().TransformType(QualType(TemplateId, 0));
2915 if (NewTemplateId.isNull())
2916 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002917
Douglas Gregor577f75a2009-08-04 16:50:30 +00002918 if (!getDerived().AlwaysRebuild() &&
2919 NNS == T->getQualifier() &&
2920 NewTemplateId == QualType(TemplateId, 0))
2921 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002922
John McCalla2becad2009-10-21 00:40:46 +00002923 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2924 } else {
John McCall833ca992009-10-29 08:12:44 +00002925 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002926 }
John McCalla2becad2009-10-21 00:40:46 +00002927 if (Result.isNull())
2928 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002929
John McCalla2becad2009-10-21 00:40:46 +00002930 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2931 NewTL.setNameLoc(TL.getNameLoc());
2932
2933 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002934}
Mike Stump1eb44332009-09-09 15:08:12 +00002935
Douglas Gregor577f75a2009-08-04 16:50:30 +00002936template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002937QualType
2938TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2939 ObjCInterfaceTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002940 assert(false && "TransformObjCInterfaceType unimplemented");
2941 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002942}
Mike Stump1eb44332009-09-09 15:08:12 +00002943
2944template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002945QualType
2946TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2947 ObjCObjectPointerTypeLoc TL) {
John McCall54e14c42009-10-22 22:37:11 +00002948 assert(false && "TransformObjCObjectPointerType unimplemented");
2949 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00002950}
2951
Douglas Gregor577f75a2009-08-04 16:50:30 +00002952//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00002953// Statement transformation
2954//===----------------------------------------------------------------------===//
2955template<typename Derived>
2956Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002957TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2958 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002959}
2960
2961template<typename Derived>
2962Sema::OwningStmtResult
2963TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2964 return getDerived().TransformCompoundStmt(S, false);
2965}
2966
2967template<typename Derived>
2968Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002969TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00002970 bool IsStmtExpr) {
2971 bool SubStmtChanged = false;
2972 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2973 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2974 B != BEnd; ++B) {
2975 OwningStmtResult Result = getDerived().TransformStmt(*B);
2976 if (Result.isInvalid())
2977 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002978
Douglas Gregor43959a92009-08-20 07:17:43 +00002979 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2980 Statements.push_back(Result.takeAs<Stmt>());
2981 }
Mike Stump1eb44332009-09-09 15:08:12 +00002982
Douglas Gregor43959a92009-08-20 07:17:43 +00002983 if (!getDerived().AlwaysRebuild() &&
2984 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00002985 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00002986
2987 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2988 move_arg(Statements),
2989 S->getRBracLoc(),
2990 IsStmtExpr);
2991}
Mike Stump1eb44332009-09-09 15:08:12 +00002992
Douglas Gregor43959a92009-08-20 07:17:43 +00002993template<typename Derived>
2994Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00002995TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00002996 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2997 {
2998 // The case value expressions are not potentially evaluated.
2999 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003000
Eli Friedman264c1f82009-11-19 03:14:00 +00003001 // Transform the left-hand case value.
3002 LHS = getDerived().TransformExpr(S->getLHS());
3003 if (LHS.isInvalid())
3004 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003005
Eli Friedman264c1f82009-11-19 03:14:00 +00003006 // Transform the right-hand case value (for the GNU case-range extension).
3007 RHS = getDerived().TransformExpr(S->getRHS());
3008 if (RHS.isInvalid())
3009 return SemaRef.StmtError();
3010 }
Mike Stump1eb44332009-09-09 15:08:12 +00003011
Douglas Gregor43959a92009-08-20 07:17:43 +00003012 // Build the case statement.
3013 // Case statements are always rebuilt so that they will attached to their
3014 // transformed switch statement.
3015 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3016 move(LHS),
3017 S->getEllipsisLoc(),
3018 move(RHS),
3019 S->getColonLoc());
3020 if (Case.isInvalid())
3021 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003022
Douglas Gregor43959a92009-08-20 07:17:43 +00003023 // Transform the statement following the case
3024 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3025 if (SubStmt.isInvalid())
3026 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003027
Douglas Gregor43959a92009-08-20 07:17:43 +00003028 // Attach the body to the case statement
3029 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3030}
3031
3032template<typename Derived>
3033Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003034TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003035 // Transform the statement following the default case
3036 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3037 if (SubStmt.isInvalid())
3038 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003039
Douglas Gregor43959a92009-08-20 07:17:43 +00003040 // Default statements are always rebuilt
3041 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3042 move(SubStmt));
3043}
Mike Stump1eb44332009-09-09 15:08:12 +00003044
Douglas Gregor43959a92009-08-20 07:17:43 +00003045template<typename Derived>
3046Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003047TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003048 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3049 if (SubStmt.isInvalid())
3050 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003051
Douglas Gregor43959a92009-08-20 07:17:43 +00003052 // FIXME: Pass the real colon location in.
3053 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3054 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3055 move(SubStmt));
3056}
Mike Stump1eb44332009-09-09 15:08:12 +00003057
Douglas Gregor43959a92009-08-20 07:17:43 +00003058template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003059Sema::OwningStmtResult
3060TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003061 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003062 OwningExprResult Cond(SemaRef);
3063 VarDecl *ConditionVar = 0;
3064 if (S->getConditionVariable()) {
3065 ConditionVar
3066 = cast_or_null<VarDecl>(
3067 getDerived().TransformDefinition(S->getConditionVariable()));
3068 if (!ConditionVar)
3069 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003070 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003071 Cond = getDerived().TransformExpr(S->getCond());
3072
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003073 if (Cond.isInvalid())
3074 return SemaRef.StmtError();
3075 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003076
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003077 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003078
Douglas Gregor43959a92009-08-20 07:17:43 +00003079 // Transform the "then" branch.
3080 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3081 if (Then.isInvalid())
3082 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003083
Douglas Gregor43959a92009-08-20 07:17:43 +00003084 // Transform the "else" branch.
3085 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3086 if (Else.isInvalid())
3087 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003088
Douglas Gregor43959a92009-08-20 07:17:43 +00003089 if (!getDerived().AlwaysRebuild() &&
3090 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003091 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003092 Then.get() == S->getThen() &&
3093 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003094 return SemaRef.Owned(S->Retain());
3095
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003096 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3097 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003098 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003099}
3100
3101template<typename Derived>
3102Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003103TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003104 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003105 OwningExprResult Cond(SemaRef);
3106 VarDecl *ConditionVar = 0;
3107 if (S->getConditionVariable()) {
3108 ConditionVar
3109 = cast_or_null<VarDecl>(
3110 getDerived().TransformDefinition(S->getConditionVariable()));
3111 if (!ConditionVar)
3112 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003113 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003114 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003115
3116 if (Cond.isInvalid())
3117 return SemaRef.StmtError();
3118 }
Mike Stump1eb44332009-09-09 15:08:12 +00003119
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003120 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003121
Douglas Gregor43959a92009-08-20 07:17:43 +00003122 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003123 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3124 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003125 if (Switch.isInvalid())
3126 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003127
Douglas Gregor43959a92009-08-20 07:17:43 +00003128 // Transform the body of the switch statement.
3129 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3130 if (Body.isInvalid())
3131 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003132
Douglas Gregor43959a92009-08-20 07:17:43 +00003133 // Complete the switch statement.
3134 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3135 move(Body));
3136}
Mike Stump1eb44332009-09-09 15:08:12 +00003137
Douglas Gregor43959a92009-08-20 07:17:43 +00003138template<typename Derived>
3139Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003140TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003141 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003142 OwningExprResult Cond(SemaRef);
3143 VarDecl *ConditionVar = 0;
3144 if (S->getConditionVariable()) {
3145 ConditionVar
3146 = cast_or_null<VarDecl>(
3147 getDerived().TransformDefinition(S->getConditionVariable()));
3148 if (!ConditionVar)
3149 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003150 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003151 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003152
3153 if (Cond.isInvalid())
3154 return SemaRef.StmtError();
3155 }
Mike Stump1eb44332009-09-09 15:08:12 +00003156
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003157 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003158
Douglas Gregor43959a92009-08-20 07:17:43 +00003159 // Transform the body
3160 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3161 if (Body.isInvalid())
3162 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003163
Douglas Gregor43959a92009-08-20 07:17:43 +00003164 if (!getDerived().AlwaysRebuild() &&
3165 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003166 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003167 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003168 return SemaRef.Owned(S->Retain());
3169
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003170 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3171 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003172}
Mike Stump1eb44332009-09-09 15:08:12 +00003173
Douglas Gregor43959a92009-08-20 07:17:43 +00003174template<typename Derived>
3175Sema::OwningStmtResult
3176TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3177 // Transform the condition
3178 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3179 if (Cond.isInvalid())
3180 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003181
Douglas Gregor43959a92009-08-20 07:17:43 +00003182 // Transform the body
3183 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3184 if (Body.isInvalid())
3185 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003186
Douglas Gregor43959a92009-08-20 07:17:43 +00003187 if (!getDerived().AlwaysRebuild() &&
3188 Cond.get() == S->getCond() &&
3189 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003190 return SemaRef.Owned(S->Retain());
3191
Douglas Gregor43959a92009-08-20 07:17:43 +00003192 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3193 /*FIXME:*/S->getWhileLoc(), move(Cond),
3194 S->getRParenLoc());
3195}
Mike Stump1eb44332009-09-09 15:08:12 +00003196
Douglas Gregor43959a92009-08-20 07:17:43 +00003197template<typename Derived>
3198Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003199TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003200 // Transform the initialization statement
3201 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3202 if (Init.isInvalid())
3203 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003204
Douglas Gregor43959a92009-08-20 07:17:43 +00003205 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003206 OwningExprResult Cond(SemaRef);
3207 VarDecl *ConditionVar = 0;
3208 if (S->getConditionVariable()) {
3209 ConditionVar
3210 = cast_or_null<VarDecl>(
3211 getDerived().TransformDefinition(S->getConditionVariable()));
3212 if (!ConditionVar)
3213 return SemaRef.StmtError();
3214 } else {
3215 Cond = getDerived().TransformExpr(S->getCond());
3216
3217 if (Cond.isInvalid())
3218 return SemaRef.StmtError();
3219 }
Mike Stump1eb44332009-09-09 15:08:12 +00003220
Douglas Gregor43959a92009-08-20 07:17:43 +00003221 // Transform the increment
3222 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3223 if (Inc.isInvalid())
3224 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003225
Douglas Gregor43959a92009-08-20 07:17:43 +00003226 // Transform the body
3227 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3228 if (Body.isInvalid())
3229 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003230
Douglas Gregor43959a92009-08-20 07:17:43 +00003231 if (!getDerived().AlwaysRebuild() &&
3232 Init.get() == S->getInit() &&
3233 Cond.get() == S->getCond() &&
3234 Inc.get() == S->getInc() &&
3235 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003236 return SemaRef.Owned(S->Retain());
3237
Douglas Gregor43959a92009-08-20 07:17:43 +00003238 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003239 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003240 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003241 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003242 S->getRParenLoc(), move(Body));
3243}
3244
3245template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003246Sema::OwningStmtResult
3247TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003248 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003249 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003250 S->getLabel());
3251}
3252
3253template<typename Derived>
3254Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003255TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003256 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3257 if (Target.isInvalid())
3258 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003259
Douglas Gregor43959a92009-08-20 07:17:43 +00003260 if (!getDerived().AlwaysRebuild() &&
3261 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003262 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003263
3264 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3265 move(Target));
3266}
3267
3268template<typename Derived>
3269Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003270TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3271 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003272}
Mike Stump1eb44332009-09-09 15:08:12 +00003273
Douglas Gregor43959a92009-08-20 07:17:43 +00003274template<typename Derived>
3275Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003276TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3277 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003278}
Mike Stump1eb44332009-09-09 15:08:12 +00003279
Douglas Gregor43959a92009-08-20 07:17:43 +00003280template<typename Derived>
3281Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003282TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003283 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3284 if (Result.isInvalid())
3285 return SemaRef.StmtError();
3286
Mike Stump1eb44332009-09-09 15:08:12 +00003287 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003288 // to tell whether the return type of the function has changed.
3289 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3290}
Mike Stump1eb44332009-09-09 15:08:12 +00003291
Douglas Gregor43959a92009-08-20 07:17:43 +00003292template<typename Derived>
3293Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003294TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003295 bool DeclChanged = false;
3296 llvm::SmallVector<Decl *, 4> Decls;
3297 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3298 D != DEnd; ++D) {
3299 Decl *Transformed = getDerived().TransformDefinition(*D);
3300 if (!Transformed)
3301 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003302
Douglas Gregor43959a92009-08-20 07:17:43 +00003303 if (Transformed != *D)
3304 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003305
Douglas Gregor43959a92009-08-20 07:17:43 +00003306 Decls.push_back(Transformed);
3307 }
Mike Stump1eb44332009-09-09 15:08:12 +00003308
Douglas Gregor43959a92009-08-20 07:17:43 +00003309 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003310 return SemaRef.Owned(S->Retain());
3311
3312 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003313 S->getStartLoc(), S->getEndLoc());
3314}
Mike Stump1eb44332009-09-09 15:08:12 +00003315
Douglas Gregor43959a92009-08-20 07:17:43 +00003316template<typename Derived>
3317Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003318TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003319 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003320 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003321}
3322
3323template<typename Derived>
3324Sema::OwningStmtResult
3325TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3326 // FIXME: Implement!
3327 assert(false && "Inline assembly cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003328 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003329}
3330
3331
3332template<typename Derived>
3333Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003334TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003335 // FIXME: Implement this
3336 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003337 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003338}
Mike Stump1eb44332009-09-09 15:08:12 +00003339
Douglas Gregor43959a92009-08-20 07:17:43 +00003340template<typename Derived>
3341Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003342TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003343 // FIXME: Implement this
3344 assert(false && "Cannot transform an Objective-C @catch statement");
3345 return SemaRef.Owned(S->Retain());
3346}
Mike Stump1eb44332009-09-09 15:08:12 +00003347
Douglas Gregor43959a92009-08-20 07:17:43 +00003348template<typename Derived>
3349Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003350TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003351 // FIXME: Implement this
3352 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003353 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003354}
Mike Stump1eb44332009-09-09 15:08:12 +00003355
Douglas Gregor43959a92009-08-20 07:17:43 +00003356template<typename Derived>
3357Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003358TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003359 // FIXME: Implement this
3360 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003361 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003362}
Mike Stump1eb44332009-09-09 15:08:12 +00003363
Douglas Gregor43959a92009-08-20 07:17:43 +00003364template<typename Derived>
3365Sema::OwningStmtResult
3366TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003367 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003368 // FIXME: Implement this
3369 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003370 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003371}
3372
3373template<typename Derived>
3374Sema::OwningStmtResult
3375TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003376 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003377 // FIXME: Implement this
3378 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003379 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003380}
3381
3382
3383template<typename Derived>
3384Sema::OwningStmtResult
3385TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3386 // Transform the exception declaration, if any.
3387 VarDecl *Var = 0;
3388 if (S->getExceptionDecl()) {
3389 VarDecl *ExceptionDecl = S->getExceptionDecl();
3390 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3391 ExceptionDecl->getDeclName());
3392
3393 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3394 if (T.isNull())
3395 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003396
Douglas Gregor43959a92009-08-20 07:17:43 +00003397 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3398 T,
John McCalla93c9342009-12-07 02:54:59 +00003399 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003400 ExceptionDecl->getIdentifier(),
3401 ExceptionDecl->getLocation(),
3402 /*FIXME: Inaccurate*/
3403 SourceRange(ExceptionDecl->getLocation()));
3404 if (!Var || Var->isInvalidDecl()) {
3405 if (Var)
3406 Var->Destroy(SemaRef.Context);
3407 return SemaRef.StmtError();
3408 }
3409 }
Mike Stump1eb44332009-09-09 15:08:12 +00003410
Douglas Gregor43959a92009-08-20 07:17:43 +00003411 // Transform the actual exception handler.
3412 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3413 if (Handler.isInvalid()) {
3414 if (Var)
3415 Var->Destroy(SemaRef.Context);
3416 return SemaRef.StmtError();
3417 }
Mike Stump1eb44332009-09-09 15:08:12 +00003418
Douglas Gregor43959a92009-08-20 07:17:43 +00003419 if (!getDerived().AlwaysRebuild() &&
3420 !Var &&
3421 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003422 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003423
3424 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3425 Var,
3426 move(Handler));
3427}
Mike Stump1eb44332009-09-09 15:08:12 +00003428
Douglas Gregor43959a92009-08-20 07:17:43 +00003429template<typename Derived>
3430Sema::OwningStmtResult
3431TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3432 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003433 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003434 = getDerived().TransformCompoundStmt(S->getTryBlock());
3435 if (TryBlock.isInvalid())
3436 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003437
Douglas Gregor43959a92009-08-20 07:17:43 +00003438 // Transform the handlers.
3439 bool HandlerChanged = false;
3440 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3441 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003442 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003443 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3444 if (Handler.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003446
Douglas Gregor43959a92009-08-20 07:17:43 +00003447 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3448 Handlers.push_back(Handler.takeAs<Stmt>());
3449 }
Mike Stump1eb44332009-09-09 15:08:12 +00003450
Douglas Gregor43959a92009-08-20 07:17:43 +00003451 if (!getDerived().AlwaysRebuild() &&
3452 TryBlock.get() == S->getTryBlock() &&
3453 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003454 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003455
3456 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003457 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003458}
Mike Stump1eb44332009-09-09 15:08:12 +00003459
Douglas Gregor43959a92009-08-20 07:17:43 +00003460//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003461// Expression transformation
3462//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003463template<typename Derived>
3464Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003465TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003466 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003467}
Mike Stump1eb44332009-09-09 15:08:12 +00003468
3469template<typename Derived>
3470Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003471TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003472 NestedNameSpecifier *Qualifier = 0;
3473 if (E->getQualifier()) {
3474 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3475 E->getQualifierRange());
3476 if (!Qualifier)
3477 return SemaRef.ExprError();
3478 }
John McCalldbd872f2009-12-08 09:08:17 +00003479
3480 ValueDecl *ND
3481 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003482 if (!ND)
3483 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003484
Douglas Gregora2813ce2009-10-23 18:54:35 +00003485 if (!getDerived().AlwaysRebuild() &&
3486 Qualifier == E->getQualifier() &&
3487 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003488 !E->hasExplicitTemplateArgumentList()) {
3489
3490 // Mark it referenced in the new context regardless.
3491 // FIXME: this is a bit instantiation-specific.
3492 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3493
Mike Stump1eb44332009-09-09 15:08:12 +00003494 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003495 }
John McCalldbd872f2009-12-08 09:08:17 +00003496
3497 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3498 if (E->hasExplicitTemplateArgumentList()) {
3499 TemplateArgs = &TransArgs;
3500 TransArgs.setLAngleLoc(E->getLAngleLoc());
3501 TransArgs.setRAngleLoc(E->getRAngleLoc());
3502 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3503 TemplateArgumentLoc Loc;
3504 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3505 return SemaRef.ExprError();
3506 TransArgs.addArgument(Loc);
3507 }
3508 }
3509
Douglas Gregora2813ce2009-10-23 18:54:35 +00003510 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003511 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003512}
Mike Stump1eb44332009-09-09 15:08:12 +00003513
Douglas Gregorb98b1992009-08-11 05:31:07 +00003514template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003515Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003516TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003517 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003518}
Mike Stump1eb44332009-09-09 15:08:12 +00003519
Douglas Gregorb98b1992009-08-11 05:31:07 +00003520template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003521Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003522TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003523 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003524}
Mike Stump1eb44332009-09-09 15:08:12 +00003525
Douglas Gregorb98b1992009-08-11 05:31:07 +00003526template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003527Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003528TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003529 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003530}
Mike Stump1eb44332009-09-09 15:08:12 +00003531
Douglas Gregorb98b1992009-08-11 05:31:07 +00003532template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003533Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003534TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003535 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003536}
Mike Stump1eb44332009-09-09 15:08:12 +00003537
Douglas Gregorb98b1992009-08-11 05:31:07 +00003538template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003539Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003540TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003541 return SemaRef.Owned(E->Retain());
3542}
3543
3544template<typename Derived>
3545Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003546TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003547 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3548 if (SubExpr.isInvalid())
3549 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003550
Douglas Gregorb98b1992009-08-11 05:31:07 +00003551 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003552 return SemaRef.Owned(E->Retain());
3553
3554 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003555 E->getRParen());
3556}
3557
Mike Stump1eb44332009-09-09 15:08:12 +00003558template<typename Derived>
3559Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003560TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3561 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003562 if (SubExpr.isInvalid())
3563 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregorb98b1992009-08-11 05:31:07 +00003565 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003566 return SemaRef.Owned(E->Retain());
3567
Douglas Gregorb98b1992009-08-11 05:31:07 +00003568 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3569 E->getOpcode(),
3570 move(SubExpr));
3571}
Mike Stump1eb44332009-09-09 15:08:12 +00003572
Douglas Gregorb98b1992009-08-11 05:31:07 +00003573template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003574Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003575TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003576 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003577 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003578
John McCalla93c9342009-12-07 02:54:59 +00003579 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003580 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003581 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003582
John McCall5ab75172009-11-04 07:28:41 +00003583 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003584 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003585
John McCall5ab75172009-11-04 07:28:41 +00003586 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003587 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003588 E->getSourceRange());
3589 }
Mike Stump1eb44332009-09-09 15:08:12 +00003590
Douglas Gregorb98b1992009-08-11 05:31:07 +00003591 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003592 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003593 // C++0x [expr.sizeof]p1:
3594 // The operand is either an expression, which is an unevaluated operand
3595 // [...]
3596 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003597
Douglas Gregorb98b1992009-08-11 05:31:07 +00003598 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3599 if (SubExpr.isInvalid())
3600 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003601
Douglas Gregorb98b1992009-08-11 05:31:07 +00003602 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3603 return SemaRef.Owned(E->Retain());
3604 }
Mike Stump1eb44332009-09-09 15:08:12 +00003605
Douglas Gregorb98b1992009-08-11 05:31:07 +00003606 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3607 E->isSizeOf(),
3608 E->getSourceRange());
3609}
Mike Stump1eb44332009-09-09 15:08:12 +00003610
Douglas Gregorb98b1992009-08-11 05:31:07 +00003611template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003612Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003613TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003614 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3615 if (LHS.isInvalid())
3616 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003617
Douglas Gregorb98b1992009-08-11 05:31:07 +00003618 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3619 if (RHS.isInvalid())
3620 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003621
3622
Douglas Gregorb98b1992009-08-11 05:31:07 +00003623 if (!getDerived().AlwaysRebuild() &&
3624 LHS.get() == E->getLHS() &&
3625 RHS.get() == E->getRHS())
3626 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003627
Douglas Gregorb98b1992009-08-11 05:31:07 +00003628 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3629 /*FIXME:*/E->getLHS()->getLocStart(),
3630 move(RHS),
3631 E->getRBracketLoc());
3632}
Mike Stump1eb44332009-09-09 15:08:12 +00003633
3634template<typename Derived>
3635Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003636TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003637 // Transform the callee.
3638 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3639 if (Callee.isInvalid())
3640 return SemaRef.ExprError();
3641
3642 // Transform arguments.
3643 bool ArgChanged = false;
3644 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3645 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3646 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3647 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3648 if (Arg.isInvalid())
3649 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003650
Douglas Gregorb98b1992009-08-11 05:31:07 +00003651 // FIXME: Wrong source location information for the ','.
3652 FakeCommaLocs.push_back(
3653 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003654
3655 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003656 Args.push_back(Arg.takeAs<Expr>());
3657 }
Mike Stump1eb44332009-09-09 15:08:12 +00003658
Douglas Gregorb98b1992009-08-11 05:31:07 +00003659 if (!getDerived().AlwaysRebuild() &&
3660 Callee.get() == E->getCallee() &&
3661 !ArgChanged)
3662 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003663
Douglas Gregorb98b1992009-08-11 05:31:07 +00003664 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003665 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003666 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3667 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3668 move_arg(Args),
3669 FakeCommaLocs.data(),
3670 E->getRParenLoc());
3671}
Mike Stump1eb44332009-09-09 15:08:12 +00003672
3673template<typename Derived>
3674Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003675TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003676 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3677 if (Base.isInvalid())
3678 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003679
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003680 NestedNameSpecifier *Qualifier = 0;
3681 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003682 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003683 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3684 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003685 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003686 return SemaRef.ExprError();
3687 }
Mike Stump1eb44332009-09-09 15:08:12 +00003688
Eli Friedmanf595cc42009-12-04 06:40:45 +00003689 ValueDecl *Member
3690 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003691 if (!Member)
3692 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregorb98b1992009-08-11 05:31:07 +00003694 if (!getDerived().AlwaysRebuild() &&
3695 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003696 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003697 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003698 !E->hasExplicitTemplateArgumentList()) {
3699
3700 // Mark it referenced in the new context regardless.
3701 // FIXME: this is a bit instantiation-specific.
3702 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003703 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003704 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003705
John McCalld5532b62009-11-23 01:53:49 +00003706 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003707 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003708 TransArgs.setLAngleLoc(E->getLAngleLoc());
3709 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003710 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003711 TemplateArgumentLoc Loc;
3712 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003713 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003714 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003715 }
3716 }
3717
Douglas Gregorb98b1992009-08-11 05:31:07 +00003718 // FIXME: Bogus source location for the operator
3719 SourceLocation FakeOperatorLoc
3720 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3721
John McCallc2233c52010-01-15 08:34:02 +00003722 // FIXME: to do this check properly, we will need to preserve the
3723 // first-qualifier-in-scope here, just in case we had a dependent
3724 // base (and therefore couldn't do the check) and a
3725 // nested-name-qualifier (and therefore could do the lookup).
3726 NamedDecl *FirstQualifierInScope = 0;
3727
Douglas Gregorb98b1992009-08-11 05:31:07 +00003728 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3729 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003730 Qualifier,
3731 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003732 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003733 Member,
John McCalld5532b62009-11-23 01:53:49 +00003734 (E->hasExplicitTemplateArgumentList()
3735 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003736 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003737}
Mike Stump1eb44332009-09-09 15:08:12 +00003738
Douglas Gregorb98b1992009-08-11 05:31:07 +00003739template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003740Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003741TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003742 assert(false && "Cannot transform abstract class");
3743 return SemaRef.Owned(E->Retain());
3744}
3745
3746template<typename Derived>
3747Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003748TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003749 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3750 if (LHS.isInvalid())
3751 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003752
Douglas Gregorb98b1992009-08-11 05:31:07 +00003753 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3754 if (RHS.isInvalid())
3755 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003756
Douglas Gregorb98b1992009-08-11 05:31:07 +00003757 if (!getDerived().AlwaysRebuild() &&
3758 LHS.get() == E->getLHS() &&
3759 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003760 return SemaRef.Owned(E->Retain());
3761
Douglas Gregorb98b1992009-08-11 05:31:07 +00003762 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3763 move(LHS), move(RHS));
3764}
3765
Mike Stump1eb44332009-09-09 15:08:12 +00003766template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003767Sema::OwningExprResult
3768TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003769 CompoundAssignOperator *E) {
3770 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003771}
Mike Stump1eb44332009-09-09 15:08:12 +00003772
Douglas Gregorb98b1992009-08-11 05:31:07 +00003773template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003774Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003775TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003776 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3777 if (Cond.isInvalid())
3778 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003779
Douglas Gregorb98b1992009-08-11 05:31:07 +00003780 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3781 if (LHS.isInvalid())
3782 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003783
Douglas Gregorb98b1992009-08-11 05:31:07 +00003784 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3785 if (RHS.isInvalid())
3786 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003787
Douglas Gregorb98b1992009-08-11 05:31:07 +00003788 if (!getDerived().AlwaysRebuild() &&
3789 Cond.get() == E->getCond() &&
3790 LHS.get() == E->getLHS() &&
3791 RHS.get() == E->getRHS())
3792 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003793
3794 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003795 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003796 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003797 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003798 move(RHS));
3799}
Mike Stump1eb44332009-09-09 15:08:12 +00003800
3801template<typename Derived>
3802Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003803TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003804 // Implicit casts are eliminated during transformation, since they
3805 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003806 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003807}
Mike Stump1eb44332009-09-09 15:08:12 +00003808
Douglas Gregorb98b1992009-08-11 05:31:07 +00003809template<typename Derived>
3810Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003811TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003812 assert(false && "Cannot transform abstract class");
3813 return SemaRef.Owned(E->Retain());
3814}
3815
3816template<typename Derived>
3817Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003818TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003819 TypeSourceInfo *OldT;
3820 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003821 {
3822 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003823 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003824 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3825 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003826
John McCall9d125032010-01-15 18:39:57 +00003827 OldT = E->getTypeInfoAsWritten();
3828 NewT = getDerived().TransformType(OldT);
3829 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003830 return SemaRef.ExprError();
3831 }
Mike Stump1eb44332009-09-09 15:08:12 +00003832
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003833 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003834 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003835 if (SubExpr.isInvalid())
3836 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003837
Douglas Gregorb98b1992009-08-11 05:31:07 +00003838 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00003839 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003840 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003841 return SemaRef.Owned(E->Retain());
3842
John McCall9d125032010-01-15 18:39:57 +00003843 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3844 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003845 E->getRParenLoc(),
3846 move(SubExpr));
3847}
Mike Stump1eb44332009-09-09 15:08:12 +00003848
Douglas Gregorb98b1992009-08-11 05:31:07 +00003849template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003850Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003851TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003852 QualType T;
3853 {
3854 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003855 SourceLocation FakeTypeLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003856 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3857 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003858
Douglas Gregorb98b1992009-08-11 05:31:07 +00003859 T = getDerived().TransformType(E->getType());
3860 if (T.isNull())
3861 return SemaRef.ExprError();
3862 }
Mike Stump1eb44332009-09-09 15:08:12 +00003863
Douglas Gregorb98b1992009-08-11 05:31:07 +00003864 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3865 if (Init.isInvalid())
3866 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868 if (!getDerived().AlwaysRebuild() &&
3869 T == E->getType() &&
3870 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003871 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003872
3873 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3874 /*FIXME:*/E->getInitializer()->getLocEnd(),
3875 move(Init));
3876}
Mike Stump1eb44332009-09-09 15:08:12 +00003877
Douglas Gregorb98b1992009-08-11 05:31:07 +00003878template<typename Derived>
3879Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003880TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003881 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3882 if (Base.isInvalid())
3883 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003884
Douglas Gregorb98b1992009-08-11 05:31:07 +00003885 if (!getDerived().AlwaysRebuild() &&
3886 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003887 return SemaRef.Owned(E->Retain());
3888
Douglas Gregorb98b1992009-08-11 05:31:07 +00003889 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00003890 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003891 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3892 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3893 E->getAccessorLoc(),
3894 E->getAccessor());
3895}
Mike Stump1eb44332009-09-09 15:08:12 +00003896
Douglas Gregorb98b1992009-08-11 05:31:07 +00003897template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003898Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003899TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003900 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00003901
Douglas Gregorb98b1992009-08-11 05:31:07 +00003902 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3903 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3904 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3905 if (Init.isInvalid())
3906 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003907
Douglas Gregorb98b1992009-08-11 05:31:07 +00003908 InitChanged = InitChanged || Init.get() != E->getInit(I);
3909 Inits.push_back(Init.takeAs<Expr>());
3910 }
Mike Stump1eb44332009-09-09 15:08:12 +00003911
Douglas Gregorb98b1992009-08-11 05:31:07 +00003912 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003913 return SemaRef.Owned(E->Retain());
3914
Douglas Gregorb98b1992009-08-11 05:31:07 +00003915 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00003916 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003917}
Mike Stump1eb44332009-09-09 15:08:12 +00003918
Douglas Gregorb98b1992009-08-11 05:31:07 +00003919template<typename Derived>
3920Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003921TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003922 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00003923
Douglas Gregor43959a92009-08-20 07:17:43 +00003924 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00003925 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3926 if (Init.isInvalid())
3927 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003928
Douglas Gregor43959a92009-08-20 07:17:43 +00003929 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00003930 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3931 bool ExprChanged = false;
3932 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3933 DEnd = E->designators_end();
3934 D != DEnd; ++D) {
3935 if (D->isFieldDesignator()) {
3936 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3937 D->getDotLoc(),
3938 D->getFieldLoc()));
3939 continue;
3940 }
Mike Stump1eb44332009-09-09 15:08:12 +00003941
Douglas Gregorb98b1992009-08-11 05:31:07 +00003942 if (D->isArrayDesignator()) {
3943 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3944 if (Index.isInvalid())
3945 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003946
3947 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003948 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00003949
Douglas Gregorb98b1992009-08-11 05:31:07 +00003950 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3951 ArrayExprs.push_back(Index.release());
3952 continue;
3953 }
Mike Stump1eb44332009-09-09 15:08:12 +00003954
Douglas Gregorb98b1992009-08-11 05:31:07 +00003955 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00003956 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00003957 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3958 if (Start.isInvalid())
3959 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003960
Douglas Gregorb98b1992009-08-11 05:31:07 +00003961 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3962 if (End.isInvalid())
3963 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003964
3965 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003966 End.get(),
3967 D->getLBracketLoc(),
3968 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00003969
Douglas Gregorb98b1992009-08-11 05:31:07 +00003970 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3971 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00003972
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973 ArrayExprs.push_back(Start.release());
3974 ArrayExprs.push_back(End.release());
3975 }
Mike Stump1eb44332009-09-09 15:08:12 +00003976
Douglas Gregorb98b1992009-08-11 05:31:07 +00003977 if (!getDerived().AlwaysRebuild() &&
3978 Init.get() == E->getInit() &&
3979 !ExprChanged)
3980 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003981
Douglas Gregorb98b1992009-08-11 05:31:07 +00003982 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3983 E->getEqualOrColonLoc(),
3984 E->usesGNUSyntax(), move(Init));
3985}
Mike Stump1eb44332009-09-09 15:08:12 +00003986
Douglas Gregorb98b1992009-08-11 05:31:07 +00003987template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003988Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00003989TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00003990 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00003991 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3992
3993 // FIXME: Will we ever have proper type location here? Will we actually
3994 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00003995 QualType T = getDerived().TransformType(E->getType());
3996 if (T.isNull())
3997 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003998
Douglas Gregorb98b1992009-08-11 05:31:07 +00003999 if (!getDerived().AlwaysRebuild() &&
4000 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004001 return SemaRef.Owned(E->Retain());
4002
Douglas Gregorb98b1992009-08-11 05:31:07 +00004003 return getDerived().RebuildImplicitValueInitExpr(T);
4004}
Mike Stump1eb44332009-09-09 15:08:12 +00004005
Douglas Gregorb98b1992009-08-11 05:31:07 +00004006template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004007Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004008TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004009 // FIXME: Do we want the type as written?
4010 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004011
Douglas Gregorb98b1992009-08-11 05:31:07 +00004012 {
4013 // FIXME: Source location isn't quite accurate.
4014 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4015 T = getDerived().TransformType(E->getType());
4016 if (T.isNull())
4017 return SemaRef.ExprError();
4018 }
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4021 if (SubExpr.isInvalid())
4022 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024 if (!getDerived().AlwaysRebuild() &&
4025 T == E->getType() &&
4026 SubExpr.get() == E->getSubExpr())
4027 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004028
Douglas Gregorb98b1992009-08-11 05:31:07 +00004029 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4030 T, E->getRParenLoc());
4031}
4032
4033template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004034Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004035TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004036 bool ArgumentChanged = false;
4037 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4038 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4039 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4040 if (Init.isInvalid())
4041 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004042
Douglas Gregorb98b1992009-08-11 05:31:07 +00004043 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4044 Inits.push_back(Init.takeAs<Expr>());
4045 }
Mike Stump1eb44332009-09-09 15:08:12 +00004046
Douglas Gregorb98b1992009-08-11 05:31:07 +00004047 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4048 move_arg(Inits),
4049 E->getRParenLoc());
4050}
Mike Stump1eb44332009-09-09 15:08:12 +00004051
Douglas Gregorb98b1992009-08-11 05:31:07 +00004052/// \brief Transform an address-of-label expression.
4053///
4054/// By default, the transformation of an address-of-label expression always
4055/// rebuilds the expression, so that the label identifier can be resolved to
4056/// the corresponding label statement by semantic analysis.
4057template<typename Derived>
4058Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004059TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4061 E->getLabel());
4062}
Mike Stump1eb44332009-09-09 15:08:12 +00004063
4064template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004065Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004066TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004067 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004068 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4069 if (SubStmt.isInvalid())
4070 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004071
Douglas Gregorb98b1992009-08-11 05:31:07 +00004072 if (!getDerived().AlwaysRebuild() &&
4073 SubStmt.get() == E->getSubStmt())
4074 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004075
4076 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004077 move(SubStmt),
4078 E->getRParenLoc());
4079}
Mike Stump1eb44332009-09-09 15:08:12 +00004080
Douglas Gregorb98b1992009-08-11 05:31:07 +00004081template<typename Derived>
4082Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004083TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004084 QualType T1, T2;
4085 {
4086 // FIXME: Source location isn't quite accurate.
4087 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregorb98b1992009-08-11 05:31:07 +00004089 T1 = getDerived().TransformType(E->getArgType1());
4090 if (T1.isNull())
4091 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004092
Douglas Gregorb98b1992009-08-11 05:31:07 +00004093 T2 = getDerived().TransformType(E->getArgType2());
4094 if (T2.isNull())
4095 return SemaRef.ExprError();
4096 }
4097
4098 if (!getDerived().AlwaysRebuild() &&
4099 T1 == E->getArgType1() &&
4100 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004101 return SemaRef.Owned(E->Retain());
4102
Douglas Gregorb98b1992009-08-11 05:31:07 +00004103 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4104 T1, T2, E->getRParenLoc());
4105}
Mike Stump1eb44332009-09-09 15:08:12 +00004106
Douglas Gregorb98b1992009-08-11 05:31:07 +00004107template<typename Derived>
4108Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004109TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004110 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4111 if (Cond.isInvalid())
4112 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004113
Douglas Gregorb98b1992009-08-11 05:31:07 +00004114 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4115 if (LHS.isInvalid())
4116 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004117
Douglas Gregorb98b1992009-08-11 05:31:07 +00004118 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4119 if (RHS.isInvalid())
4120 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004121
Douglas Gregorb98b1992009-08-11 05:31:07 +00004122 if (!getDerived().AlwaysRebuild() &&
4123 Cond.get() == E->getCond() &&
4124 LHS.get() == E->getLHS() &&
4125 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
4127
Douglas Gregorb98b1992009-08-11 05:31:07 +00004128 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4129 move(Cond), move(LHS), move(RHS),
4130 E->getRParenLoc());
4131}
Mike Stump1eb44332009-09-09 15:08:12 +00004132
Douglas Gregorb98b1992009-08-11 05:31:07 +00004133template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004134Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004135TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004136 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004137}
4138
4139template<typename Derived>
4140Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004141TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004142 switch (E->getOperator()) {
4143 case OO_New:
4144 case OO_Delete:
4145 case OO_Array_New:
4146 case OO_Array_Delete:
4147 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4148 return SemaRef.ExprError();
4149
4150 case OO_Call: {
4151 // This is a call to an object's operator().
4152 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4153
4154 // Transform the object itself.
4155 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4156 if (Object.isInvalid())
4157 return SemaRef.ExprError();
4158
4159 // FIXME: Poor location information
4160 SourceLocation FakeLParenLoc
4161 = SemaRef.PP.getLocForEndOfToken(
4162 static_cast<Expr *>(Object.get())->getLocEnd());
4163
4164 // Transform the call arguments.
4165 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4166 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4167 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004168 if (getDerived().DropCallArgument(E->getArg(I)))
4169 break;
4170
Douglas Gregor668d6d92009-12-13 20:44:55 +00004171 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4172 if (Arg.isInvalid())
4173 return SemaRef.ExprError();
4174
4175 // FIXME: Poor source location information.
4176 SourceLocation FakeCommaLoc
4177 = SemaRef.PP.getLocForEndOfToken(
4178 static_cast<Expr *>(Arg.get())->getLocEnd());
4179 FakeCommaLocs.push_back(FakeCommaLoc);
4180 Args.push_back(Arg.release());
4181 }
4182
4183 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4184 move_arg(Args),
4185 FakeCommaLocs.data(),
4186 E->getLocEnd());
4187 }
4188
4189#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4190 case OO_##Name:
4191#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4192#include "clang/Basic/OperatorKinds.def"
4193 case OO_Subscript:
4194 // Handled below.
4195 break;
4196
4197 case OO_Conditional:
4198 llvm_unreachable("conditional operator is not actually overloadable");
4199 return SemaRef.ExprError();
4200
4201 case OO_None:
4202 case NUM_OVERLOADED_OPERATORS:
4203 llvm_unreachable("not an overloaded operator?");
4204 return SemaRef.ExprError();
4205 }
4206
Douglas Gregorb98b1992009-08-11 05:31:07 +00004207 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4208 if (Callee.isInvalid())
4209 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004210
John McCall454feb92009-12-08 09:21:05 +00004211 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004212 if (First.isInvalid())
4213 return SemaRef.ExprError();
4214
4215 OwningExprResult Second(SemaRef);
4216 if (E->getNumArgs() == 2) {
4217 Second = getDerived().TransformExpr(E->getArg(1));
4218 if (Second.isInvalid())
4219 return SemaRef.ExprError();
4220 }
Mike Stump1eb44332009-09-09 15:08:12 +00004221
Douglas Gregorb98b1992009-08-11 05:31:07 +00004222 if (!getDerived().AlwaysRebuild() &&
4223 Callee.get() == E->getCallee() &&
4224 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004225 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4226 return SemaRef.Owned(E->Retain());
4227
Douglas Gregorb98b1992009-08-11 05:31:07 +00004228 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4229 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004230 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004231 move(First),
4232 move(Second));
4233}
Mike Stump1eb44332009-09-09 15:08:12 +00004234
Douglas Gregorb98b1992009-08-11 05:31:07 +00004235template<typename Derived>
4236Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004237TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4238 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004239}
Mike Stump1eb44332009-09-09 15:08:12 +00004240
Douglas Gregorb98b1992009-08-11 05:31:07 +00004241template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004242Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004243TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004244 TypeSourceInfo *OldT;
4245 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004246 {
4247 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004248 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004249 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4250 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004251
John McCall9d125032010-01-15 18:39:57 +00004252 OldT = E->getTypeInfoAsWritten();
4253 NewT = getDerived().TransformType(OldT);
4254 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004255 return SemaRef.ExprError();
4256 }
Mike Stump1eb44332009-09-09 15:08:12 +00004257
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004258 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004259 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004260 if (SubExpr.isInvalid())
4261 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004262
Douglas Gregorb98b1992009-08-11 05:31:07 +00004263 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004264 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004265 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004266 return SemaRef.Owned(E->Retain());
4267
Douglas Gregorb98b1992009-08-11 05:31:07 +00004268 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004269 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004270 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4271 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4272 SourceLocation FakeRParenLoc
4273 = SemaRef.PP.getLocForEndOfToken(
4274 E->getSubExpr()->getSourceRange().getEnd());
4275 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004276 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004277 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004278 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004279 FakeRAngleLoc,
4280 FakeRAngleLoc,
4281 move(SubExpr),
4282 FakeRParenLoc);
4283}
Mike Stump1eb44332009-09-09 15:08:12 +00004284
Douglas Gregorb98b1992009-08-11 05:31:07 +00004285template<typename Derived>
4286Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004287TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4288 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004289}
Mike Stump1eb44332009-09-09 15:08:12 +00004290
4291template<typename Derived>
4292Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004293TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4294 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004295}
4296
Douglas Gregorb98b1992009-08-11 05:31:07 +00004297template<typename Derived>
4298Sema::OwningExprResult
4299TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004300 CXXReinterpretCastExpr *E) {
4301 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004302}
Mike Stump1eb44332009-09-09 15:08:12 +00004303
Douglas Gregorb98b1992009-08-11 05:31:07 +00004304template<typename Derived>
4305Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004306TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4307 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004308}
Mike Stump1eb44332009-09-09 15:08:12 +00004309
Douglas Gregorb98b1992009-08-11 05:31:07 +00004310template<typename Derived>
4311Sema::OwningExprResult
4312TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004313 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004314 TypeSourceInfo *OldT;
4315 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004316 {
4317 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004318
John McCall9d125032010-01-15 18:39:57 +00004319 OldT = E->getTypeInfoAsWritten();
4320 NewT = getDerived().TransformType(OldT);
4321 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004322 return SemaRef.ExprError();
4323 }
Mike Stump1eb44332009-09-09 15:08:12 +00004324
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004325 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004326 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327 if (SubExpr.isInvalid())
4328 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004329
Douglas Gregorb98b1992009-08-11 05:31:07 +00004330 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004331 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004332 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004333 return SemaRef.Owned(E->Retain());
4334
Douglas Gregorb98b1992009-08-11 05:31:07 +00004335 // FIXME: The end of the type's source range is wrong
4336 return getDerived().RebuildCXXFunctionalCastExpr(
4337 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004338 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004339 /*FIXME:*/E->getSubExpr()->getLocStart(),
4340 move(SubExpr),
4341 E->getRParenLoc());
4342}
Mike Stump1eb44332009-09-09 15:08:12 +00004343
Douglas Gregorb98b1992009-08-11 05:31:07 +00004344template<typename Derived>
4345Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004346TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004347 if (E->isTypeOperand()) {
4348 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004349
Douglas Gregorb98b1992009-08-11 05:31:07 +00004350 QualType T = getDerived().TransformType(E->getTypeOperand());
4351 if (T.isNull())
4352 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004353
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354 if (!getDerived().AlwaysRebuild() &&
4355 T == E->getTypeOperand())
4356 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004357
Douglas Gregorb98b1992009-08-11 05:31:07 +00004358 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4359 /*FIXME:*/E->getLocStart(),
4360 T,
4361 E->getLocEnd());
4362 }
Mike Stump1eb44332009-09-09 15:08:12 +00004363
Douglas Gregorb98b1992009-08-11 05:31:07 +00004364 // We don't know whether the expression is potentially evaluated until
4365 // after we perform semantic analysis, so the expression is potentially
4366 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004367 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004369
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4371 if (SubExpr.isInvalid())
4372 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004373
Douglas Gregorb98b1992009-08-11 05:31:07 +00004374 if (!getDerived().AlwaysRebuild() &&
4375 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004376 return SemaRef.Owned(E->Retain());
4377
Douglas Gregorb98b1992009-08-11 05:31:07 +00004378 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4379 /*FIXME:*/E->getLocStart(),
4380 move(SubExpr),
4381 E->getLocEnd());
4382}
4383
4384template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004385Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004386TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004387 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004388}
Mike Stump1eb44332009-09-09 15:08:12 +00004389
Douglas Gregorb98b1992009-08-11 05:31:07 +00004390template<typename Derived>
4391Sema::OwningExprResult
4392TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004393 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004394 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004395}
Mike Stump1eb44332009-09-09 15:08:12 +00004396
Douglas Gregorb98b1992009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004400 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004401
Douglas Gregorb98b1992009-08-11 05:31:07 +00004402 QualType T = getDerived().TransformType(E->getType());
4403 if (T.isNull())
4404 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004405
Douglas Gregorb98b1992009-08-11 05:31:07 +00004406 if (!getDerived().AlwaysRebuild() &&
4407 T == E->getType())
4408 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004409
Douglas Gregor828a1972010-01-07 23:12:05 +00004410 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004411}
Mike Stump1eb44332009-09-09 15:08:12 +00004412
Douglas Gregorb98b1992009-08-11 05:31:07 +00004413template<typename Derived>
4414Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004416 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4417 if (SubExpr.isInvalid())
4418 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004419
Douglas Gregorb98b1992009-08-11 05:31:07 +00004420 if (!getDerived().AlwaysRebuild() &&
4421 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004422 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004423
4424 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4425}
Mike Stump1eb44332009-09-09 15:08:12 +00004426
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427template<typename Derived>
4428Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004429TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004430 ParmVarDecl *Param
Douglas Gregorb98b1992009-08-11 05:31:07 +00004431 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4432 if (!Param)
4433 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004434
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 if (getDerived().AlwaysRebuild() &&
4436 Param == E->getParam())
4437 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004438
Douglas Gregor036aed12009-12-23 23:03:06 +00004439 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004440}
Mike Stump1eb44332009-09-09 15:08:12 +00004441
Douglas Gregorb98b1992009-08-11 05:31:07 +00004442template<typename Derived>
4443Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004444TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004445 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4446
4447 QualType T = getDerived().TransformType(E->getType());
4448 if (T.isNull())
4449 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004450
Douglas Gregorb98b1992009-08-11 05:31:07 +00004451 if (!getDerived().AlwaysRebuild() &&
4452 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004453 return SemaRef.Owned(E->Retain());
4454
4455 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456 /*FIXME:*/E->getTypeBeginLoc(),
4457 T,
4458 E->getRParenLoc());
4459}
Mike Stump1eb44332009-09-09 15:08:12 +00004460
Douglas Gregorb98b1992009-08-11 05:31:07 +00004461template<typename Derived>
4462Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004463TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004464 // Transform the type that we're allocating
4465 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4466 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4467 if (AllocType.isNull())
4468 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004469
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 // Transform the size of the array we're allocating (if any).
4471 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4472 if (ArraySize.isInvalid())
4473 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475 // Transform the placement arguments (if any).
4476 bool ArgumentChanged = false;
4477 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4478 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4479 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4480 if (Arg.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004482
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4484 PlacementArgs.push_back(Arg.take());
4485 }
Mike Stump1eb44332009-09-09 15:08:12 +00004486
Douglas Gregor43959a92009-08-20 07:17:43 +00004487 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004488 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4489 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4490 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4491 if (Arg.isInvalid())
4492 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004493
Douglas Gregorb98b1992009-08-11 05:31:07 +00004494 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4495 ConstructorArgs.push_back(Arg.take());
4496 }
Mike Stump1eb44332009-09-09 15:08:12 +00004497
Douglas Gregorb98b1992009-08-11 05:31:07 +00004498 if (!getDerived().AlwaysRebuild() &&
4499 AllocType == E->getAllocatedType() &&
4500 ArraySize.get() == E->getArraySize() &&
4501 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004502 return SemaRef.Owned(E->Retain());
4503
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004504 if (!ArraySize.get()) {
4505 // If no array size was specified, but the new expression was
4506 // instantiated with an array type (e.g., "new T" where T is
4507 // instantiated with "int[4]"), extract the outer bound from the
4508 // array type as our array size. We do this with constant and
4509 // dependently-sized array types.
4510 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4511 if (!ArrayT) {
4512 // Do nothing
4513 } else if (const ConstantArrayType *ConsArrayT
4514 = dyn_cast<ConstantArrayType>(ArrayT)) {
4515 ArraySize
4516 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4517 ConsArrayT->getSize(),
4518 SemaRef.Context.getSizeType(),
4519 /*FIXME:*/E->getLocStart()));
4520 AllocType = ConsArrayT->getElementType();
4521 } else if (const DependentSizedArrayType *DepArrayT
4522 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4523 if (DepArrayT->getSizeExpr()) {
4524 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4525 AllocType = DepArrayT->getElementType();
4526 }
4527 }
4528 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004529 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4530 E->isGlobalNew(),
4531 /*FIXME:*/E->getLocStart(),
4532 move_arg(PlacementArgs),
4533 /*FIXME:*/E->getLocStart(),
4534 E->isParenTypeId(),
4535 AllocType,
4536 /*FIXME:*/E->getLocStart(),
4537 /*FIXME:*/SourceRange(),
4538 move(ArraySize),
4539 /*FIXME:*/E->getLocStart(),
4540 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004541 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004542}
Mike Stump1eb44332009-09-09 15:08:12 +00004543
Douglas Gregorb98b1992009-08-11 05:31:07 +00004544template<typename Derived>
4545Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004546TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4548 if (Operand.isInvalid())
4549 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
Douglas Gregorb98b1992009-08-11 05:31:07 +00004551 if (!getDerived().AlwaysRebuild() &&
Mike Stump1eb44332009-09-09 15:08:12 +00004552 Operand.get() == E->getArgument())
4553 return SemaRef.Owned(E->Retain());
4554
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4556 E->isGlobalDelete(),
4557 E->isArrayForm(),
4558 move(Operand));
4559}
Mike Stump1eb44332009-09-09 15:08:12 +00004560
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561template<typename Derived>
4562Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004563TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004564 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004565 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4566 if (Base.isInvalid())
4567 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004568
Douglas Gregora71d8192009-09-04 17:36:40 +00004569 NestedNameSpecifier *Qualifier
4570 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4571 E->getQualifierRange());
4572 if (E->getQualifier() && !Qualifier)
4573 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregora71d8192009-09-04 17:36:40 +00004575 QualType DestroyedType;
4576 {
4577 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4578 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4579 if (DestroyedType.isNull())
4580 return SemaRef.ExprError();
4581 }
Mike Stump1eb44332009-09-09 15:08:12 +00004582
Douglas Gregora71d8192009-09-04 17:36:40 +00004583 if (!getDerived().AlwaysRebuild() &&
4584 Base.get() == E->getBase() &&
4585 Qualifier == E->getQualifier() &&
4586 DestroyedType == E->getDestroyedType())
4587 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004588
Douglas Gregora71d8192009-09-04 17:36:40 +00004589 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4590 E->getOperatorLoc(),
4591 E->isArrow(),
4592 E->getDestroyedTypeLoc(),
4593 DestroyedType,
4594 Qualifier,
4595 E->getQualifierRange());
4596}
Mike Stump1eb44332009-09-09 15:08:12 +00004597
Douglas Gregora71d8192009-09-04 17:36:40 +00004598template<typename Derived>
4599Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004600TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004601 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004602 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4603
4604 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4605 Sema::LookupOrdinaryName);
4606
4607 // Transform all the decls.
4608 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4609 E = Old->decls_end(); I != E; ++I) {
4610 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00004611 if (!InstD) {
4612 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4613 // This can happen because of dependent hiding.
4614 if (isa<UsingShadowDecl>(*I))
4615 continue;
4616 else
4617 return SemaRef.ExprError();
4618 }
John McCallf7a1a742009-11-24 19:00:30 +00004619
4620 // Expand using declarations.
4621 if (isa<UsingDecl>(InstD)) {
4622 UsingDecl *UD = cast<UsingDecl>(InstD);
4623 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4624 E = UD->shadow_end(); I != E; ++I)
4625 R.addDecl(*I);
4626 continue;
4627 }
4628
4629 R.addDecl(InstD);
4630 }
4631
4632 // Resolve a kind, but don't do any further analysis. If it's
4633 // ambiguous, the callee needs to deal with it.
4634 R.resolveKind();
4635
4636 // Rebuild the nested-name qualifier, if present.
4637 CXXScopeSpec SS;
4638 NestedNameSpecifier *Qualifier = 0;
4639 if (Old->getQualifier()) {
4640 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4641 Old->getQualifierRange());
4642 if (!Qualifier)
4643 return SemaRef.ExprError();
4644
4645 SS.setScopeRep(Qualifier);
4646 SS.setRange(Old->getQualifierRange());
4647 }
4648
4649 // If we have no template arguments, it's a normal declaration name.
4650 if (!Old->hasExplicitTemplateArgs())
4651 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4652
4653 // If we have template arguments, rebuild them, then rebuild the
4654 // templateid expression.
4655 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4656 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4657 TemplateArgumentLoc Loc;
4658 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4659 return SemaRef.ExprError();
4660 TransArgs.addArgument(Loc);
4661 }
4662
4663 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4664 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004665}
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregorb98b1992009-08-11 05:31:07 +00004667template<typename Derived>
4668Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004669TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004670 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004671
Douglas Gregorb98b1992009-08-11 05:31:07 +00004672 QualType T = getDerived().TransformType(E->getQueriedType());
4673 if (T.isNull())
4674 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregorb98b1992009-08-11 05:31:07 +00004676 if (!getDerived().AlwaysRebuild() &&
4677 T == E->getQueriedType())
4678 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004679
Douglas Gregorb98b1992009-08-11 05:31:07 +00004680 // FIXME: Bad location information
4681 SourceLocation FakeLParenLoc
4682 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004683
4684 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004685 E->getLocStart(),
4686 /*FIXME:*/FakeLParenLoc,
4687 T,
4688 E->getLocEnd());
4689}
Mike Stump1eb44332009-09-09 15:08:12 +00004690
Douglas Gregorb98b1992009-08-11 05:31:07 +00004691template<typename Derived>
4692Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004693TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004694 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004696 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4697 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004698 if (!NNS)
4699 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004700
4701 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004702 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4703 if (!Name)
4704 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004705
John McCallf7a1a742009-11-24 19:00:30 +00004706 if (!E->hasExplicitTemplateArgs()) {
4707 if (!getDerived().AlwaysRebuild() &&
4708 NNS == E->getQualifier() &&
4709 Name == E->getDeclName())
4710 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004711
John McCallf7a1a742009-11-24 19:00:30 +00004712 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4713 E->getQualifierRange(),
4714 Name, E->getLocation(),
4715 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004716 }
John McCalld5532b62009-11-23 01:53:49 +00004717
4718 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004719 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004720 TemplateArgumentLoc Loc;
4721 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004722 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004723 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 }
4725
John McCallf7a1a742009-11-24 19:00:30 +00004726 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4727 E->getQualifierRange(),
4728 Name, E->getLocation(),
4729 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730}
4731
4732template<typename Derived>
4733Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004734TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004735 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4736
4737 QualType T = getDerived().TransformType(E->getType());
4738 if (T.isNull())
4739 return SemaRef.ExprError();
4740
4741 CXXConstructorDecl *Constructor
4742 = cast_or_null<CXXConstructorDecl>(
4743 getDerived().TransformDecl(E->getConstructor()));
4744 if (!Constructor)
4745 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregorb98b1992009-08-11 05:31:07 +00004747 bool ArgumentChanged = false;
4748 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004749 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004750 ArgEnd = E->arg_end();
4751 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004752 if (getDerived().DropCallArgument(*Arg)) {
4753 ArgumentChanged = true;
4754 break;
4755 }
4756
Douglas Gregorb98b1992009-08-11 05:31:07 +00004757 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4758 if (TransArg.isInvalid())
4759 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004760
Douglas Gregorb98b1992009-08-11 05:31:07 +00004761 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4762 Args.push_back(TransArg.takeAs<Expr>());
4763 }
4764
4765 if (!getDerived().AlwaysRebuild() &&
4766 T == E->getType() &&
4767 Constructor == E->getConstructor() &&
4768 !ArgumentChanged)
4769 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004770
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004771 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4772 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004773 move_arg(Args));
4774}
Mike Stump1eb44332009-09-09 15:08:12 +00004775
Douglas Gregorb98b1992009-08-11 05:31:07 +00004776/// \brief Transform a C++ temporary-binding expression.
4777///
Douglas Gregor51326552009-12-24 18:51:59 +00004778/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4779/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004780template<typename Derived>
4781Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004782TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004783 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004784}
Mike Stump1eb44332009-09-09 15:08:12 +00004785
4786/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004787/// be destroyed after the expression is evaluated.
4788///
Douglas Gregor51326552009-12-24 18:51:59 +00004789/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4790/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004791template<typename Derived>
4792Sema::OwningExprResult
4793TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004794 CXXExprWithTemporaries *E) {
4795 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004796}
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregorb98b1992009-08-11 05:31:07 +00004798template<typename Derived>
4799Sema::OwningExprResult
4800TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004801 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004802 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4803 QualType T = getDerived().TransformType(E->getType());
4804 if (T.isNull())
4805 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807 CXXConstructorDecl *Constructor
4808 = cast_or_null<CXXConstructorDecl>(
4809 getDerived().TransformDecl(E->getConstructor()));
4810 if (!Constructor)
4811 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004812
Douglas Gregorb98b1992009-08-11 05:31:07 +00004813 bool ArgumentChanged = false;
4814 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4815 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004816 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004817 ArgEnd = E->arg_end();
4818 Arg != ArgEnd; ++Arg) {
4819 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4820 if (TransArg.isInvalid())
4821 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004822
Douglas Gregorb98b1992009-08-11 05:31:07 +00004823 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4824 Args.push_back((Expr *)TransArg.release());
4825 }
Mike Stump1eb44332009-09-09 15:08:12 +00004826
Douglas Gregorb98b1992009-08-11 05:31:07 +00004827 if (!getDerived().AlwaysRebuild() &&
4828 T == E->getType() &&
4829 Constructor == E->getConstructor() &&
4830 !ArgumentChanged)
4831 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004832
Douglas Gregorb98b1992009-08-11 05:31:07 +00004833 // FIXME: Bogus location information
4834 SourceLocation CommaLoc;
4835 if (Args.size() > 1) {
4836 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004837 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004838 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4839 }
4840 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4841 T,
4842 /*FIXME:*/E->getTypeBeginLoc(),
4843 move_arg(Args),
4844 &CommaLoc,
4845 E->getLocEnd());
4846}
Mike Stump1eb44332009-09-09 15:08:12 +00004847
Douglas Gregorb98b1992009-08-11 05:31:07 +00004848template<typename Derived>
4849Sema::OwningExprResult
4850TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004851 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004852 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4853 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4854 if (T.isNull())
4855 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004856
Douglas Gregorb98b1992009-08-11 05:31:07 +00004857 bool ArgumentChanged = false;
4858 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4859 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4860 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4861 ArgEnd = E->arg_end();
4862 Arg != ArgEnd; ++Arg) {
4863 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4864 if (TransArg.isInvalid())
4865 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004866
Douglas Gregorb98b1992009-08-11 05:31:07 +00004867 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4868 FakeCommaLocs.push_back(
4869 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4870 Args.push_back(TransArg.takeAs<Expr>());
4871 }
Mike Stump1eb44332009-09-09 15:08:12 +00004872
Douglas Gregorb98b1992009-08-11 05:31:07 +00004873 if (!getDerived().AlwaysRebuild() &&
4874 T == E->getTypeAsWritten() &&
4875 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004876 return SemaRef.Owned(E->Retain());
4877
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878 // FIXME: we're faking the locations of the commas
4879 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4880 T,
4881 E->getLParenLoc(),
4882 move_arg(Args),
4883 FakeCommaLocs.data(),
4884 E->getRParenLoc());
4885}
Mike Stump1eb44332009-09-09 15:08:12 +00004886
Douglas Gregorb98b1992009-08-11 05:31:07 +00004887template<typename Derived>
4888Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004889TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00004890 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004891 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004892 OwningExprResult Base(SemaRef, (Expr*) 0);
4893 Expr *OldBase;
4894 QualType BaseType;
4895 QualType ObjectType;
4896 if (!E->isImplicitAccess()) {
4897 OldBase = E->getBase();
4898 Base = getDerived().TransformExpr(OldBase);
4899 if (Base.isInvalid())
4900 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004901
John McCallaa81e162009-12-01 22:10:20 +00004902 // Start the member reference and compute the object's type.
4903 Sema::TypeTy *ObjectTy = 0;
4904 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4905 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00004906 E->isArrow()? tok::arrow : tok::period,
John McCallaa81e162009-12-01 22:10:20 +00004907 ObjectTy);
4908 if (Base.isInvalid())
4909 return SemaRef.ExprError();
4910
4911 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4912 BaseType = ((Expr*) Base.get())->getType();
4913 } else {
4914 OldBase = 0;
4915 BaseType = getDerived().TransformType(E->getBaseType());
4916 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4917 }
Mike Stump1eb44332009-09-09 15:08:12 +00004918
Douglas Gregor6cd21982009-10-20 05:58:46 +00004919 // Transform the first part of the nested-name-specifier that qualifies
4920 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00004921 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00004922 = getDerived().TransformFirstQualifierInScope(
4923 E->getFirstQualifierFoundInScope(),
4924 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00004925
Douglas Gregora38c6872009-09-03 16:14:30 +00004926 NestedNameSpecifier *Qualifier = 0;
4927 if (E->getQualifier()) {
4928 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4929 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00004930 ObjectType,
4931 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00004932 if (!Qualifier)
4933 return SemaRef.ExprError();
4934 }
Mike Stump1eb44332009-09-09 15:08:12 +00004935
4936 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00004937 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00004938 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00004939 if (!Name)
4940 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004941
John McCallaa81e162009-12-01 22:10:20 +00004942 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004943 // This is a reference to a member without an explicitly-specified
4944 // template argument list. Optimize for this common case.
4945 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00004946 Base.get() == OldBase &&
4947 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004948 Qualifier == E->getQualifier() &&
4949 Name == E->getMember() &&
4950 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00004951 return SemaRef.Owned(E->Retain());
4952
John McCall865d4472009-11-19 22:55:06 +00004953 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00004954 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004955 E->isArrow(),
4956 E->getOperatorLoc(),
4957 Qualifier,
4958 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00004959 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004960 Name,
4961 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00004962 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004963 }
4964
John McCalld5532b62009-11-23 01:53:49 +00004965 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004966 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004967 TemplateArgumentLoc Loc;
4968 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004969 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004970 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004971 }
Mike Stump1eb44332009-09-09 15:08:12 +00004972
John McCall865d4472009-11-19 22:55:06 +00004973 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00004974 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004975 E->isArrow(),
4976 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00004977 Qualifier,
4978 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00004979 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00004980 Name,
4981 E->getMemberLoc(),
4982 &TransArgs);
4983}
4984
4985template<typename Derived>
4986Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004987TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00004988 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00004989 OwningExprResult Base(SemaRef, (Expr*) 0);
4990 QualType BaseType;
4991 if (!Old->isImplicitAccess()) {
4992 Base = getDerived().TransformExpr(Old->getBase());
4993 if (Base.isInvalid())
4994 return SemaRef.ExprError();
4995 BaseType = ((Expr*) Base.get())->getType();
4996 } else {
4997 BaseType = getDerived().TransformType(Old->getBaseType());
4998 }
John McCall129e2df2009-11-30 22:42:35 +00004999
5000 NestedNameSpecifier *Qualifier = 0;
5001 if (Old->getQualifier()) {
5002 Qualifier
5003 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5004 Old->getQualifierRange());
5005 if (Qualifier == 0)
5006 return SemaRef.ExprError();
5007 }
5008
5009 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5010 Sema::LookupOrdinaryName);
5011
5012 // Transform all the decls.
5013 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5014 E = Old->decls_end(); I != E; ++I) {
5015 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005016 if (!InstD) {
5017 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5018 // This can happen because of dependent hiding.
5019 if (isa<UsingShadowDecl>(*I))
5020 continue;
5021 else
5022 return SemaRef.ExprError();
5023 }
John McCall129e2df2009-11-30 22:42:35 +00005024
5025 // Expand using declarations.
5026 if (isa<UsingDecl>(InstD)) {
5027 UsingDecl *UD = cast<UsingDecl>(InstD);
5028 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5029 E = UD->shadow_end(); I != E; ++I)
5030 R.addDecl(*I);
5031 continue;
5032 }
5033
5034 R.addDecl(InstD);
5035 }
5036
5037 R.resolveKind();
5038
5039 TemplateArgumentListInfo TransArgs;
5040 if (Old->hasExplicitTemplateArgs()) {
5041 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5042 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5043 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5044 TemplateArgumentLoc Loc;
5045 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5046 Loc))
5047 return SemaRef.ExprError();
5048 TransArgs.addArgument(Loc);
5049 }
5050 }
John McCallc2233c52010-01-15 08:34:02 +00005051
5052 // FIXME: to do this check properly, we will need to preserve the
5053 // first-qualifier-in-scope here, just in case we had a dependent
5054 // base (and therefore couldn't do the check) and a
5055 // nested-name-qualifier (and therefore could do the lookup).
5056 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005057
5058 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005059 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005060 Old->getOperatorLoc(),
5061 Old->isArrow(),
5062 Qualifier,
5063 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005064 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005065 R,
5066 (Old->hasExplicitTemplateArgs()
5067 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068}
5069
5070template<typename Derived>
5071Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005072TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005073 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074}
5075
Mike Stump1eb44332009-09-09 15:08:12 +00005076template<typename Derived>
5077Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005079 // FIXME: poor source location
5080 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5081 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5082 if (EncodedType.isNull())
5083 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005084
Douglas Gregorb98b1992009-08-11 05:31:07 +00005085 if (!getDerived().AlwaysRebuild() &&
5086 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005087 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005088
5089 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5090 EncodedType,
5091 E->getRParenLoc());
5092}
Mike Stump1eb44332009-09-09 15:08:12 +00005093
Douglas Gregorb98b1992009-08-11 05:31:07 +00005094template<typename Derived>
5095Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005096TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 // FIXME: Implement this!
5098 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005099 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100}
5101
Mike Stump1eb44332009-09-09 15:08:12 +00005102template<typename Derived>
5103Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005104TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005105 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005106}
5107
Mike Stump1eb44332009-09-09 15:08:12 +00005108template<typename Derived>
5109Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005110TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005111 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005112 = cast_or_null<ObjCProtocolDecl>(
5113 getDerived().TransformDecl(E->getProtocol()));
5114 if (!Protocol)
5115 return SemaRef.ExprError();
5116
5117 if (!getDerived().AlwaysRebuild() &&
5118 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005119 return SemaRef.Owned(E->Retain());
5120
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 return getDerived().RebuildObjCProtocolExpr(Protocol,
5122 E->getAtLoc(),
5123 /*FIXME:*/E->getAtLoc(),
5124 /*FIXME:*/E->getAtLoc(),
5125 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127}
5128
Mike Stump1eb44332009-09-09 15:08:12 +00005129template<typename Derived>
5130Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005131TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005132 // FIXME: Implement this!
5133 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005134 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005135}
5136
Mike Stump1eb44332009-09-09 15:08:12 +00005137template<typename Derived>
5138Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005139TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005140 // FIXME: Implement this!
5141 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005142 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005143}
5144
Mike Stump1eb44332009-09-09 15:08:12 +00005145template<typename Derived>
5146Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005147TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005148 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005149 // FIXME: Implement this!
5150 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005151 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005152}
5153
Mike Stump1eb44332009-09-09 15:08:12 +00005154template<typename Derived>
5155Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005156TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005157 // FIXME: Implement this!
5158 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005159 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005160}
5161
Mike Stump1eb44332009-09-09 15:08:12 +00005162template<typename Derived>
5163Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005164TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005165 // FIXME: Implement this!
5166 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005167 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005168}
5169
Mike Stump1eb44332009-09-09 15:08:12 +00005170template<typename Derived>
5171Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005172TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005173 bool ArgumentChanged = false;
5174 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5175 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5176 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5177 if (SubExpr.isInvalid())
5178 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005179
Douglas Gregorb98b1992009-08-11 05:31:07 +00005180 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5181 SubExprs.push_back(SubExpr.takeAs<Expr>());
5182 }
Mike Stump1eb44332009-09-09 15:08:12 +00005183
Douglas Gregorb98b1992009-08-11 05:31:07 +00005184 if (!getDerived().AlwaysRebuild() &&
5185 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005186 return SemaRef.Owned(E->Retain());
5187
Douglas Gregorb98b1992009-08-11 05:31:07 +00005188 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5189 move_arg(SubExprs),
5190 E->getRParenLoc());
5191}
5192
Mike Stump1eb44332009-09-09 15:08:12 +00005193template<typename Derived>
5194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005195TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005196 // FIXME: Implement this!
5197 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005198 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005199}
5200
Mike Stump1eb44332009-09-09 15:08:12 +00005201template<typename Derived>
5202Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 // FIXME: Implement this!
5205 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005206 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207}
Mike Stump1eb44332009-09-09 15:08:12 +00005208
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005210// Type reconstruction
5211//===----------------------------------------------------------------------===//
5212
Mike Stump1eb44332009-09-09 15:08:12 +00005213template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005214QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5215 SourceLocation Star) {
5216 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005217 getDerived().getBaseEntity());
5218}
5219
Mike Stump1eb44332009-09-09 15:08:12 +00005220template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005221QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5222 SourceLocation Star) {
5223 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005224 getDerived().getBaseEntity());
5225}
5226
Mike Stump1eb44332009-09-09 15:08:12 +00005227template<typename Derived>
5228QualType
John McCall85737a72009-10-30 00:06:24 +00005229TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5230 bool WrittenAsLValue,
5231 SourceLocation Sigil) {
5232 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5233 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005234}
5235
5236template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005237QualType
John McCall85737a72009-10-30 00:06:24 +00005238TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5239 QualType ClassType,
5240 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005241 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005242 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005243}
5244
5245template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005246QualType
John McCall85737a72009-10-30 00:06:24 +00005247TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5248 SourceLocation Sigil) {
5249 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005250 getDerived().getBaseEntity());
5251}
5252
5253template<typename Derived>
5254QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005255TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5256 ArrayType::ArraySizeModifier SizeMod,
5257 const llvm::APInt *Size,
5258 Expr *SizeExpr,
5259 unsigned IndexTypeQuals,
5260 SourceRange BracketsRange) {
5261 if (SizeExpr || !Size)
5262 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5263 IndexTypeQuals, BracketsRange,
5264 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005265
5266 QualType Types[] = {
5267 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5268 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5269 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005270 };
5271 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5272 QualType SizeType;
5273 for (unsigned I = 0; I != NumTypes; ++I)
5274 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5275 SizeType = Types[I];
5276 break;
5277 }
Mike Stump1eb44332009-09-09 15:08:12 +00005278
Douglas Gregor577f75a2009-08-04 16:50:30 +00005279 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005280 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005281 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005282 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005283}
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregor577f75a2009-08-04 16:50:30 +00005285template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005286QualType
5287TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005288 ArrayType::ArraySizeModifier SizeMod,
5289 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005290 unsigned IndexTypeQuals,
5291 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005292 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005293 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005294}
5295
5296template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005297QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005298TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005299 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005300 unsigned IndexTypeQuals,
5301 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005302 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005303 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005304}
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Douglas Gregor577f75a2009-08-04 16:50:30 +00005306template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005307QualType
5308TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005309 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005310 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005311 unsigned IndexTypeQuals,
5312 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005313 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005314 SizeExpr.takeAs<Expr>(),
5315 IndexTypeQuals, BracketsRange);
5316}
5317
5318template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005319QualType
5320TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005321 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005322 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005323 unsigned IndexTypeQuals,
5324 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005325 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005326 SizeExpr.takeAs<Expr>(),
5327 IndexTypeQuals, BracketsRange);
5328}
5329
5330template<typename Derived>
5331QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5332 unsigned NumElements) {
5333 // FIXME: semantic checking!
5334 return SemaRef.Context.getVectorType(ElementType, NumElements);
5335}
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor577f75a2009-08-04 16:50:30 +00005337template<typename Derived>
5338QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5339 unsigned NumElements,
5340 SourceLocation AttributeLoc) {
5341 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5342 NumElements, true);
5343 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005344 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005345 AttributeLoc);
5346 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5347 AttributeLoc);
5348}
Mike Stump1eb44332009-09-09 15:08:12 +00005349
Douglas Gregor577f75a2009-08-04 16:50:30 +00005350template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005351QualType
5352TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005353 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005354 SourceLocation AttributeLoc) {
5355 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5356}
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregor577f75a2009-08-04 16:50:30 +00005358template<typename Derived>
5359QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005360 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005361 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005362 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005363 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005364 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005365 Quals,
5366 getDerived().getBaseLocation(),
5367 getDerived().getBaseEntity());
5368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor577f75a2009-08-04 16:50:30 +00005370template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005371QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5372 return SemaRef.Context.getFunctionNoProtoType(T);
5373}
5374
5375template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005376QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5377 assert(D && "no decl found");
5378 if (D->isInvalidDecl()) return QualType();
5379
5380 TypeDecl *Ty;
5381 if (isa<UsingDecl>(D)) {
5382 UsingDecl *Using = cast<UsingDecl>(D);
5383 assert(Using->isTypeName() &&
5384 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5385
5386 // A valid resolved using typename decl points to exactly one type decl.
5387 assert(++Using->shadow_begin() == Using->shadow_end());
5388 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5389
5390 } else {
5391 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5392 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5393 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5394 }
5395
5396 return SemaRef.Context.getTypeDeclType(Ty);
5397}
5398
5399template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005400QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005401 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5402}
5403
5404template<typename Derived>
5405QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5406 return SemaRef.Context.getTypeOfType(Underlying);
5407}
5408
5409template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005410QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005411 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5412}
5413
5414template<typename Derived>
5415QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005416 TemplateName Template,
5417 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005418 const TemplateArgumentListInfo &TemplateArgs) {
5419 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005420}
Mike Stump1eb44332009-09-09 15:08:12 +00005421
Douglas Gregordcee1a12009-08-06 05:28:30 +00005422template<typename Derived>
5423NestedNameSpecifier *
5424TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5425 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005426 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005427 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005428 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005429 CXXScopeSpec SS;
5430 // FIXME: The source location information is all wrong.
5431 SS.setRange(Range);
5432 SS.setScopeRep(Prefix);
5433 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005434 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005435 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005436 ObjectType,
5437 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005438 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005439}
5440
5441template<typename Derived>
5442NestedNameSpecifier *
5443TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5444 SourceRange Range,
5445 NamespaceDecl *NS) {
5446 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5447}
5448
5449template<typename Derived>
5450NestedNameSpecifier *
5451TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5452 SourceRange Range,
5453 bool TemplateKW,
5454 QualType T) {
5455 if (T->isDependentType() || T->isRecordType() ||
5456 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005457 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005458 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5459 T.getTypePtr());
5460 }
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregordcee1a12009-08-06 05:28:30 +00005462 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5463 return 0;
5464}
Mike Stump1eb44332009-09-09 15:08:12 +00005465
Douglas Gregord1067e52009-08-06 06:41:21 +00005466template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005467TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005468TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5469 bool TemplateKW,
5470 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005471 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005472 Template);
5473}
5474
5475template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005476TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005477TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005478 const IdentifierInfo &II,
5479 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005480 CXXScopeSpec SS;
5481 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005482 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005483 UnqualifiedId Name;
5484 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005485 return getSema().ActOnDependentTemplateName(
5486 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005487 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005488 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005489 ObjectType.getAsOpaquePtr(),
5490 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005491 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005492}
Mike Stump1eb44332009-09-09 15:08:12 +00005493
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005495TemplateName
5496TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5497 OverloadedOperatorKind Operator,
5498 QualType ObjectType) {
5499 CXXScopeSpec SS;
5500 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5501 SS.setScopeRep(Qualifier);
5502 UnqualifiedId Name;
5503 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5504 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5505 Operator, SymbolLocations);
5506 return getSema().ActOnDependentTemplateName(
5507 /*FIXME:*/getDerived().getBaseLocation(),
5508 SS,
5509 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005510 ObjectType.getAsOpaquePtr(),
5511 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005512 .template getAsVal<TemplateName>();
5513}
5514
5515template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005516Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005517TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5518 SourceLocation OpLoc,
5519 ExprArg Callee,
5520 ExprArg First,
5521 ExprArg Second) {
5522 Expr *FirstExpr = (Expr *)First.get();
5523 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005524 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005525 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregorb98b1992009-08-11 05:31:07 +00005527 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005528 if (Op == OO_Subscript) {
5529 if (!FirstExpr->getType()->isOverloadableType() &&
5530 !SecondExpr->getType()->isOverloadableType())
5531 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005532 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005533 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005534 } else if (Op == OO_Arrow) {
5535 // -> is never a builtin operation.
5536 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005537 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 if (!FirstExpr->getType()->isOverloadableType()) {
5539 // The argument is not of overloadable type, so try to create a
5540 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005541 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005542 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005543
Douglas Gregorb98b1992009-08-11 05:31:07 +00005544 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5545 }
5546 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005547 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005548 !SecondExpr->getType()->isOverloadableType()) {
5549 // Neither of the arguments is an overloadable type, so try to
5550 // create a built-in binary operation.
5551 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005552 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5554 if (Result.isInvalid())
5555 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557 First.release();
5558 Second.release();
5559 return move(Result);
5560 }
5561 }
Mike Stump1eb44332009-09-09 15:08:12 +00005562
5563 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005564 // used during overload resolution.
5565 Sema::FunctionSet Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005566
John McCallba135432009-11-21 08:51:07 +00005567 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5568 assert(ULE->requiresADL());
5569
5570 // FIXME: Do we have to check
5571 // IsAcceptableNonMemberOperatorCandidate for each of these?
5572 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5573 E = ULE->decls_end(); I != E; ++I)
5574 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5575 } else {
5576 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5577 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5578 }
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregorb98b1992009-08-11 05:31:07 +00005580 // Add any functions found via argument-dependent lookup.
5581 Expr *Args[2] = { FirstExpr, SecondExpr };
5582 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005583 DeclarationName OpName
Douglas Gregorb98b1992009-08-11 05:31:07 +00005584 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redl644be852009-10-23 19:23:15 +00005585 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5586 Functions);
Mike Stump1eb44332009-09-09 15:08:12 +00005587
Douglas Gregorb98b1992009-08-11 05:31:07 +00005588 // Create the overloaded operator invocation for unary operators.
5589 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005590 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5592 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5593 }
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Sebastian Redlf322ed62009-10-29 20:17:01 +00005595 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005596 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5597 OpLoc,
5598 move(First),
5599 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005600
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005602 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005603 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005604 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5606 if (Result.isInvalid())
5607 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005608
Douglas Gregorb98b1992009-08-11 05:31:07 +00005609 First.release();
5610 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005611 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005612}
Mike Stump1eb44332009-09-09 15:08:12 +00005613
Douglas Gregor577f75a2009-08-04 16:50:30 +00005614} // end namespace clang
5615
5616#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H