blob: 922c041393f9184e4676f79011c0d3cb9b6657fc [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.
Douglas Gregor124b8782010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
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.
Douglas Gregor124b8782010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregor124b8782010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000213
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000215 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000224
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall454feb92009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000234
Douglas Gregor577f75a2009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
240 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump1eb44332009-09-09 15:08:12 +0000247
Douglas Gregor6cd21982009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregor577f75a2009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregorb10cd042010-02-21 18:36:56 +0000268 bool MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000269 QualType ObjectType = QualType(),
270 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000271
Douglas Gregor81499bb2009-09-03 22:13:48 +0000272 /// \brief Transform the given declaration name.
273 ///
274 /// By default, transforms the types of conversion function, constructor,
275 /// and destructor names and then (if needed) rebuilds the declaration name.
276 /// Identifiers and selectors are returned unmodified. Sublcasses may
277 /// override this function to provide alternate behavior.
278 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +0000279 SourceLocation Loc,
280 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000281
Douglas Gregor577f75a2009-08-04 16:50:30 +0000282 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000283 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000284 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000285 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000286 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000287 TemplateName TransformTemplateName(TemplateName Name,
288 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000289
Douglas Gregor577f75a2009-08-04 16:50:30 +0000290 /// \brief Transform the given template argument.
291 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000292 /// By default, this operation transforms the type, expression, or
293 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000294 /// new template argument from the transformed result. Subclasses may
295 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000296 ///
297 /// Returns true if there was an error.
298 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
299 TemplateArgumentLoc &Output);
300
301 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
302 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
303 TemplateArgumentLoc &ArgLoc);
304
John McCalla93c9342009-12-07 02:54:59 +0000305 /// \brief Fakes up a TypeSourceInfo for a type.
306 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
307 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000308 getDerived().getBaseLocation());
309 }
Mike Stump1eb44332009-09-09 15:08:12 +0000310
John McCalla2becad2009-10-21 00:40:46 +0000311#define ABSTRACT_TYPELOC(CLASS, PARENT)
312#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000313 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
314 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000315#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000316
Douglas Gregor124b8782010-02-16 19:09:40 +0000317 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
318 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000319
Douglas Gregordd62b152009-10-19 22:04:39 +0000320 QualType
321 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
322 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +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.
John Thompson82287d12010-02-05 00:12:22 +0000431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
432 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000433
Douglas Gregor577f75a2009-08-04 16:50:30 +0000434 /// \brief Build a new extended vector type given the element type and
435 /// number of elements.
436 ///
437 /// By default, performs semantic analysis when building the vector type.
438 /// Subclasses may override this routine to provide different behavior.
439 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
440 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000441
442 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000443 /// given the element type and number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000447 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000448 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000449 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Douglas Gregor577f75a2009-08-04 16:50:30 +0000451 /// \brief Build a new function type.
452 ///
453 /// By default, performs semantic analysis when building the function type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000456 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000457 unsigned NumParamTypes,
458 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000459
John McCalla2becad2009-10-21 00:40:46 +0000460 /// \brief Build a new unprototyped function type.
461 QualType RebuildFunctionNoProtoType(QualType ResultType);
462
John McCalled976492009-12-04 22:46:56 +0000463 /// \brief Rebuild an unresolved typename type, given the decl that
464 /// the UnresolvedUsingTypenameDecl was transformed to.
465 QualType RebuildUnresolvedUsingType(Decl *D);
466
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467 /// \brief Build a new typedef type.
468 QualType RebuildTypedefType(TypedefDecl *Typedef) {
469 return SemaRef.Context.getTypeDeclType(Typedef);
470 }
471
472 /// \brief Build a new class/struct/union type.
473 QualType RebuildRecordType(RecordDecl *Record) {
474 return SemaRef.Context.getTypeDeclType(Record);
475 }
476
477 /// \brief Build a new Enum type.
478 QualType RebuildEnumType(EnumDecl *Enum) {
479 return SemaRef.Context.getTypeDeclType(Enum);
480 }
John McCall7da24312009-09-05 00:15:47 +0000481
482 /// \brief Build a new elaborated type.
483 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
484 return SemaRef.Context.getElaboratedType(T, Tag);
485 }
Mike Stump1eb44332009-09-09 15:08:12 +0000486
487 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000488 ///
489 /// By default, performs semantic analysis when building the typeof type.
490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000491 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000492
Mike Stump1eb44332009-09-09 15:08:12 +0000493 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000494 ///
495 /// By default, builds a new TypeOfType with the given underlying type.
496 QualType RebuildTypeOfType(QualType Underlying);
497
Mike Stump1eb44332009-09-09 15:08:12 +0000498 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000499 ///
500 /// By default, performs semantic analysis when building the decltype type.
501 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000502 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000503
Douglas Gregor577f75a2009-08-04 16:50:30 +0000504 /// \brief Build a new template specialization type.
505 ///
506 /// By default, performs semantic analysis when building the template
507 /// specialization type. Subclasses may override this routine to provide
508 /// different behavior.
509 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000510 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000511 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Douglas Gregor577f75a2009-08-04 16:50:30 +0000513 /// \brief Build a new qualified name type.
514 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000515 /// By default, builds a new QualifiedNameType type from the
516 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000517 /// this routine to provide different behavior.
518 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
519 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000520 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000521
522 /// \brief Build a new typename type that refers to a template-id.
523 ///
524 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000525 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000526 /// different behavior.
527 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000528 if (NNS->isDependent()) {
529 CXXScopeSpec SS;
530 SS.setScopeRep(NNS);
531 if (!SemaRef.computeDeclContext(SS))
532 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000533 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000534 }
Mike Stump1eb44332009-09-09 15:08:12 +0000535
Douglas Gregor577f75a2009-08-04 16:50:30 +0000536 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000537 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000538
539 /// \brief Build a new typename type that refers to an identifier.
540 ///
541 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000542 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000543 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000544 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000545 const IdentifierInfo *Id,
546 SourceRange SR) {
547 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000548 }
Mike Stump1eb44332009-09-09 15:08:12 +0000549
Douglas Gregordcee1a12009-08-06 05:28:30 +0000550 /// \brief Build a new nested-name-specifier given the prefix and an
551 /// identifier that names the next step in the nested-name-specifier.
552 ///
553 /// By default, performs semantic analysis when building the new
554 /// nested-name-specifier. Subclasses may override this routine to provide
555 /// different behavior.
556 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
557 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000558 IdentifierInfo &II,
Douglas Gregorb10cd042010-02-21 18:36:56 +0000559 bool MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000560 QualType ObjectType,
561 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000562
563 /// \brief Build a new nested-name-specifier given the prefix and the
564 /// namespace named in the next step in the nested-name-specifier.
565 ///
566 /// By default, performs semantic analysis when building the new
567 /// nested-name-specifier. Subclasses may override this routine to provide
568 /// different behavior.
569 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
570 SourceRange Range,
571 NamespaceDecl *NS);
572
573 /// \brief Build a new nested-name-specifier given the prefix and the
574 /// type named in the next step in the nested-name-specifier.
575 ///
576 /// By default, performs semantic analysis when building the new
577 /// nested-name-specifier. Subclasses may override this routine to provide
578 /// different behavior.
579 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
580 SourceRange Range,
581 bool TemplateKW,
Douglas Gregorb10cd042010-02-21 18:36:56 +0000582 QualType T,
583 bool MayBePseudoDestructor);
Douglas Gregord1067e52009-08-06 06:41:21 +0000584
585 /// \brief Build a new template name given a nested name specifier, a flag
586 /// indicating whether the "template" keyword was provided, and the template
587 /// that the template name refers to.
588 ///
589 /// By default, builds the new template name directly. Subclasses may override
590 /// this routine to provide different behavior.
591 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
592 bool TemplateKW,
593 TemplateDecl *Template);
594
Douglas Gregord1067e52009-08-06 06:41:21 +0000595 /// \brief Build a new template name given a nested name specifier and the
596 /// name that is referred to as a template.
597 ///
598 /// By default, performs semantic analysis to determine whether the name can
599 /// be resolved to a specific template, then builds the appropriate kind of
600 /// template name. Subclasses may override this routine to provide different
601 /// behavior.
602 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000603 const IdentifierInfo &II,
604 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000605
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000606 /// \brief Build a new template name given a nested name specifier and the
607 /// overloaded operator name that is referred to as a template.
608 ///
609 /// By default, performs semantic analysis to determine whether the name can
610 /// be resolved to a specific template, then builds the appropriate kind of
611 /// template name. Subclasses may override this routine to provide different
612 /// behavior.
613 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
614 OverloadedOperatorKind Operator,
615 QualType ObjectType);
616
Douglas Gregor43959a92009-08-20 07:17:43 +0000617 /// \brief Build a new compound statement.
618 ///
619 /// By default, performs semantic analysis to build the new statement.
620 /// Subclasses may override this routine to provide different behavior.
621 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
622 MultiStmtArg Statements,
623 SourceLocation RBraceLoc,
624 bool IsStmtExpr) {
625 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
626 IsStmtExpr);
627 }
628
629 /// \brief Build a new case statement.
630 ///
631 /// By default, performs semantic analysis to build the new statement.
632 /// Subclasses may override this routine to provide different behavior.
633 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
634 ExprArg LHS,
635 SourceLocation EllipsisLoc,
636 ExprArg RHS,
637 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000638 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000639 ColonLoc);
640 }
Mike Stump1eb44332009-09-09 15:08:12 +0000641
Douglas Gregor43959a92009-08-20 07:17:43 +0000642 /// \brief Attach the body to a new case statement.
643 ///
644 /// By default, performs semantic analysis to build the new statement.
645 /// Subclasses may override this routine to provide different behavior.
646 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
647 getSema().ActOnCaseStmtBody(S.get(), move(Body));
648 return move(S);
649 }
Mike Stump1eb44332009-09-09 15:08:12 +0000650
Douglas Gregor43959a92009-08-20 07:17:43 +0000651 /// \brief Build a new default statement.
652 ///
653 /// By default, performs semantic analysis to build the new statement.
654 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000655 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000656 SourceLocation ColonLoc,
657 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000658 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000659 /*CurScope=*/0);
660 }
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor43959a92009-08-20 07:17:43 +0000662 /// \brief Build a new label statement.
663 ///
664 /// By default, performs semantic analysis to build the new statement.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000666 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000667 IdentifierInfo *Id,
668 SourceLocation ColonLoc,
669 StmtArg SubStmt) {
670 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
671 }
Mike Stump1eb44332009-09-09 15:08:12 +0000672
Douglas Gregor43959a92009-08-20 07:17:43 +0000673 /// \brief Build a new "if" statement.
674 ///
675 /// By default, performs semantic analysis to build the new statement.
676 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000677 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000678 VarDecl *CondVar, StmtArg Then,
679 SourceLocation ElseLoc, StmtArg Else) {
680 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
681 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000682 }
Mike Stump1eb44332009-09-09 15:08:12 +0000683
Douglas Gregor43959a92009-08-20 07:17:43 +0000684 /// \brief Start building a new switch statement.
685 ///
686 /// By default, performs semantic analysis to build the new statement.
687 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000688 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
689 VarDecl *CondVar) {
690 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000691 }
Mike Stump1eb44332009-09-09 15:08:12 +0000692
Douglas Gregor43959a92009-08-20 07:17:43 +0000693 /// \brief Attach the body to the switch statement.
694 ///
695 /// By default, performs semantic analysis to build the new statement.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000697 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000698 StmtArg Switch, StmtArg Body) {
699 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
700 move(Body));
701 }
702
703 /// \brief Build a new while statement.
704 ///
705 /// By default, performs semantic analysis to build the new statement.
706 /// Subclasses may override this routine to provide different behavior.
707 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
708 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000709 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000710 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000711 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
712 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000713 }
Mike Stump1eb44332009-09-09 15:08:12 +0000714
Douglas Gregor43959a92009-08-20 07:17:43 +0000715 /// \brief Build a new do-while statement.
716 ///
717 /// By default, performs semantic analysis to build the new statement.
718 /// Subclasses may override this routine to provide different behavior.
719 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
720 SourceLocation WhileLoc,
721 SourceLocation LParenLoc,
722 ExprArg Cond,
723 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000724 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000725 move(Cond), RParenLoc);
726 }
727
728 /// \brief Build a new for statement.
729 ///
730 /// By default, performs semantic analysis to build the new statement.
731 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000732 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000733 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000734 StmtArg Init, Sema::FullExprArg Cond,
735 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000736 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000737 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
738 DeclPtrTy::make(CondVar),
739 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000740 }
Mike Stump1eb44332009-09-09 15:08:12 +0000741
Douglas Gregor43959a92009-08-20 07:17:43 +0000742 /// \brief Build a new goto statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
746 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
747 SourceLocation LabelLoc,
748 LabelStmt *Label) {
749 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
750 }
751
752 /// \brief Build a new indirect goto statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
756 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
757 SourceLocation StarLoc,
758 ExprArg Target) {
759 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
760 }
Mike Stump1eb44332009-09-09 15:08:12 +0000761
Douglas Gregor43959a92009-08-20 07:17:43 +0000762 /// \brief Build a new return statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
766 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
767 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000768
Douglas Gregor43959a92009-08-20 07:17:43 +0000769 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
770 }
Mike Stump1eb44332009-09-09 15:08:12 +0000771
Douglas Gregor43959a92009-08-20 07:17:43 +0000772 /// \brief Build a new declaration statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
776 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000777 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000778 SourceLocation EndLoc) {
779 return getSema().Owned(
780 new (getSema().Context) DeclStmt(
781 DeclGroupRef::Create(getSema().Context,
782 Decls, NumDecls),
783 StartLoc, EndLoc));
784 }
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Anders Carlsson703e3942010-01-24 05:50:09 +0000786 /// \brief Build a new inline asm statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
790 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
791 bool IsSimple,
792 bool IsVolatile,
793 unsigned NumOutputs,
794 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000795 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000796 MultiExprArg Constraints,
797 MultiExprArg Exprs,
798 ExprArg AsmString,
799 MultiExprArg Clobbers,
800 SourceLocation RParenLoc,
801 bool MSAsm) {
802 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
803 NumInputs, Names, move(Constraints),
804 move(Exprs), move(AsmString), move(Clobbers),
805 RParenLoc, MSAsm);
806 }
807
Douglas Gregor43959a92009-08-20 07:17:43 +0000808 /// \brief Build a new C++ exception declaration.
809 ///
810 /// By default, performs semantic analysis to build the new decaration.
811 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000812 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000813 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000814 IdentifierInfo *Name,
815 SourceLocation Loc,
816 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000817 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000818 TypeRange);
819 }
820
821 /// \brief Build a new C++ catch statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
825 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
826 VarDecl *ExceptionDecl,
827 StmtArg Handler) {
828 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000829 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000830 Handler.takeAs<Stmt>()));
831 }
Mike Stump1eb44332009-09-09 15:08:12 +0000832
Douglas Gregor43959a92009-08-20 07:17:43 +0000833 /// \brief Build a new C++ try statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
838 StmtArg TryBlock,
839 MultiStmtArg Handlers) {
840 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
841 }
Mike Stump1eb44332009-09-09 15:08:12 +0000842
Douglas Gregorb98b1992009-08-11 05:31:07 +0000843 /// \brief Build a new expression that references a declaration.
844 ///
845 /// By default, performs semantic analysis to build the new expression.
846 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000847 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
848 LookupResult &R,
849 bool RequiresADL) {
850 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
851 }
852
853
854 /// \brief Build a new expression that references a declaration.
855 ///
856 /// By default, performs semantic analysis to build the new expression.
857 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000858 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
859 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000860 ValueDecl *VD, SourceLocation Loc,
861 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000862 CXXScopeSpec SS;
863 SS.setScopeRep(Qualifier);
864 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000865
866 // FIXME: loses template args.
867
868 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000869 }
Mike Stump1eb44332009-09-09 15:08:12 +0000870
Douglas Gregorb98b1992009-08-11 05:31:07 +0000871 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000872 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000873 /// By default, performs semantic analysis to build the new expression.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
876 SourceLocation RParen) {
877 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
878 }
879
Douglas Gregora71d8192009-09-04 17:36:40 +0000880 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000881 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000882 /// By default, performs semantic analysis to build the new expression.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
885 SourceLocation OperatorLoc,
886 bool isArrow,
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000887 NestedNameSpecifier *Qualifier,
888 SourceRange QualifierRange,
889 TypeSourceInfo *ScopeType,
890 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +0000891 SourceLocation TildeLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000892 TypeSourceInfo *DestroyedType);
Mike Stump1eb44332009-09-09 15:08:12 +0000893
Douglas Gregorb98b1992009-08-11 05:31:07 +0000894 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000895 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000896 /// By default, performs semantic analysis to build the new expression.
897 /// Subclasses may override this routine to provide different behavior.
898 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
899 UnaryOperator::Opcode Opc,
900 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000901 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000902 }
Mike Stump1eb44332009-09-09 15:08:12 +0000903
Douglas Gregorb98b1992009-08-11 05:31:07 +0000904 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000905 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000906 /// By default, performs semantic analysis to build the new expression.
907 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000908 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000909 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000910 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000911 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000912 }
913
Mike Stump1eb44332009-09-09 15:08:12 +0000914 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000915 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000916 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000917 /// By default, performs semantic analysis to build the new expression.
918 /// Subclasses may override this routine to provide different behavior.
919 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
920 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000921 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000922 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
923 OpLoc, isSizeOf, R);
924 if (Result.isInvalid())
925 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000926
Douglas Gregorb98b1992009-08-11 05:31:07 +0000927 SubExpr.release();
928 return move(Result);
929 }
Mike Stump1eb44332009-09-09 15:08:12 +0000930
Douglas Gregorb98b1992009-08-11 05:31:07 +0000931 /// \brief Build a new array subscript 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.
Mike Stump1eb44332009-09-09 15:08:12 +0000935 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000936 SourceLocation LBracketLoc,
937 ExprArg RHS,
938 SourceLocation RBracketLoc) {
939 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000940 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000941 RBracketLoc);
942 }
943
944 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000945 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000946 /// By default, performs semantic analysis to build the new expression.
947 /// Subclasses may override this routine to provide different behavior.
948 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
949 MultiExprArg Args,
950 SourceLocation *CommaLocs,
951 SourceLocation RParenLoc) {
952 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
953 move(Args), CommaLocs, RParenLoc);
954 }
955
956 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000957 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000958 /// By default, performs semantic analysis to build the new expression.
959 /// Subclasses may override this routine to provide different behavior.
960 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000961 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000962 NestedNameSpecifier *Qualifier,
963 SourceRange QualifierRange,
964 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000965 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000966 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000967 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000968 if (!Member->getDeclName()) {
969 // We have a reference to an unnamed field.
970 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000971
Douglas Gregor83a56c42009-12-24 20:02:50 +0000972 Expr *BaseExpr = Base.takeAs<Expr>();
973 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
974 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000975
Mike Stump1eb44332009-09-09 15:08:12 +0000976 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000977 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000978 Member, MemberLoc,
979 cast<FieldDecl>(Member)->getType());
980 return getSema().Owned(ME);
981 }
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000983 CXXScopeSpec SS;
984 if (Qualifier) {
985 SS.setRange(QualifierRange);
986 SS.setScopeRep(Qualifier);
987 }
988
John McCallaa81e162009-12-01 22:10:20 +0000989 QualType BaseType = ((Expr*) Base.get())->getType();
990
John McCallc2233c52010-01-15 08:34:02 +0000991 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
992 Sema::LookupMemberName);
993 R.addDecl(Member);
994 R.resolveKind();
995
John McCallaa81e162009-12-01 22:10:20 +0000996 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
997 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000998 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +0000999 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001000 }
Mike Stump1eb44332009-09-09 15:08:12 +00001001
Douglas Gregorb98b1992009-08-11 05:31:07 +00001002 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001003 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001004 /// By default, performs semantic analysis to build the new expression.
1005 /// Subclasses may override this routine to provide different behavior.
1006 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1007 BinaryOperator::Opcode Opc,
1008 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001009 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1010 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001011 }
1012
1013 /// \brief Build a new conditional operator 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.
1017 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1018 SourceLocation QuestionLoc,
1019 ExprArg LHS,
1020 SourceLocation ColonLoc,
1021 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001022 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001023 move(LHS), move(RHS));
1024 }
1025
Douglas Gregorb98b1992009-08-11 05:31:07 +00001026 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001027 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001028 /// By default, performs semantic analysis to build the new expression.
1029 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001030 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1031 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001032 SourceLocation RParenLoc,
1033 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001034 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1035 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001036 }
Mike Stump1eb44332009-09-09 15:08:12 +00001037
Douglas Gregorb98b1992009-08-11 05:31:07 +00001038 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001039 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001040 /// By default, performs semantic analysis to build the new expression.
1041 /// Subclasses may override this routine to provide different behavior.
1042 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001043 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001044 SourceLocation RParenLoc,
1045 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001046 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1047 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001048 }
Mike Stump1eb44332009-09-09 15:08:12 +00001049
Douglas Gregorb98b1992009-08-11 05:31:07 +00001050 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001051 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001052 /// By default, performs semantic analysis to build the new expression.
1053 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001054 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001055 SourceLocation OpLoc,
1056 SourceLocation AccessorLoc,
1057 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001058
John McCall129e2df2009-11-30 22:42:35 +00001059 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001060 QualType BaseType = ((Expr*) Base.get())->getType();
1061 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001062 OpLoc, /*IsArrow*/ false,
1063 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001064 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001065 AccessorLoc,
1066 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001067 }
Mike Stump1eb44332009-09-09 15:08:12 +00001068
Douglas Gregorb98b1992009-08-11 05:31:07 +00001069 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001070 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001071 /// By default, performs semantic analysis to build the new expression.
1072 /// Subclasses may override this routine to provide different behavior.
1073 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1074 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001075 SourceLocation RBraceLoc,
1076 QualType ResultTy) {
1077 OwningExprResult Result
1078 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1079 if (Result.isInvalid() || ResultTy->isDependentType())
1080 return move(Result);
1081
1082 // Patch in the result type we were given, which may have been computed
1083 // when the initial InitListExpr was built.
1084 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1085 ILE->setType(ResultTy);
1086 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Douglas Gregorb98b1992009-08-11 05:31:07 +00001089 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001090 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001091 /// By default, performs semantic analysis to build the new expression.
1092 /// Subclasses may override this routine to provide different behavior.
1093 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1094 MultiExprArg ArrayExprs,
1095 SourceLocation EqualOrColonLoc,
1096 bool GNUSyntax,
1097 ExprArg Init) {
1098 OwningExprResult Result
1099 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1100 move(Init));
1101 if (Result.isInvalid())
1102 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001103
Douglas Gregorb98b1992009-08-11 05:31:07 +00001104 ArrayExprs.release();
1105 return move(Result);
1106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Douglas Gregorb98b1992009-08-11 05:31:07 +00001108 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001109 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001110 /// By default, builds the implicit value initialization without performing
1111 /// any semantic analysis. Subclasses may override this routine to provide
1112 /// different behavior.
1113 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1114 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1115 }
Mike Stump1eb44332009-09-09 15:08:12 +00001116
Douglas Gregorb98b1992009-08-11 05:31:07 +00001117 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001118 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001119 /// By default, performs semantic analysis to build the new expression.
1120 /// Subclasses may override this routine to provide different behavior.
1121 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1122 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001123 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001124 RParenLoc);
1125 }
1126
1127 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001128 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001129 /// By default, performs semantic analysis to build the new expression.
1130 /// Subclasses may override this routine to provide different behavior.
1131 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1132 MultiExprArg SubExprs,
1133 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001134 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1135 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001136 }
Mike Stump1eb44332009-09-09 15:08:12 +00001137
Douglas Gregorb98b1992009-08-11 05:31:07 +00001138 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001139 ///
1140 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001141 /// rather than attempting to map the label statement itself.
1142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1144 SourceLocation LabelLoc,
1145 LabelStmt *Label) {
1146 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1147 }
Mike Stump1eb44332009-09-09 15:08:12 +00001148
Douglas Gregorb98b1992009-08-11 05:31:07 +00001149 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001150 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001151 /// By default, performs semantic analysis to build the new expression.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1154 StmtArg SubStmt,
1155 SourceLocation RParenLoc) {
1156 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1157 }
Mike Stump1eb44332009-09-09 15:08:12 +00001158
Douglas Gregorb98b1992009-08-11 05:31:07 +00001159 /// \brief Build a new __builtin_types_compatible_p 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 RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1164 QualType T1, QualType T2,
1165 SourceLocation RParenLoc) {
1166 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1167 T1.getAsOpaquePtr(),
1168 T2.getAsOpaquePtr(),
1169 RParenLoc);
1170 }
Mike Stump1eb44332009-09-09 15:08:12 +00001171
Douglas Gregorb98b1992009-08-11 05:31:07 +00001172 /// \brief Build a new __builtin_choose_expr expression.
1173 ///
1174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
1176 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1177 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1178 SourceLocation RParenLoc) {
1179 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1180 move(Cond), move(LHS), move(RHS),
1181 RParenLoc);
1182 }
Mike Stump1eb44332009-09-09 15:08:12 +00001183
Douglas Gregorb98b1992009-08-11 05:31:07 +00001184 /// \brief Build a new overloaded operator call expression.
1185 ///
1186 /// By default, performs semantic analysis to build the new expression.
1187 /// The semantic analysis provides the behavior of template instantiation,
1188 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001189 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001190 /// argument-dependent lookup, etc. Subclasses may override this routine to
1191 /// provide different behavior.
1192 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1193 SourceLocation OpLoc,
1194 ExprArg Callee,
1195 ExprArg First,
1196 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001197
1198 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001199 /// reinterpret_cast.
1200 ///
1201 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001202 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001203 /// Subclasses may override this routine to provide different behavior.
1204 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1205 Stmt::StmtClass Class,
1206 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001207 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 SourceLocation RAngleLoc,
1209 SourceLocation LParenLoc,
1210 ExprArg SubExpr,
1211 SourceLocation RParenLoc) {
1212 switch (Class) {
1213 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001214 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001215 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001216 move(SubExpr), RParenLoc);
1217
1218 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001219 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001220 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001221 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001222
Douglas Gregorb98b1992009-08-11 05:31:07 +00001223 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001224 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001225 RAngleLoc, LParenLoc,
1226 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001227 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001228
Douglas Gregorb98b1992009-08-11 05:31:07 +00001229 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001230 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001231 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001232 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001233
Douglas Gregorb98b1992009-08-11 05:31:07 +00001234 default:
1235 assert(false && "Invalid C++ named cast");
1236 break;
1237 }
Mike Stump1eb44332009-09-09 15:08:12 +00001238
Douglas Gregorb98b1992009-08-11 05:31:07 +00001239 return getSema().ExprError();
1240 }
Mike Stump1eb44332009-09-09 15:08:12 +00001241
Douglas Gregorb98b1992009-08-11 05:31:07 +00001242 /// \brief Build a new C++ static_cast expression.
1243 ///
1244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
1246 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1247 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001248 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001249 SourceLocation RAngleLoc,
1250 SourceLocation LParenLoc,
1251 ExprArg SubExpr,
1252 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001253 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1254 TInfo, move(SubExpr),
1255 SourceRange(LAngleLoc, RAngleLoc),
1256 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001257 }
1258
1259 /// \brief Build a new C++ dynamic_cast expression.
1260 ///
1261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
1263 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1264 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001265 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001266 SourceLocation RAngleLoc,
1267 SourceLocation LParenLoc,
1268 ExprArg SubExpr,
1269 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001270 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1271 TInfo, move(SubExpr),
1272 SourceRange(LAngleLoc, RAngleLoc),
1273 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001274 }
1275
1276 /// \brief Build a new C++ reinterpret_cast expression.
1277 ///
1278 /// By default, performs semantic analysis to build the new expression.
1279 /// Subclasses may override this routine to provide different behavior.
1280 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1281 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001282 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 SourceLocation RAngleLoc,
1284 SourceLocation LParenLoc,
1285 ExprArg SubExpr,
1286 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001287 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1288 TInfo, move(SubExpr),
1289 SourceRange(LAngleLoc, RAngleLoc),
1290 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 }
1292
1293 /// \brief Build a new C++ const_cast expression.
1294 ///
1295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
1297 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1298 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001299 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 SourceLocation RAngleLoc,
1301 SourceLocation LParenLoc,
1302 ExprArg SubExpr,
1303 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001304 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1305 TInfo, move(SubExpr),
1306 SourceRange(LAngleLoc, RAngleLoc),
1307 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001308 }
Mike Stump1eb44332009-09-09 15:08:12 +00001309
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 /// \brief Build a new C++ functional-style cast expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001315 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001316 SourceLocation LParenLoc,
1317 ExprArg SubExpr,
1318 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001319 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001320 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001321 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001322 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001323 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001324 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001325 RParenLoc);
1326 }
Mike Stump1eb44332009-09-09 15:08:12 +00001327
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 /// \brief Build a new C++ typeid(type) expression.
1329 ///
1330 /// By default, performs semantic analysis to build the new expression.
1331 /// Subclasses may override this routine to provide different behavior.
1332 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1333 SourceLocation LParenLoc,
1334 QualType T,
1335 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001336 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001337 T.getAsOpaquePtr(), RParenLoc);
1338 }
Mike Stump1eb44332009-09-09 15:08:12 +00001339
Douglas Gregorb98b1992009-08-11 05:31:07 +00001340 /// \brief Build a new C++ typeid(expr) expression.
1341 ///
1342 /// By default, performs semantic analysis to build the new expression.
1343 /// Subclasses may override this routine to provide different behavior.
1344 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1345 SourceLocation LParenLoc,
1346 ExprArg Operand,
1347 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001348 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001349 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1350 RParenLoc);
1351 if (Result.isInvalid())
1352 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001353
Douglas Gregorb98b1992009-08-11 05:31:07 +00001354 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1355 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001356 }
1357
Douglas Gregorb98b1992009-08-11 05:31:07 +00001358 /// \brief Build a new C++ "this" expression.
1359 ///
1360 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001361 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001362 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001363 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001364 QualType ThisType,
1365 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001367 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1368 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001369 }
1370
1371 /// \brief Build a new C++ throw expression.
1372 ///
1373 /// By default, performs semantic analysis to build the new expression.
1374 /// Subclasses may override this routine to provide different behavior.
1375 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1376 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1377 }
1378
1379 /// \brief Build a new C++ default-argument expression.
1380 ///
1381 /// By default, builds a new default-argument expression, which does not
1382 /// require any semantic analysis. Subclasses may override this routine to
1383 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001384 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1385 ParmVarDecl *Param) {
1386 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1387 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 }
1389
1390 /// \brief Build a new C++ zero-initialization expression.
1391 ///
1392 /// By default, performs semantic analysis to build the new expression.
1393 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001394 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001395 SourceLocation LParenLoc,
1396 QualType T,
1397 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001398 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1399 T.getAsOpaquePtr(), LParenLoc,
1400 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 0, RParenLoc);
1402 }
Mike Stump1eb44332009-09-09 15:08:12 +00001403
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 /// \brief Build a new C++ "new" expression.
1405 ///
1406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 bool UseGlobal,
1410 SourceLocation PlacementLParen,
1411 MultiExprArg PlacementArgs,
1412 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001413 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 QualType AllocType,
1415 SourceLocation TypeLoc,
1416 SourceRange TypeRange,
1417 ExprArg ArraySize,
1418 SourceLocation ConstructorLParen,
1419 MultiExprArg ConstructorArgs,
1420 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001421 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 PlacementLParen,
1423 move(PlacementArgs),
1424 PlacementRParen,
1425 ParenTypeId,
1426 AllocType,
1427 TypeLoc,
1428 TypeRange,
1429 move(ArraySize),
1430 ConstructorLParen,
1431 move(ConstructorArgs),
1432 ConstructorRParen);
1433 }
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Douglas Gregorb98b1992009-08-11 05:31:07 +00001435 /// \brief Build a new C++ "delete" expression.
1436 ///
1437 /// By default, performs semantic analysis to build the new expression.
1438 /// Subclasses may override this routine to provide different behavior.
1439 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1440 bool IsGlobalDelete,
1441 bool IsArrayForm,
1442 ExprArg Operand) {
1443 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1444 move(Operand));
1445 }
Mike Stump1eb44332009-09-09 15:08:12 +00001446
Douglas Gregorb98b1992009-08-11 05:31:07 +00001447 /// \brief Build a new unary type trait expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
1451 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1452 SourceLocation StartLoc,
1453 SourceLocation LParenLoc,
1454 QualType T,
1455 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001456 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 T.getAsOpaquePtr(), RParenLoc);
1458 }
1459
Mike Stump1eb44332009-09-09 15:08:12 +00001460 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// expression.
1462 ///
1463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001465 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001466 SourceRange QualifierRange,
1467 DeclarationName Name,
1468 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001469 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001470 CXXScopeSpec SS;
1471 SS.setRange(QualifierRange);
1472 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001473
1474 if (TemplateArgs)
1475 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1476 *TemplateArgs);
1477
1478 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001479 }
1480
1481 /// \brief Build a new template-id expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001485 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1486 LookupResult &R,
1487 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001488 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001489 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001490 }
1491
1492 /// \brief Build a new object-construction expression.
1493 ///
1494 /// By default, performs semantic analysis to build the new expression.
1495 /// Subclasses may override this routine to provide different behavior.
1496 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001497 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 CXXConstructorDecl *Constructor,
1499 bool IsElidable,
1500 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001501 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1502 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1503 ConvertedArgs))
1504 return getSema().ExprError();
1505
1506 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1507 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 }
1509
1510 /// \brief Build a new object-construction expression.
1511 ///
1512 /// By default, performs semantic analysis to build the new expression.
1513 /// Subclasses may override this routine to provide different behavior.
1514 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1515 QualType T,
1516 SourceLocation LParenLoc,
1517 MultiExprArg Args,
1518 SourceLocation *Commas,
1519 SourceLocation RParenLoc) {
1520 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1521 T.getAsOpaquePtr(),
1522 LParenLoc,
1523 move(Args),
1524 Commas,
1525 RParenLoc);
1526 }
1527
1528 /// \brief Build a new object-construction expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
1532 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1533 QualType T,
1534 SourceLocation LParenLoc,
1535 MultiExprArg Args,
1536 SourceLocation *Commas,
1537 SourceLocation RParenLoc) {
1538 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1539 /*FIXME*/LParenLoc),
1540 T.getAsOpaquePtr(),
1541 LParenLoc,
1542 move(Args),
1543 Commas,
1544 RParenLoc);
1545 }
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 /// \brief Build a new member reference expression.
1548 ///
1549 /// By default, performs semantic analysis to build the new expression.
1550 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001551 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001552 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 bool IsArrow,
1554 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001555 NestedNameSpecifier *Qualifier,
1556 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001557 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001558 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001559 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001560 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001562 SS.setRange(QualifierRange);
1563 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001564
John McCallaa81e162009-12-01 22:10:20 +00001565 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1566 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001567 SS, FirstQualifierInScope,
1568 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 }
1570
John McCall129e2df2009-11-30 22:42:35 +00001571 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001572 ///
1573 /// By default, performs semantic analysis to build the new expression.
1574 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001575 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001576 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001577 SourceLocation OperatorLoc,
1578 bool IsArrow,
1579 NestedNameSpecifier *Qualifier,
1580 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001581 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001582 LookupResult &R,
1583 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001584 CXXScopeSpec SS;
1585 SS.setRange(QualifierRange);
1586 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001587
John McCallaa81e162009-12-01 22:10:20 +00001588 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1589 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001590 SS, FirstQualifierInScope,
1591 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001592 }
Mike Stump1eb44332009-09-09 15:08:12 +00001593
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// \brief Build a new Objective-C @encode expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1598 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1599 QualType T,
1600 SourceLocation RParenLoc) {
1601 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1602 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001603 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604
1605 /// \brief Build a new Objective-C protocol expression.
1606 ///
1607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
1609 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1610 SourceLocation AtLoc,
1611 SourceLocation ProtoLoc,
1612 SourceLocation LParenLoc,
1613 SourceLocation RParenLoc) {
1614 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1615 Protocol->getIdentifier(),
1616 AtLoc,
1617 ProtoLoc,
1618 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001619 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 }
Mike Stump1eb44332009-09-09 15:08:12 +00001621
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// \brief Build a new shuffle vector expression.
1623 ///
1624 /// By default, performs semantic analysis to build the new expression.
1625 /// Subclasses may override this routine to provide different behavior.
1626 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1627 MultiExprArg SubExprs,
1628 SourceLocation RParenLoc) {
1629 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001630 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001631 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1632 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1633 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1634 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 // Build a reference to the __builtin_shufflevector builtin
1637 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001638 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001639 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001640 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001642
1643 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 unsigned NumSubExprs = SubExprs.size();
1645 Expr **Subs = (Expr **)SubExprs.release();
1646 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1647 Subs, NumSubExprs,
1648 Builtin->getResultType(),
1649 RParenLoc);
1650 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001651
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 // Type-check the __builtin_shufflevector expression.
1653 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1654 if (Result.isInvalid())
1655 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001656
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001658 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001660};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661
Douglas Gregor43959a92009-08-20 07:17:43 +00001662template<typename Derived>
1663Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1664 if (!S)
1665 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregor43959a92009-08-20 07:17:43 +00001667 switch (S->getStmtClass()) {
1668 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregor43959a92009-08-20 07:17:43 +00001670 // Transform individual statement nodes
1671#define STMT(Node, Parent) \
1672 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1673#define EXPR(Node, Parent)
1674#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001675
Douglas Gregor43959a92009-08-20 07:17:43 +00001676 // Transform expressions by calling TransformExpr.
1677#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001678#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001679#define EXPR(Node, Parent) case Stmt::Node##Class:
1680#include "clang/AST/StmtNodes.def"
1681 {
1682 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1683 if (E.isInvalid())
1684 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001686 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001687 }
Mike Stump1eb44332009-09-09 15:08:12 +00001688 }
1689
Douglas Gregor43959a92009-08-20 07:17:43 +00001690 return SemaRef.Owned(S->Retain());
1691}
Mike Stump1eb44332009-09-09 15:08:12 +00001692
1693
Douglas Gregor670444e2009-08-04 22:27:00 +00001694template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001695Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001696 if (!E)
1697 return SemaRef.Owned(E);
1698
1699 switch (E->getStmtClass()) {
1700 case Stmt::NoStmtClass: break;
1701#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001702#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001704 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001706 }
1707
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001709}
1710
1711template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001712NestedNameSpecifier *
1713TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001714 SourceRange Range,
Douglas Gregorb10cd042010-02-21 18:36:56 +00001715 bool MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001716 QualType ObjectType,
1717 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001718 if (!NNS)
1719 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001720
Douglas Gregor43959a92009-08-20 07:17:43 +00001721 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001722 NestedNameSpecifier *Prefix = NNS->getPrefix();
1723 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001724 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorb10cd042010-02-21 18:36:56 +00001725 false,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001726 ObjectType,
1727 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001728 if (!Prefix)
1729 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001730
1731 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001732 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001733 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001734 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001735 }
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Douglas Gregordcee1a12009-08-06 05:28:30 +00001737 switch (NNS->getKind()) {
1738 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001739 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001740 "Identifier nested-name-specifier with no prefix or object type");
1741 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1742 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001743 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001744
1745 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001746 *NNS->getAsIdentifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00001747 MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001748 ObjectType,
1749 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001750
Douglas Gregordcee1a12009-08-06 05:28:30 +00001751 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001752 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001753 = cast_or_null<NamespaceDecl>(
1754 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001755 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001756 Prefix == NNS->getPrefix() &&
1757 NS == NNS->getAsNamespace())
1758 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001759
Douglas Gregordcee1a12009-08-06 05:28:30 +00001760 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1761 }
Mike Stump1eb44332009-09-09 15:08:12 +00001762
Douglas Gregordcee1a12009-08-06 05:28:30 +00001763 case NestedNameSpecifier::Global:
1764 // There is no meaningful transformation that one could perform on the
1765 // global scope.
1766 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001767
Douglas Gregordcee1a12009-08-06 05:28:30 +00001768 case NestedNameSpecifier::TypeSpecWithTemplate:
1769 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001770 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00001771 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1772 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001773 if (T.isNull())
1774 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001775
Douglas Gregordcee1a12009-08-06 05:28:30 +00001776 if (!getDerived().AlwaysRebuild() &&
1777 Prefix == NNS->getPrefix() &&
1778 T == QualType(NNS->getAsType(), 0))
1779 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001780
1781 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1782 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorb10cd042010-02-21 18:36:56 +00001783 T,
1784 MayBePseudoDestructor);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001785 }
1786 }
Mike Stump1eb44332009-09-09 15:08:12 +00001787
Douglas Gregordcee1a12009-08-06 05:28:30 +00001788 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001789 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001790}
1791
1792template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001793DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001794TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001795 SourceLocation Loc,
1796 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001797 if (!Name)
1798 return Name;
1799
1800 switch (Name.getNameKind()) {
1801 case DeclarationName::Identifier:
1802 case DeclarationName::ObjCZeroArgSelector:
1803 case DeclarationName::ObjCOneArgSelector:
1804 case DeclarationName::ObjCMultiArgSelector:
1805 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001806 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001807 case DeclarationName::CXXUsingDirective:
1808 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001809
Douglas Gregor81499bb2009-09-03 22:13:48 +00001810 case DeclarationName::CXXConstructorName:
1811 case DeclarationName::CXXDestructorName:
1812 case DeclarationName::CXXConversionFunctionName: {
1813 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregor124b8782010-02-16 19:09:40 +00001814 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1815 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00001816 if (T.isNull())
1817 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001818
Douglas Gregor81499bb2009-09-03 22:13:48 +00001819 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001820 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001821 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001822 }
Mike Stump1eb44332009-09-09 15:08:12 +00001823 }
1824
Douglas Gregor81499bb2009-09-03 22:13:48 +00001825 return DeclarationName();
1826}
1827
1828template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001829TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001830TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1831 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00001832 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001833 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001834 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001835 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregorb10cd042010-02-21 18:36:56 +00001836 false,
Douglas Gregor124b8782010-02-16 19:09:40 +00001837 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001838 if (!NNS)
1839 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001840
Douglas Gregord1067e52009-08-06 06:41:21 +00001841 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001842 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001843 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1844 if (!TransTemplate)
1845 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001846
Douglas Gregord1067e52009-08-06 06:41:21 +00001847 if (!getDerived().AlwaysRebuild() &&
1848 NNS == QTN->getQualifier() &&
1849 TransTemplate == Template)
1850 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001851
Douglas Gregord1067e52009-08-06 06:41:21 +00001852 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1853 TransTemplate);
1854 }
Mike Stump1eb44332009-09-09 15:08:12 +00001855
John McCallf7a1a742009-11-24 19:00:30 +00001856 // These should be getting filtered out before they make it into the AST.
1857 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001858 }
Mike Stump1eb44332009-09-09 15:08:12 +00001859
Douglas Gregord1067e52009-08-06 06:41:21 +00001860 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001861 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001862 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001863 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregorb10cd042010-02-21 18:36:56 +00001864 false,
Douglas Gregor124b8782010-02-16 19:09:40 +00001865 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001866 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001867 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001868
Douglas Gregord1067e52009-08-06 06:41:21 +00001869 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001870 NNS == DTN->getQualifier() &&
1871 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001872 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001873
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001874 if (DTN->isIdentifier())
1875 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1876 ObjectType);
1877
1878 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1879 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001880 }
Mike Stump1eb44332009-09-09 15:08:12 +00001881
Douglas Gregord1067e52009-08-06 06:41:21 +00001882 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001883 TemplateDecl *TransTemplate
Douglas Gregord1067e52009-08-06 06:41:21 +00001884 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1885 if (!TransTemplate)
1886 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001887
Douglas Gregord1067e52009-08-06 06:41:21 +00001888 if (!getDerived().AlwaysRebuild() &&
1889 TransTemplate == Template)
1890 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001891
Douglas Gregord1067e52009-08-06 06:41:21 +00001892 return TemplateName(TransTemplate);
1893 }
Mike Stump1eb44332009-09-09 15:08:12 +00001894
John McCallf7a1a742009-11-24 19:00:30 +00001895 // These should be getting filtered out before they reach the AST.
1896 assert(false && "overloaded function decl survived to here");
1897 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001898}
1899
1900template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001901void TreeTransform<Derived>::InventTemplateArgumentLoc(
1902 const TemplateArgument &Arg,
1903 TemplateArgumentLoc &Output) {
1904 SourceLocation Loc = getDerived().getBaseLocation();
1905 switch (Arg.getKind()) {
1906 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001907 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001908 break;
1909
1910 case TemplateArgument::Type:
1911 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001912 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001913
1914 break;
1915
Douglas Gregor788cd062009-11-11 01:00:40 +00001916 case TemplateArgument::Template:
1917 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1918 break;
1919
John McCall833ca992009-10-29 08:12:44 +00001920 case TemplateArgument::Expression:
1921 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1922 break;
1923
1924 case TemplateArgument::Declaration:
1925 case TemplateArgument::Integral:
1926 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001927 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001928 break;
1929 }
1930}
1931
1932template<typename Derived>
1933bool TreeTransform<Derived>::TransformTemplateArgument(
1934 const TemplateArgumentLoc &Input,
1935 TemplateArgumentLoc &Output) {
1936 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001937 switch (Arg.getKind()) {
1938 case TemplateArgument::Null:
1939 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001940 Output = Input;
1941 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001942
Douglas Gregor670444e2009-08-04 22:27:00 +00001943 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001944 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001945 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001946 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001947
1948 DI = getDerived().TransformType(DI);
1949 if (!DI) return true;
1950
1951 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1952 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001953 }
Mike Stump1eb44332009-09-09 15:08:12 +00001954
Douglas Gregor670444e2009-08-04 22:27:00 +00001955 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001956 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001957 DeclarationName Name;
1958 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1959 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001960 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor670444e2009-08-04 22:27:00 +00001961 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001962 if (!D) return true;
1963
John McCall828bff22009-10-29 18:45:58 +00001964 Expr *SourceExpr = Input.getSourceDeclExpression();
1965 if (SourceExpr) {
1966 EnterExpressionEvaluationContext Unevaluated(getSema(),
1967 Action::Unevaluated);
1968 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1969 if (E.isInvalid())
1970 SourceExpr = NULL;
1971 else {
1972 SourceExpr = E.takeAs<Expr>();
1973 SourceExpr->Retain();
1974 }
1975 }
1976
1977 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001978 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001979 }
Mike Stump1eb44332009-09-09 15:08:12 +00001980
Douglas Gregor788cd062009-11-11 01:00:40 +00001981 case TemplateArgument::Template: {
1982 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1983 TemplateName Template
1984 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1985 if (Template.isNull())
1986 return true;
1987
1988 Output = TemplateArgumentLoc(TemplateArgument(Template),
1989 Input.getTemplateQualifierRange(),
1990 Input.getTemplateNameLoc());
1991 return false;
1992 }
1993
Douglas Gregor670444e2009-08-04 22:27:00 +00001994 case TemplateArgument::Expression: {
1995 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00001996 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001997 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00001998
John McCall833ca992009-10-29 08:12:44 +00001999 Expr *InputExpr = Input.getSourceExpression();
2000 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2001
2002 Sema::OwningExprResult E
2003 = getDerived().TransformExpr(InputExpr);
2004 if (E.isInvalid()) return true;
2005
2006 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002007 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002008 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2009 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002010 }
Mike Stump1eb44332009-09-09 15:08:12 +00002011
Douglas Gregor670444e2009-08-04 22:27:00 +00002012 case TemplateArgument::Pack: {
2013 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2014 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002015 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002016 AEnd = Arg.pack_end();
2017 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002018
John McCall833ca992009-10-29 08:12:44 +00002019 // FIXME: preserve source information here when we start
2020 // caring about parameter packs.
2021
John McCall828bff22009-10-29 18:45:58 +00002022 TemplateArgumentLoc InputArg;
2023 TemplateArgumentLoc OutputArg;
2024 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2025 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002026 return true;
2027
John McCall828bff22009-10-29 18:45:58 +00002028 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002029 }
2030 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002031 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002032 true);
John McCall828bff22009-10-29 18:45:58 +00002033 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002034 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002035 }
2036 }
Mike Stump1eb44332009-09-09 15:08:12 +00002037
Douglas Gregor670444e2009-08-04 22:27:00 +00002038 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002039 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002040}
2041
Douglas Gregor577f75a2009-08-04 16:50:30 +00002042//===----------------------------------------------------------------------===//
2043// Type transformation
2044//===----------------------------------------------------------------------===//
2045
2046template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002047QualType TreeTransform<Derived>::TransformType(QualType T,
2048 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002049 if (getDerived().AlreadyTransformed(T))
2050 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002051
John McCalla2becad2009-10-21 00:40:46 +00002052 // Temporary workaround. All of these transformations should
2053 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002054 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002055 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002056
Douglas Gregor124b8782010-02-16 19:09:40 +00002057 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002058
John McCalla2becad2009-10-21 00:40:46 +00002059 if (!NewDI)
2060 return QualType();
2061
2062 return NewDI->getType();
2063}
2064
2065template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002066TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2067 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002068 if (getDerived().AlreadyTransformed(DI->getType()))
2069 return DI;
2070
2071 TypeLocBuilder TLB;
2072
2073 TypeLoc TL = DI->getTypeLoc();
2074 TLB.reserve(TL.getFullDataSize());
2075
Douglas Gregor124b8782010-02-16 19:09:40 +00002076 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002077 if (Result.isNull())
2078 return 0;
2079
John McCalla93c9342009-12-07 02:54:59 +00002080 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002081}
2082
2083template<typename Derived>
2084QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002085TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2086 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002087 switch (T.getTypeLocClass()) {
2088#define ABSTRACT_TYPELOC(CLASS, PARENT)
2089#define TYPELOC(CLASS, PARENT) \
2090 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002091 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2092 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002093#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002094 }
Mike Stump1eb44332009-09-09 15:08:12 +00002095
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002096 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002097 return QualType();
2098}
2099
2100/// FIXME: By default, this routine adds type qualifiers only to types
2101/// that can have qualifiers, and silently suppresses those qualifiers
2102/// that are not permitted (e.g., qualifiers on reference or function
2103/// types). This is the right thing for template instantiation, but
2104/// probably not for other clients.
2105template<typename Derived>
2106QualType
2107TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002108 QualifiedTypeLoc T,
2109 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002110 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002111
Douglas Gregor124b8782010-02-16 19:09:40 +00002112 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2113 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002114 if (Result.isNull())
2115 return QualType();
2116
2117 // Silently suppress qualifiers if the result type can't be qualified.
2118 // FIXME: this is the right thing for template instantiation, but
2119 // probably not for other clients.
2120 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002121 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002122
John McCalla2becad2009-10-21 00:40:46 +00002123 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2124
2125 TLB.push<QualifiedTypeLoc>(Result);
2126
2127 // No location information to preserve.
2128
2129 return Result;
2130}
2131
2132template <class TyLoc> static inline
2133QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2134 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2135 NewT.setNameLoc(T.getNameLoc());
2136 return T.getType();
2137}
2138
2139// Ugly metaprogramming macros because I couldn't be bothered to make
2140// the equivalent template version work.
2141#define TransformPointerLikeType(TypeClass) do { \
2142 QualType PointeeType \
2143 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2144 if (PointeeType.isNull()) \
2145 return QualType(); \
2146 \
2147 QualType Result = TL.getType(); \
2148 if (getDerived().AlwaysRebuild() || \
2149 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002150 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2151 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002152 if (Result.isNull()) \
2153 return QualType(); \
2154 } \
2155 \
2156 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2157 NewT.setSigilLoc(TL.getSigilLoc()); \
2158 \
2159 return Result; \
2160} while(0)
2161
John McCalla2becad2009-10-21 00:40:46 +00002162template<typename Derived>
2163QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002164 BuiltinTypeLoc T,
2165 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002166 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2167 NewT.setBuiltinLoc(T.getBuiltinLoc());
2168 if (T.needsExtraLocalData())
2169 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2170 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002171}
Mike Stump1eb44332009-09-09 15:08:12 +00002172
Douglas Gregor577f75a2009-08-04 16:50:30 +00002173template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002174QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002175 ComplexTypeLoc T,
2176 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002177 // FIXME: recurse?
2178 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002179}
Mike Stump1eb44332009-09-09 15:08:12 +00002180
Douglas Gregor577f75a2009-08-04 16:50:30 +00002181template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002182QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002183 PointerTypeLoc TL,
2184 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002185 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002186}
Mike Stump1eb44332009-09-09 15:08:12 +00002187
2188template<typename Derived>
2189QualType
John McCalla2becad2009-10-21 00:40:46 +00002190TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002191 BlockPointerTypeLoc TL,
2192 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002193 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002194}
2195
John McCall85737a72009-10-30 00:06:24 +00002196/// Transforms a reference type. Note that somewhat paradoxically we
2197/// don't care whether the type itself is an l-value type or an r-value
2198/// type; we only care if the type was *written* as an l-value type
2199/// or an r-value type.
2200template<typename Derived>
2201QualType
2202TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002203 ReferenceTypeLoc TL,
2204 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002205 const ReferenceType *T = TL.getTypePtr();
2206
2207 // Note that this works with the pointee-as-written.
2208 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2209 if (PointeeType.isNull())
2210 return QualType();
2211
2212 QualType Result = TL.getType();
2213 if (getDerived().AlwaysRebuild() ||
2214 PointeeType != T->getPointeeTypeAsWritten()) {
2215 Result = getDerived().RebuildReferenceType(PointeeType,
2216 T->isSpelledAsLValue(),
2217 TL.getSigilLoc());
2218 if (Result.isNull())
2219 return QualType();
2220 }
2221
2222 // r-value references can be rebuilt as l-value references.
2223 ReferenceTypeLoc NewTL;
2224 if (isa<LValueReferenceType>(Result))
2225 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2226 else
2227 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2228 NewTL.setSigilLoc(TL.getSigilLoc());
2229
2230 return Result;
2231}
2232
Mike Stump1eb44332009-09-09 15:08:12 +00002233template<typename Derived>
2234QualType
John McCalla2becad2009-10-21 00:40:46 +00002235TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002236 LValueReferenceTypeLoc TL,
2237 QualType ObjectType) {
2238 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002239}
2240
Mike Stump1eb44332009-09-09 15:08:12 +00002241template<typename Derived>
2242QualType
John McCalla2becad2009-10-21 00:40:46 +00002243TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002244 RValueReferenceTypeLoc TL,
2245 QualType ObjectType) {
2246 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002247}
Mike Stump1eb44332009-09-09 15:08:12 +00002248
Douglas Gregor577f75a2009-08-04 16:50:30 +00002249template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002250QualType
John McCalla2becad2009-10-21 00:40:46 +00002251TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002252 MemberPointerTypeLoc TL,
2253 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002254 MemberPointerType *T = TL.getTypePtr();
2255
2256 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002257 if (PointeeType.isNull())
2258 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002259
John McCalla2becad2009-10-21 00:40:46 +00002260 // TODO: preserve source information for this.
2261 QualType ClassType
2262 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002263 if (ClassType.isNull())
2264 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002265
John McCalla2becad2009-10-21 00:40:46 +00002266 QualType Result = TL.getType();
2267 if (getDerived().AlwaysRebuild() ||
2268 PointeeType != T->getPointeeType() ||
2269 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002270 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2271 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002272 if (Result.isNull())
2273 return QualType();
2274 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002275
John McCalla2becad2009-10-21 00:40:46 +00002276 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2277 NewTL.setSigilLoc(TL.getSigilLoc());
2278
2279 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002280}
2281
Mike Stump1eb44332009-09-09 15:08:12 +00002282template<typename Derived>
2283QualType
John McCalla2becad2009-10-21 00:40:46 +00002284TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002285 ConstantArrayTypeLoc TL,
2286 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002287 ConstantArrayType *T = TL.getTypePtr();
2288 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002289 if (ElementType.isNull())
2290 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002291
John McCalla2becad2009-10-21 00:40:46 +00002292 QualType Result = TL.getType();
2293 if (getDerived().AlwaysRebuild() ||
2294 ElementType != T->getElementType()) {
2295 Result = getDerived().RebuildConstantArrayType(ElementType,
2296 T->getSizeModifier(),
2297 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002298 T->getIndexTypeCVRQualifiers(),
2299 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002300 if (Result.isNull())
2301 return QualType();
2302 }
2303
2304 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2305 NewTL.setLBracketLoc(TL.getLBracketLoc());
2306 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002307
John McCalla2becad2009-10-21 00:40:46 +00002308 Expr *Size = TL.getSizeExpr();
2309 if (Size) {
2310 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2311 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2312 }
2313 NewTL.setSizeExpr(Size);
2314
2315 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002316}
Mike Stump1eb44332009-09-09 15:08:12 +00002317
Douglas Gregor577f75a2009-08-04 16:50:30 +00002318template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002319QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002320 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002321 IncompleteArrayTypeLoc TL,
2322 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002323 IncompleteArrayType *T = TL.getTypePtr();
2324 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002325 if (ElementType.isNull())
2326 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002327
John McCalla2becad2009-10-21 00:40:46 +00002328 QualType Result = TL.getType();
2329 if (getDerived().AlwaysRebuild() ||
2330 ElementType != T->getElementType()) {
2331 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002332 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002333 T->getIndexTypeCVRQualifiers(),
2334 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002335 if (Result.isNull())
2336 return QualType();
2337 }
2338
2339 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2340 NewTL.setLBracketLoc(TL.getLBracketLoc());
2341 NewTL.setRBracketLoc(TL.getRBracketLoc());
2342 NewTL.setSizeExpr(0);
2343
2344 return Result;
2345}
2346
2347template<typename Derived>
2348QualType
2349TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002350 VariableArrayTypeLoc TL,
2351 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002352 VariableArrayType *T = TL.getTypePtr();
2353 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2354 if (ElementType.isNull())
2355 return QualType();
2356
2357 // Array bounds are not potentially evaluated contexts
2358 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2359
2360 Sema::OwningExprResult SizeResult
2361 = getDerived().TransformExpr(T->getSizeExpr());
2362 if (SizeResult.isInvalid())
2363 return QualType();
2364
2365 Expr *Size = static_cast<Expr*>(SizeResult.get());
2366
2367 QualType Result = TL.getType();
2368 if (getDerived().AlwaysRebuild() ||
2369 ElementType != T->getElementType() ||
2370 Size != T->getSizeExpr()) {
2371 Result = getDerived().RebuildVariableArrayType(ElementType,
2372 T->getSizeModifier(),
2373 move(SizeResult),
2374 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002375 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002376 if (Result.isNull())
2377 return QualType();
2378 }
2379 else SizeResult.take();
2380
2381 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2382 NewTL.setLBracketLoc(TL.getLBracketLoc());
2383 NewTL.setRBracketLoc(TL.getRBracketLoc());
2384 NewTL.setSizeExpr(Size);
2385
2386 return Result;
2387}
2388
2389template<typename Derived>
2390QualType
2391TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002392 DependentSizedArrayTypeLoc TL,
2393 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002394 DependentSizedArrayType *T = TL.getTypePtr();
2395 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2396 if (ElementType.isNull())
2397 return QualType();
2398
2399 // Array bounds are not potentially evaluated contexts
2400 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2401
2402 Sema::OwningExprResult SizeResult
2403 = getDerived().TransformExpr(T->getSizeExpr());
2404 if (SizeResult.isInvalid())
2405 return QualType();
2406
2407 Expr *Size = static_cast<Expr*>(SizeResult.get());
2408
2409 QualType Result = TL.getType();
2410 if (getDerived().AlwaysRebuild() ||
2411 ElementType != T->getElementType() ||
2412 Size != T->getSizeExpr()) {
2413 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2414 T->getSizeModifier(),
2415 move(SizeResult),
2416 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002417 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002418 if (Result.isNull())
2419 return QualType();
2420 }
2421 else SizeResult.take();
2422
2423 // We might have any sort of array type now, but fortunately they
2424 // all have the same location layout.
2425 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2426 NewTL.setLBracketLoc(TL.getLBracketLoc());
2427 NewTL.setRBracketLoc(TL.getRBracketLoc());
2428 NewTL.setSizeExpr(Size);
2429
2430 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002431}
Mike Stump1eb44332009-09-09 15:08:12 +00002432
2433template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002434QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002435 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002436 DependentSizedExtVectorTypeLoc TL,
2437 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002438 DependentSizedExtVectorType *T = TL.getTypePtr();
2439
2440 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002441 QualType ElementType = getDerived().TransformType(T->getElementType());
2442 if (ElementType.isNull())
2443 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002444
Douglas Gregor670444e2009-08-04 22:27:00 +00002445 // Vector sizes are not potentially evaluated contexts
2446 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2447
Douglas Gregor577f75a2009-08-04 16:50:30 +00002448 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2449 if (Size.isInvalid())
2450 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002451
John McCalla2becad2009-10-21 00:40:46 +00002452 QualType Result = TL.getType();
2453 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002454 ElementType != T->getElementType() ||
2455 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002456 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002457 move(Size),
2458 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002459 if (Result.isNull())
2460 return QualType();
2461 }
2462 else Size.take();
2463
2464 // Result might be dependent or not.
2465 if (isa<DependentSizedExtVectorType>(Result)) {
2466 DependentSizedExtVectorTypeLoc NewTL
2467 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2468 NewTL.setNameLoc(TL.getNameLoc());
2469 } else {
2470 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2471 NewTL.setNameLoc(TL.getNameLoc());
2472 }
2473
2474 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002475}
Mike Stump1eb44332009-09-09 15:08:12 +00002476
2477template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002478QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002479 VectorTypeLoc TL,
2480 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002481 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002482 QualType ElementType = getDerived().TransformType(T->getElementType());
2483 if (ElementType.isNull())
2484 return QualType();
2485
John McCalla2becad2009-10-21 00:40:46 +00002486 QualType Result = TL.getType();
2487 if (getDerived().AlwaysRebuild() ||
2488 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002489 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2490 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002491 if (Result.isNull())
2492 return QualType();
2493 }
2494
2495 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2496 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002497
John McCalla2becad2009-10-21 00:40:46 +00002498 return Result;
2499}
2500
2501template<typename Derived>
2502QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002503 ExtVectorTypeLoc TL,
2504 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002505 VectorType *T = TL.getTypePtr();
2506 QualType ElementType = getDerived().TransformType(T->getElementType());
2507 if (ElementType.isNull())
2508 return QualType();
2509
2510 QualType Result = TL.getType();
2511 if (getDerived().AlwaysRebuild() ||
2512 ElementType != T->getElementType()) {
2513 Result = getDerived().RebuildExtVectorType(ElementType,
2514 T->getNumElements(),
2515 /*FIXME*/ SourceLocation());
2516 if (Result.isNull())
2517 return QualType();
2518 }
2519
2520 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2521 NewTL.setNameLoc(TL.getNameLoc());
2522
2523 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002524}
Mike Stump1eb44332009-09-09 15:08:12 +00002525
2526template<typename Derived>
2527QualType
John McCalla2becad2009-10-21 00:40:46 +00002528TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002529 FunctionProtoTypeLoc TL,
2530 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002531 FunctionProtoType *T = TL.getTypePtr();
2532 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002533 if (ResultType.isNull())
2534 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002535
John McCalla2becad2009-10-21 00:40:46 +00002536 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002537 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002538 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2539 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2540 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002541
John McCalla2becad2009-10-21 00:40:46 +00002542 QualType NewType;
2543 ParmVarDecl *NewParm;
2544
2545 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002546 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002547 assert(OldDI->getType() == T->getArgType(i));
2548
John McCalla93c9342009-12-07 02:54:59 +00002549 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002550 if (!NewDI)
2551 return QualType();
2552
2553 if (NewDI == OldDI)
2554 NewParm = OldParm;
2555 else
2556 NewParm = ParmVarDecl::Create(SemaRef.Context,
2557 OldParm->getDeclContext(),
2558 OldParm->getLocation(),
2559 OldParm->getIdentifier(),
2560 NewDI->getType(),
2561 NewDI,
2562 OldParm->getStorageClass(),
2563 /* DefArg */ NULL);
2564 NewType = NewParm->getType();
2565
2566 // Deal with the possibility that we don't have a parameter
2567 // declaration for this parameter.
2568 } else {
2569 NewParm = 0;
2570
2571 QualType OldType = T->getArgType(i);
2572 NewType = getDerived().TransformType(OldType);
2573 if (NewType.isNull())
2574 return QualType();
2575 }
2576
2577 ParamTypes.push_back(NewType);
2578 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002579 }
Mike Stump1eb44332009-09-09 15:08:12 +00002580
John McCalla2becad2009-10-21 00:40:46 +00002581 QualType Result = TL.getType();
2582 if (getDerived().AlwaysRebuild() ||
2583 ResultType != T->getResultType() ||
2584 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2585 Result = getDerived().RebuildFunctionProtoType(ResultType,
2586 ParamTypes.data(),
2587 ParamTypes.size(),
2588 T->isVariadic(),
2589 T->getTypeQuals());
2590 if (Result.isNull())
2591 return QualType();
2592 }
Mike Stump1eb44332009-09-09 15:08:12 +00002593
John McCalla2becad2009-10-21 00:40:46 +00002594 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2595 NewTL.setLParenLoc(TL.getLParenLoc());
2596 NewTL.setRParenLoc(TL.getRParenLoc());
2597 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2598 NewTL.setArg(i, ParamDecls[i]);
2599
2600 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002601}
Mike Stump1eb44332009-09-09 15:08:12 +00002602
Douglas Gregor577f75a2009-08-04 16:50:30 +00002603template<typename Derived>
2604QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002605 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002606 FunctionNoProtoTypeLoc TL,
2607 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002608 FunctionNoProtoType *T = TL.getTypePtr();
2609 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2610 if (ResultType.isNull())
2611 return QualType();
2612
2613 QualType Result = TL.getType();
2614 if (getDerived().AlwaysRebuild() ||
2615 ResultType != T->getResultType())
2616 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2617
2618 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2619 NewTL.setLParenLoc(TL.getLParenLoc());
2620 NewTL.setRParenLoc(TL.getRParenLoc());
2621
2622 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002623}
Mike Stump1eb44332009-09-09 15:08:12 +00002624
John McCalled976492009-12-04 22:46:56 +00002625template<typename Derived> QualType
2626TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002627 UnresolvedUsingTypeLoc TL,
2628 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002629 UnresolvedUsingType *T = TL.getTypePtr();
2630 Decl *D = getDerived().TransformDecl(T->getDecl());
2631 if (!D)
2632 return QualType();
2633
2634 QualType Result = TL.getType();
2635 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2636 Result = getDerived().RebuildUnresolvedUsingType(D);
2637 if (Result.isNull())
2638 return QualType();
2639 }
2640
2641 // We might get an arbitrary type spec type back. We should at
2642 // least always get a type spec type, though.
2643 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2644 NewTL.setNameLoc(TL.getNameLoc());
2645
2646 return Result;
2647}
2648
Douglas Gregor577f75a2009-08-04 16:50:30 +00002649template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002650QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002651 TypedefTypeLoc TL,
2652 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002653 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002654 TypedefDecl *Typedef
2655 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2656 if (!Typedef)
2657 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002658
John McCalla2becad2009-10-21 00:40:46 +00002659 QualType Result = TL.getType();
2660 if (getDerived().AlwaysRebuild() ||
2661 Typedef != T->getDecl()) {
2662 Result = getDerived().RebuildTypedefType(Typedef);
2663 if (Result.isNull())
2664 return QualType();
2665 }
Mike Stump1eb44332009-09-09 15:08:12 +00002666
John McCalla2becad2009-10-21 00:40:46 +00002667 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2668 NewTL.setNameLoc(TL.getNameLoc());
2669
2670 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002671}
Mike Stump1eb44332009-09-09 15:08:12 +00002672
Douglas Gregor577f75a2009-08-04 16:50:30 +00002673template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002674QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002675 TypeOfExprTypeLoc TL,
2676 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002677 // typeof expressions are not potentially evaluated contexts
2678 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002679
John McCallcfb708c2010-01-13 20:03:27 +00002680 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002681 if (E.isInvalid())
2682 return QualType();
2683
John McCalla2becad2009-10-21 00:40:46 +00002684 QualType Result = TL.getType();
2685 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002686 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002687 Result = getDerived().RebuildTypeOfExprType(move(E));
2688 if (Result.isNull())
2689 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002690 }
John McCalla2becad2009-10-21 00:40:46 +00002691 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002692
John McCalla2becad2009-10-21 00:40:46 +00002693 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002694 NewTL.setTypeofLoc(TL.getTypeofLoc());
2695 NewTL.setLParenLoc(TL.getLParenLoc());
2696 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002697
2698 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002699}
Mike Stump1eb44332009-09-09 15:08:12 +00002700
2701template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002702QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002703 TypeOfTypeLoc TL,
2704 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00002705 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2706 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2707 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002708 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002709
John McCalla2becad2009-10-21 00:40:46 +00002710 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002711 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2712 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002713 if (Result.isNull())
2714 return QualType();
2715 }
Mike Stump1eb44332009-09-09 15:08:12 +00002716
John McCalla2becad2009-10-21 00:40:46 +00002717 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002718 NewTL.setTypeofLoc(TL.getTypeofLoc());
2719 NewTL.setLParenLoc(TL.getLParenLoc());
2720 NewTL.setRParenLoc(TL.getRParenLoc());
2721 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002722
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>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002728 DecltypeTypeLoc TL,
2729 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002730 DecltypeType *T = TL.getTypePtr();
2731
Douglas Gregor670444e2009-08-04 22:27:00 +00002732 // decltype expressions are not potentially evaluated contexts
2733 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002734
Douglas Gregor577f75a2009-08-04 16:50:30 +00002735 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2736 if (E.isInvalid())
2737 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002738
John McCalla2becad2009-10-21 00:40:46 +00002739 QualType Result = TL.getType();
2740 if (getDerived().AlwaysRebuild() ||
2741 E.get() != T->getUnderlyingExpr()) {
2742 Result = getDerived().RebuildDecltypeType(move(E));
2743 if (Result.isNull())
2744 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002745 }
John McCalla2becad2009-10-21 00:40:46 +00002746 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002747
John McCalla2becad2009-10-21 00:40:46 +00002748 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2749 NewTL.setNameLoc(TL.getNameLoc());
2750
2751 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002752}
2753
2754template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002755QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002756 RecordTypeLoc TL,
2757 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002758 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759 RecordDecl *Record
John McCalla2becad2009-10-21 00:40:46 +00002760 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002761 if (!Record)
2762 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002763
John McCalla2becad2009-10-21 00:40:46 +00002764 QualType Result = TL.getType();
2765 if (getDerived().AlwaysRebuild() ||
2766 Record != T->getDecl()) {
2767 Result = getDerived().RebuildRecordType(Record);
2768 if (Result.isNull())
2769 return QualType();
2770 }
Mike Stump1eb44332009-09-09 15:08:12 +00002771
John McCalla2becad2009-10-21 00:40:46 +00002772 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2773 NewTL.setNameLoc(TL.getNameLoc());
2774
2775 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002776}
Mike Stump1eb44332009-09-09 15:08:12 +00002777
2778template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002779QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002780 EnumTypeLoc TL,
2781 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002782 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002783 EnumDecl *Enum
John McCalla2becad2009-10-21 00:40:46 +00002784 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002785 if (!Enum)
2786 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002787
John McCalla2becad2009-10-21 00:40:46 +00002788 QualType Result = TL.getType();
2789 if (getDerived().AlwaysRebuild() ||
2790 Enum != T->getDecl()) {
2791 Result = getDerived().RebuildEnumType(Enum);
2792 if (Result.isNull())
2793 return QualType();
2794 }
Mike Stump1eb44332009-09-09 15:08:12 +00002795
John McCalla2becad2009-10-21 00:40:46 +00002796 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2797 NewTL.setNameLoc(TL.getNameLoc());
2798
2799 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002800}
John McCall7da24312009-09-05 00:15:47 +00002801
2802template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002803QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002804 ElaboratedTypeLoc TL,
2805 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002806 ElaboratedType *T = TL.getTypePtr();
2807
2808 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002809 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2810 if (Underlying.isNull())
2811 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002812
John McCalla2becad2009-10-21 00:40:46 +00002813 QualType Result = TL.getType();
2814 if (getDerived().AlwaysRebuild() ||
2815 Underlying != T->getUnderlyingType()) {
2816 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2817 if (Result.isNull())
2818 return QualType();
2819 }
Mike Stump1eb44332009-09-09 15:08:12 +00002820
John McCalla2becad2009-10-21 00:40:46 +00002821 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2822 NewTL.setNameLoc(TL.getNameLoc());
2823
2824 return Result;
John McCall7da24312009-09-05 00:15:47 +00002825}
Mike Stump1eb44332009-09-09 15:08:12 +00002826
2827
Douglas Gregor577f75a2009-08-04 16:50:30 +00002828template<typename Derived>
2829QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002830 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002831 TemplateTypeParmTypeLoc TL,
2832 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002833 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002834}
2835
Mike Stump1eb44332009-09-09 15:08:12 +00002836template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002837QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002838 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002839 SubstTemplateTypeParmTypeLoc TL,
2840 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002841 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002842}
2843
2844template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002845QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2846 const TemplateSpecializationType *TST,
2847 QualType ObjectType) {
2848 // FIXME: this entire method is a temporary workaround; callers
2849 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002850
John McCall833ca992009-10-29 08:12:44 +00002851 // Fake up a TemplateSpecializationTypeLoc.
2852 TypeLocBuilder TLB;
2853 TemplateSpecializationTypeLoc TL
2854 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2855
John McCall828bff22009-10-29 18:45:58 +00002856 SourceLocation BaseLoc = getDerived().getBaseLocation();
2857
2858 TL.setTemplateNameLoc(BaseLoc);
2859 TL.setLAngleLoc(BaseLoc);
2860 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002861 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2862 const TemplateArgument &TA = TST->getArg(i);
2863 TemplateArgumentLoc TAL;
2864 getDerived().InventTemplateArgumentLoc(TA, TAL);
2865 TL.setArgLocInfo(i, TAL.getLocInfo());
2866 }
2867
2868 TypeLocBuilder IgnoredTLB;
2869 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002870}
2871
2872template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002873QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002874 TypeLocBuilder &TLB,
2875 TemplateSpecializationTypeLoc TL,
2876 QualType ObjectType) {
2877 const TemplateSpecializationType *T = TL.getTypePtr();
2878
Mike Stump1eb44332009-09-09 15:08:12 +00002879 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002880 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002881 if (Template.isNull())
2882 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002883
John McCalld5532b62009-11-23 01:53:49 +00002884 TemplateArgumentListInfo NewTemplateArgs;
2885 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2886 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2887
2888 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2889 TemplateArgumentLoc Loc;
2890 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002891 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002892 NewTemplateArgs.addArgument(Loc);
2893 }
Mike Stump1eb44332009-09-09 15:08:12 +00002894
John McCall833ca992009-10-29 08:12:44 +00002895 // FIXME: maybe don't rebuild if all the template arguments are the same.
2896
2897 QualType Result =
2898 getDerived().RebuildTemplateSpecializationType(Template,
2899 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002900 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002901
2902 if (!Result.isNull()) {
2903 TemplateSpecializationTypeLoc NewTL
2904 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2905 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2906 NewTL.setLAngleLoc(TL.getLAngleLoc());
2907 NewTL.setRAngleLoc(TL.getRAngleLoc());
2908 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2909 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002910 }
Mike Stump1eb44332009-09-09 15:08:12 +00002911
John McCall833ca992009-10-29 08:12:44 +00002912 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002913}
Mike Stump1eb44332009-09-09 15:08:12 +00002914
2915template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002916QualType
2917TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002918 QualifiedNameTypeLoc TL,
2919 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002920 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002921 NestedNameSpecifier *NNS
2922 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002923 SourceRange(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00002924 false,
Douglas Gregor124b8782010-02-16 19:09:40 +00002925 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002926 if (!NNS)
2927 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002928
Douglas Gregor577f75a2009-08-04 16:50:30 +00002929 QualType Named = getDerived().TransformType(T->getNamedType());
2930 if (Named.isNull())
2931 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002932
John McCalla2becad2009-10-21 00:40:46 +00002933 QualType Result = TL.getType();
2934 if (getDerived().AlwaysRebuild() ||
2935 NNS != T->getQualifier() ||
2936 Named != T->getNamedType()) {
2937 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2938 if (Result.isNull())
2939 return QualType();
2940 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002941
John McCalla2becad2009-10-21 00:40:46 +00002942 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2943 NewTL.setNameLoc(TL.getNameLoc());
2944
2945 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002946}
Mike Stump1eb44332009-09-09 15:08:12 +00002947
2948template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002949QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002950 TypenameTypeLoc TL,
2951 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002952 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002953
2954 /* FIXME: preserve source information better than this */
2955 SourceRange SR(TL.getNameLoc());
2956
Douglas Gregor577f75a2009-08-04 16:50:30 +00002957 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00002958 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorb10cd042010-02-21 18:36:56 +00002959 false, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002960 if (!NNS)
2961 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002962
John McCalla2becad2009-10-21 00:40:46 +00002963 QualType Result;
2964
Douglas Gregor577f75a2009-08-04 16:50:30 +00002965 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002966 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002967 = getDerived().TransformType(QualType(TemplateId, 0));
2968 if (NewTemplateId.isNull())
2969 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002970
Douglas Gregor577f75a2009-08-04 16:50:30 +00002971 if (!getDerived().AlwaysRebuild() &&
2972 NNS == T->getQualifier() &&
2973 NewTemplateId == QualType(TemplateId, 0))
2974 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002975
John McCalla2becad2009-10-21 00:40:46 +00002976 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2977 } else {
John McCall833ca992009-10-29 08:12:44 +00002978 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002979 }
John McCalla2becad2009-10-21 00:40:46 +00002980 if (Result.isNull())
2981 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002982
John McCalla2becad2009-10-21 00:40:46 +00002983 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2984 NewTL.setNameLoc(TL.getNameLoc());
2985
2986 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002987}
Mike Stump1eb44332009-09-09 15:08:12 +00002988
Douglas Gregor577f75a2009-08-04 16:50:30 +00002989template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002990QualType
2991TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002992 ObjCInterfaceTypeLoc TL,
2993 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00002994 assert(false && "TransformObjCInterfaceType unimplemented");
2995 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002996}
Mike Stump1eb44332009-09-09 15:08:12 +00002997
2998template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002999QualType
3000TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00003001 ObjCObjectPointerTypeLoc TL,
3002 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003003 assert(false && "TransformObjCObjectPointerType unimplemented");
3004 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003005}
3006
Douglas Gregor577f75a2009-08-04 16:50:30 +00003007//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003008// Statement transformation
3009//===----------------------------------------------------------------------===//
3010template<typename Derived>
3011Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003012TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3013 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003014}
3015
3016template<typename Derived>
3017Sema::OwningStmtResult
3018TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3019 return getDerived().TransformCompoundStmt(S, false);
3020}
3021
3022template<typename Derived>
3023Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003024TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003025 bool IsStmtExpr) {
3026 bool SubStmtChanged = false;
3027 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3028 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3029 B != BEnd; ++B) {
3030 OwningStmtResult Result = getDerived().TransformStmt(*B);
3031 if (Result.isInvalid())
3032 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003033
Douglas Gregor43959a92009-08-20 07:17:43 +00003034 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3035 Statements.push_back(Result.takeAs<Stmt>());
3036 }
Mike Stump1eb44332009-09-09 15:08:12 +00003037
Douglas Gregor43959a92009-08-20 07:17:43 +00003038 if (!getDerived().AlwaysRebuild() &&
3039 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003040 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003041
3042 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3043 move_arg(Statements),
3044 S->getRBracLoc(),
3045 IsStmtExpr);
3046}
Mike Stump1eb44332009-09-09 15:08:12 +00003047
Douglas Gregor43959a92009-08-20 07:17:43 +00003048template<typename Derived>
3049Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003050TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003051 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3052 {
3053 // The case value expressions are not potentially evaluated.
3054 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003055
Eli Friedman264c1f82009-11-19 03:14:00 +00003056 // Transform the left-hand case value.
3057 LHS = getDerived().TransformExpr(S->getLHS());
3058 if (LHS.isInvalid())
3059 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003060
Eli Friedman264c1f82009-11-19 03:14:00 +00003061 // Transform the right-hand case value (for the GNU case-range extension).
3062 RHS = getDerived().TransformExpr(S->getRHS());
3063 if (RHS.isInvalid())
3064 return SemaRef.StmtError();
3065 }
Mike Stump1eb44332009-09-09 15:08:12 +00003066
Douglas Gregor43959a92009-08-20 07:17:43 +00003067 // Build the case statement.
3068 // Case statements are always rebuilt so that they will attached to their
3069 // transformed switch statement.
3070 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3071 move(LHS),
3072 S->getEllipsisLoc(),
3073 move(RHS),
3074 S->getColonLoc());
3075 if (Case.isInvalid())
3076 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003077
Douglas Gregor43959a92009-08-20 07:17:43 +00003078 // Transform the statement following the case
3079 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3080 if (SubStmt.isInvalid())
3081 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003082
Douglas Gregor43959a92009-08-20 07:17:43 +00003083 // Attach the body to the case statement
3084 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3085}
3086
3087template<typename Derived>
3088Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003089TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003090 // Transform the statement following the default case
3091 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3092 if (SubStmt.isInvalid())
3093 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003094
Douglas Gregor43959a92009-08-20 07:17:43 +00003095 // Default statements are always rebuilt
3096 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3097 move(SubStmt));
3098}
Mike Stump1eb44332009-09-09 15:08:12 +00003099
Douglas Gregor43959a92009-08-20 07:17:43 +00003100template<typename Derived>
3101Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003102TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003103 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3104 if (SubStmt.isInvalid())
3105 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003106
Douglas Gregor43959a92009-08-20 07:17:43 +00003107 // FIXME: Pass the real colon location in.
3108 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3109 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3110 move(SubStmt));
3111}
Mike Stump1eb44332009-09-09 15:08:12 +00003112
Douglas Gregor43959a92009-08-20 07:17:43 +00003113template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003114Sema::OwningStmtResult
3115TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003116 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003117 OwningExprResult Cond(SemaRef);
3118 VarDecl *ConditionVar = 0;
3119 if (S->getConditionVariable()) {
3120 ConditionVar
3121 = cast_or_null<VarDecl>(
3122 getDerived().TransformDefinition(S->getConditionVariable()));
3123 if (!ConditionVar)
3124 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003125 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003126 Cond = getDerived().TransformExpr(S->getCond());
3127
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003128 if (Cond.isInvalid())
3129 return SemaRef.StmtError();
3130 }
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003131
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003132 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003133
Douglas Gregor43959a92009-08-20 07:17:43 +00003134 // Transform the "then" branch.
3135 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3136 if (Then.isInvalid())
3137 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003138
Douglas Gregor43959a92009-08-20 07:17:43 +00003139 // Transform the "else" branch.
3140 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3141 if (Else.isInvalid())
3142 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003143
Douglas Gregor43959a92009-08-20 07:17:43 +00003144 if (!getDerived().AlwaysRebuild() &&
3145 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003146 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003147 Then.get() == S->getThen() &&
3148 Else.get() == S->getElse())
Mike Stump1eb44332009-09-09 15:08:12 +00003149 return SemaRef.Owned(S->Retain());
3150
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003151 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3152 move(Then),
Mike Stump1eb44332009-09-09 15:08:12 +00003153 S->getElseLoc(), move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +00003154}
3155
3156template<typename Derived>
3157Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003158TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003159 // Transform the condition.
Douglas Gregord3d53012009-11-24 17:07:59 +00003160 OwningExprResult Cond(SemaRef);
3161 VarDecl *ConditionVar = 0;
3162 if (S->getConditionVariable()) {
3163 ConditionVar
3164 = cast_or_null<VarDecl>(
3165 getDerived().TransformDefinition(S->getConditionVariable()));
3166 if (!ConditionVar)
3167 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003168 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003169 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003170
3171 if (Cond.isInvalid())
3172 return SemaRef.StmtError();
3173 }
Mike Stump1eb44332009-09-09 15:08:12 +00003174
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003175 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003176
Douglas Gregor43959a92009-08-20 07:17:43 +00003177 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003178 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3179 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003180 if (Switch.isInvalid())
3181 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003182
Douglas Gregor43959a92009-08-20 07:17:43 +00003183 // Transform the body of the switch statement.
3184 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3185 if (Body.isInvalid())
3186 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003187
Douglas Gregor43959a92009-08-20 07:17:43 +00003188 // Complete the switch statement.
3189 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3190 move(Body));
3191}
Mike Stump1eb44332009-09-09 15:08:12 +00003192
Douglas Gregor43959a92009-08-20 07:17:43 +00003193template<typename Derived>
3194Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003195TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003196 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003197 OwningExprResult Cond(SemaRef);
3198 VarDecl *ConditionVar = 0;
3199 if (S->getConditionVariable()) {
3200 ConditionVar
3201 = cast_or_null<VarDecl>(
3202 getDerived().TransformDefinition(S->getConditionVariable()));
3203 if (!ConditionVar)
3204 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003205 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003206 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003207
3208 if (Cond.isInvalid())
3209 return SemaRef.StmtError();
3210 }
Mike Stump1eb44332009-09-09 15:08:12 +00003211
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003212 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003213
Douglas Gregor43959a92009-08-20 07:17:43 +00003214 // Transform the body
3215 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3216 if (Body.isInvalid())
3217 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003218
Douglas Gregor43959a92009-08-20 07:17:43 +00003219 if (!getDerived().AlwaysRebuild() &&
3220 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003221 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003222 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003223 return SemaRef.Owned(S->Retain());
3224
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003225 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3226 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003227}
Mike Stump1eb44332009-09-09 15:08:12 +00003228
Douglas Gregor43959a92009-08-20 07:17:43 +00003229template<typename Derived>
3230Sema::OwningStmtResult
3231TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3232 // Transform the condition
3233 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3234 if (Cond.isInvalid())
3235 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003236
Douglas Gregor43959a92009-08-20 07:17:43 +00003237 // Transform the body
3238 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3239 if (Body.isInvalid())
3240 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003241
Douglas Gregor43959a92009-08-20 07:17:43 +00003242 if (!getDerived().AlwaysRebuild() &&
3243 Cond.get() == S->getCond() &&
3244 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003245 return SemaRef.Owned(S->Retain());
3246
Douglas Gregor43959a92009-08-20 07:17:43 +00003247 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3248 /*FIXME:*/S->getWhileLoc(), move(Cond),
3249 S->getRParenLoc());
3250}
Mike Stump1eb44332009-09-09 15:08:12 +00003251
Douglas Gregor43959a92009-08-20 07:17:43 +00003252template<typename Derived>
3253Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003254TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003255 // Transform the initialization statement
3256 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3257 if (Init.isInvalid())
3258 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003259
Douglas Gregor43959a92009-08-20 07:17:43 +00003260 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003261 OwningExprResult Cond(SemaRef);
3262 VarDecl *ConditionVar = 0;
3263 if (S->getConditionVariable()) {
3264 ConditionVar
3265 = cast_or_null<VarDecl>(
3266 getDerived().TransformDefinition(S->getConditionVariable()));
3267 if (!ConditionVar)
3268 return SemaRef.StmtError();
3269 } else {
3270 Cond = getDerived().TransformExpr(S->getCond());
3271
3272 if (Cond.isInvalid())
3273 return SemaRef.StmtError();
3274 }
Mike Stump1eb44332009-09-09 15:08:12 +00003275
Douglas Gregor43959a92009-08-20 07:17:43 +00003276 // Transform the increment
3277 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3278 if (Inc.isInvalid())
3279 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003280
Douglas Gregor43959a92009-08-20 07:17:43 +00003281 // Transform the body
3282 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3283 if (Body.isInvalid())
3284 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003285
Douglas Gregor43959a92009-08-20 07:17:43 +00003286 if (!getDerived().AlwaysRebuild() &&
3287 Init.get() == S->getInit() &&
3288 Cond.get() == S->getCond() &&
3289 Inc.get() == S->getInc() &&
3290 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003291 return SemaRef.Owned(S->Retain());
3292
Douglas Gregor43959a92009-08-20 07:17:43 +00003293 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003294 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003295 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003296 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003297 S->getRParenLoc(), move(Body));
3298}
3299
3300template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003301Sema::OwningStmtResult
3302TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003303 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003304 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003305 S->getLabel());
3306}
3307
3308template<typename Derived>
3309Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003310TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003311 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3312 if (Target.isInvalid())
3313 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003314
Douglas Gregor43959a92009-08-20 07:17:43 +00003315 if (!getDerived().AlwaysRebuild() &&
3316 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003317 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003318
3319 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3320 move(Target));
3321}
3322
3323template<typename Derived>
3324Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003325TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3326 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003327}
Mike Stump1eb44332009-09-09 15:08:12 +00003328
Douglas Gregor43959a92009-08-20 07:17:43 +00003329template<typename Derived>
3330Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003331TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3332 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003333}
Mike Stump1eb44332009-09-09 15:08:12 +00003334
Douglas Gregor43959a92009-08-20 07:17:43 +00003335template<typename Derived>
3336Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003337TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003338 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3339 if (Result.isInvalid())
3340 return SemaRef.StmtError();
3341
Mike Stump1eb44332009-09-09 15:08:12 +00003342 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003343 // to tell whether the return type of the function has changed.
3344 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3345}
Mike Stump1eb44332009-09-09 15:08:12 +00003346
Douglas Gregor43959a92009-08-20 07:17:43 +00003347template<typename Derived>
3348Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003349TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003350 bool DeclChanged = false;
3351 llvm::SmallVector<Decl *, 4> Decls;
3352 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3353 D != DEnd; ++D) {
3354 Decl *Transformed = getDerived().TransformDefinition(*D);
3355 if (!Transformed)
3356 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003357
Douglas Gregor43959a92009-08-20 07:17:43 +00003358 if (Transformed != *D)
3359 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003360
Douglas Gregor43959a92009-08-20 07:17:43 +00003361 Decls.push_back(Transformed);
3362 }
Mike Stump1eb44332009-09-09 15:08:12 +00003363
Douglas Gregor43959a92009-08-20 07:17:43 +00003364 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003365 return SemaRef.Owned(S->Retain());
3366
3367 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003368 S->getStartLoc(), S->getEndLoc());
3369}
Mike Stump1eb44332009-09-09 15:08:12 +00003370
Douglas Gregor43959a92009-08-20 07:17:43 +00003371template<typename Derived>
3372Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003373TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003374 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003375 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003376}
3377
3378template<typename Derived>
3379Sema::OwningStmtResult
3380TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003381
3382 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3383 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003384 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003385
Anders Carlsson703e3942010-01-24 05:50:09 +00003386 OwningExprResult AsmString(SemaRef);
3387 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3388
3389 bool ExprsChanged = false;
3390
3391 // Go through the outputs.
3392 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003393 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003394
Anders Carlsson703e3942010-01-24 05:50:09 +00003395 // No need to transform the constraint literal.
3396 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3397
3398 // Transform the output expr.
3399 Expr *OutputExpr = S->getOutputExpr(I);
3400 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3401 if (Result.isInvalid())
3402 return SemaRef.StmtError();
3403
3404 ExprsChanged |= Result.get() != OutputExpr;
3405
3406 Exprs.push_back(Result.takeAs<Expr>());
3407 }
3408
3409 // Go through the inputs.
3410 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003411 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003412
Anders Carlsson703e3942010-01-24 05:50:09 +00003413 // No need to transform the constraint literal.
3414 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3415
3416 // Transform the input expr.
3417 Expr *InputExpr = S->getInputExpr(I);
3418 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3419 if (Result.isInvalid())
3420 return SemaRef.StmtError();
3421
3422 ExprsChanged |= Result.get() != InputExpr;
3423
3424 Exprs.push_back(Result.takeAs<Expr>());
3425 }
3426
3427 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3428 return SemaRef.Owned(S->Retain());
3429
3430 // Go through the clobbers.
3431 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3432 Clobbers.push_back(S->getClobber(I)->Retain());
3433
3434 // No need to transform the asm string literal.
3435 AsmString = SemaRef.Owned(S->getAsmString());
3436
3437 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3438 S->isSimple(),
3439 S->isVolatile(),
3440 S->getNumOutputs(),
3441 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003442 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003443 move_arg(Constraints),
3444 move_arg(Exprs),
3445 move(AsmString),
3446 move_arg(Clobbers),
3447 S->getRParenLoc(),
3448 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003449}
3450
3451
3452template<typename Derived>
3453Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003454TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003455 // FIXME: Implement this
3456 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003457 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003458}
Mike Stump1eb44332009-09-09 15:08:12 +00003459
Douglas Gregor43959a92009-08-20 07:17:43 +00003460template<typename Derived>
3461Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003462TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003463 // FIXME: Implement this
3464 assert(false && "Cannot transform an Objective-C @catch statement");
3465 return SemaRef.Owned(S->Retain());
3466}
Mike Stump1eb44332009-09-09 15:08:12 +00003467
Douglas Gregor43959a92009-08-20 07:17:43 +00003468template<typename Derived>
3469Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003470TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003471 // FIXME: Implement this
3472 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003473 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003474}
Mike Stump1eb44332009-09-09 15:08:12 +00003475
Douglas Gregor43959a92009-08-20 07:17:43 +00003476template<typename Derived>
3477Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003478TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003479 // FIXME: Implement this
3480 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003481 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003482}
Mike Stump1eb44332009-09-09 15:08:12 +00003483
Douglas Gregor43959a92009-08-20 07:17:43 +00003484template<typename Derived>
3485Sema::OwningStmtResult
3486TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003487 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003488 // FIXME: Implement this
3489 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003490 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003491}
3492
3493template<typename Derived>
3494Sema::OwningStmtResult
3495TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003496 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003497 // FIXME: Implement this
3498 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003499 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003500}
3501
3502
3503template<typename Derived>
3504Sema::OwningStmtResult
3505TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3506 // Transform the exception declaration, if any.
3507 VarDecl *Var = 0;
3508 if (S->getExceptionDecl()) {
3509 VarDecl *ExceptionDecl = S->getExceptionDecl();
3510 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3511 ExceptionDecl->getDeclName());
3512
3513 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3514 if (T.isNull())
3515 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003516
Douglas Gregor43959a92009-08-20 07:17:43 +00003517 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3518 T,
John McCalla93c9342009-12-07 02:54:59 +00003519 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003520 ExceptionDecl->getIdentifier(),
3521 ExceptionDecl->getLocation(),
3522 /*FIXME: Inaccurate*/
3523 SourceRange(ExceptionDecl->getLocation()));
3524 if (!Var || Var->isInvalidDecl()) {
3525 if (Var)
3526 Var->Destroy(SemaRef.Context);
3527 return SemaRef.StmtError();
3528 }
3529 }
Mike Stump1eb44332009-09-09 15:08:12 +00003530
Douglas Gregor43959a92009-08-20 07:17:43 +00003531 // Transform the actual exception handler.
3532 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3533 if (Handler.isInvalid()) {
3534 if (Var)
3535 Var->Destroy(SemaRef.Context);
3536 return SemaRef.StmtError();
3537 }
Mike Stump1eb44332009-09-09 15:08:12 +00003538
Douglas Gregor43959a92009-08-20 07:17:43 +00003539 if (!getDerived().AlwaysRebuild() &&
3540 !Var &&
3541 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003542 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003543
3544 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3545 Var,
3546 move(Handler));
3547}
Mike Stump1eb44332009-09-09 15:08:12 +00003548
Douglas Gregor43959a92009-08-20 07:17:43 +00003549template<typename Derived>
3550Sema::OwningStmtResult
3551TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3552 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003553 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003554 = getDerived().TransformCompoundStmt(S->getTryBlock());
3555 if (TryBlock.isInvalid())
3556 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003557
Douglas Gregor43959a92009-08-20 07:17:43 +00003558 // Transform the handlers.
3559 bool HandlerChanged = false;
3560 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3561 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003562 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003563 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3564 if (Handler.isInvalid())
3565 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003566
Douglas Gregor43959a92009-08-20 07:17:43 +00003567 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3568 Handlers.push_back(Handler.takeAs<Stmt>());
3569 }
Mike Stump1eb44332009-09-09 15:08:12 +00003570
Douglas Gregor43959a92009-08-20 07:17:43 +00003571 if (!getDerived().AlwaysRebuild() &&
3572 TryBlock.get() == S->getTryBlock() &&
3573 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003574 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003575
3576 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003577 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003578}
Mike Stump1eb44332009-09-09 15:08:12 +00003579
Douglas Gregor43959a92009-08-20 07:17:43 +00003580//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003581// Expression transformation
3582//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003583template<typename Derived>
3584Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003585TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003586 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003587}
Mike Stump1eb44332009-09-09 15:08:12 +00003588
3589template<typename Derived>
3590Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003591TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003592 NestedNameSpecifier *Qualifier = 0;
3593 if (E->getQualifier()) {
3594 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00003595 E->getQualifierRange(),
3596 false);
Douglas Gregora2813ce2009-10-23 18:54:35 +00003597 if (!Qualifier)
3598 return SemaRef.ExprError();
3599 }
John McCalldbd872f2009-12-08 09:08:17 +00003600
3601 ValueDecl *ND
3602 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003603 if (!ND)
3604 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003605
Douglas Gregora2813ce2009-10-23 18:54:35 +00003606 if (!getDerived().AlwaysRebuild() &&
3607 Qualifier == E->getQualifier() &&
3608 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003609 !E->hasExplicitTemplateArgumentList()) {
3610
3611 // Mark it referenced in the new context regardless.
3612 // FIXME: this is a bit instantiation-specific.
3613 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3614
Mike Stump1eb44332009-09-09 15:08:12 +00003615 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003616 }
John McCalldbd872f2009-12-08 09:08:17 +00003617
3618 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3619 if (E->hasExplicitTemplateArgumentList()) {
3620 TemplateArgs = &TransArgs;
3621 TransArgs.setLAngleLoc(E->getLAngleLoc());
3622 TransArgs.setRAngleLoc(E->getRAngleLoc());
3623 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3624 TemplateArgumentLoc Loc;
3625 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3626 return SemaRef.ExprError();
3627 TransArgs.addArgument(Loc);
3628 }
3629 }
3630
Douglas Gregora2813ce2009-10-23 18:54:35 +00003631 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003632 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003633}
Mike Stump1eb44332009-09-09 15:08:12 +00003634
Douglas Gregorb98b1992009-08-11 05:31:07 +00003635template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003636Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003637TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003638 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003639}
Mike Stump1eb44332009-09-09 15:08:12 +00003640
Douglas Gregorb98b1992009-08-11 05:31:07 +00003641template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003642Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003643TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003644 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003645}
Mike Stump1eb44332009-09-09 15:08:12 +00003646
Douglas Gregorb98b1992009-08-11 05:31:07 +00003647template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003648Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003649TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003650 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003651}
Mike Stump1eb44332009-09-09 15:08:12 +00003652
Douglas Gregorb98b1992009-08-11 05:31:07 +00003653template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003654Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003655TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003656 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003657}
Mike Stump1eb44332009-09-09 15:08:12 +00003658
Douglas Gregorb98b1992009-08-11 05:31:07 +00003659template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003660Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003661TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003662 return SemaRef.Owned(E->Retain());
3663}
3664
3665template<typename Derived>
3666Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003667TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003668 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3669 if (SubExpr.isInvalid())
3670 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003671
Douglas Gregorb98b1992009-08-11 05:31:07 +00003672 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003673 return SemaRef.Owned(E->Retain());
3674
3675 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003676 E->getRParen());
3677}
3678
Mike Stump1eb44332009-09-09 15:08:12 +00003679template<typename Derived>
3680Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003681TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3682 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003683 if (SubExpr.isInvalid())
3684 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003685
Douglas Gregorb98b1992009-08-11 05:31:07 +00003686 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003687 return SemaRef.Owned(E->Retain());
3688
Douglas Gregorb98b1992009-08-11 05:31:07 +00003689 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3690 E->getOpcode(),
3691 move(SubExpr));
3692}
Mike Stump1eb44332009-09-09 15:08:12 +00003693
Douglas Gregorb98b1992009-08-11 05:31:07 +00003694template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003695Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003696TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003697 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003698 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003699
John McCalla93c9342009-12-07 02:54:59 +00003700 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003701 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003702 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003703
John McCall5ab75172009-11-04 07:28:41 +00003704 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003705 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003706
John McCall5ab75172009-11-04 07:28:41 +00003707 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003708 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003709 E->getSourceRange());
3710 }
Mike Stump1eb44332009-09-09 15:08:12 +00003711
Douglas Gregorb98b1992009-08-11 05:31:07 +00003712 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003713 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003714 // C++0x [expr.sizeof]p1:
3715 // The operand is either an expression, which is an unevaluated operand
3716 // [...]
3717 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregorb98b1992009-08-11 05:31:07 +00003719 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3720 if (SubExpr.isInvalid())
3721 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003722
Douglas Gregorb98b1992009-08-11 05:31:07 +00003723 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3724 return SemaRef.Owned(E->Retain());
3725 }
Mike Stump1eb44332009-09-09 15:08:12 +00003726
Douglas Gregorb98b1992009-08-11 05:31:07 +00003727 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3728 E->isSizeOf(),
3729 E->getSourceRange());
3730}
Mike Stump1eb44332009-09-09 15:08:12 +00003731
Douglas Gregorb98b1992009-08-11 05:31:07 +00003732template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003733Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003734TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003735 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3736 if (LHS.isInvalid())
3737 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003738
Douglas Gregorb98b1992009-08-11 05:31:07 +00003739 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3740 if (RHS.isInvalid())
3741 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003742
3743
Douglas Gregorb98b1992009-08-11 05:31:07 +00003744 if (!getDerived().AlwaysRebuild() &&
3745 LHS.get() == E->getLHS() &&
3746 RHS.get() == E->getRHS())
3747 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003748
Douglas Gregorb98b1992009-08-11 05:31:07 +00003749 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3750 /*FIXME:*/E->getLHS()->getLocStart(),
3751 move(RHS),
3752 E->getRBracketLoc());
3753}
Mike Stump1eb44332009-09-09 15:08:12 +00003754
3755template<typename Derived>
3756Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003757TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003758 // Transform the callee.
3759 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3760 if (Callee.isInvalid())
3761 return SemaRef.ExprError();
3762
3763 // Transform arguments.
3764 bool ArgChanged = false;
3765 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3766 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3767 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3768 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3769 if (Arg.isInvalid())
3770 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003771
Douglas Gregorb98b1992009-08-11 05:31:07 +00003772 // FIXME: Wrong source location information for the ','.
3773 FakeCommaLocs.push_back(
3774 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003775
3776 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003777 Args.push_back(Arg.takeAs<Expr>());
3778 }
Mike Stump1eb44332009-09-09 15:08:12 +00003779
Douglas Gregorb98b1992009-08-11 05:31:07 +00003780 if (!getDerived().AlwaysRebuild() &&
3781 Callee.get() == E->getCallee() &&
3782 !ArgChanged)
3783 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003784
Douglas Gregorb98b1992009-08-11 05:31:07 +00003785 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003786 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003787 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3788 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3789 move_arg(Args),
3790 FakeCommaLocs.data(),
3791 E->getRParenLoc());
3792}
Mike Stump1eb44332009-09-09 15:08:12 +00003793
3794template<typename Derived>
3795Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003796TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003797 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3798 if (Base.isInvalid())
3799 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003800
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003801 NestedNameSpecifier *Qualifier = 0;
3802 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003803 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003804 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00003805 E->getQualifierRange(),
3806 false);
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003807 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003808 return SemaRef.ExprError();
3809 }
Mike Stump1eb44332009-09-09 15:08:12 +00003810
Eli Friedmanf595cc42009-12-04 06:40:45 +00003811 ValueDecl *Member
3812 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003813 if (!Member)
3814 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003815
Douglas Gregorb98b1992009-08-11 05:31:07 +00003816 if (!getDerived().AlwaysRebuild() &&
3817 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003818 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003819 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003820 !E->hasExplicitTemplateArgumentList()) {
3821
3822 // Mark it referenced in the new context regardless.
3823 // FIXME: this is a bit instantiation-specific.
3824 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003825 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003826 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003827
John McCalld5532b62009-11-23 01:53:49 +00003828 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003829 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003830 TransArgs.setLAngleLoc(E->getLAngleLoc());
3831 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003832 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003833 TemplateArgumentLoc Loc;
3834 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003835 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003836 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003837 }
3838 }
3839
Douglas Gregorb98b1992009-08-11 05:31:07 +00003840 // FIXME: Bogus source location for the operator
3841 SourceLocation FakeOperatorLoc
3842 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3843
John McCallc2233c52010-01-15 08:34:02 +00003844 // FIXME: to do this check properly, we will need to preserve the
3845 // first-qualifier-in-scope here, just in case we had a dependent
3846 // base (and therefore couldn't do the check) and a
3847 // nested-name-qualifier (and therefore could do the lookup).
3848 NamedDecl *FirstQualifierInScope = 0;
3849
Douglas Gregorb98b1992009-08-11 05:31:07 +00003850 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3851 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003852 Qualifier,
3853 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003854 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003855 Member,
John McCalld5532b62009-11-23 01:53:49 +00003856 (E->hasExplicitTemplateArgumentList()
3857 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003858 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003859}
Mike Stump1eb44332009-09-09 15:08:12 +00003860
Douglas Gregorb98b1992009-08-11 05:31:07 +00003861template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003862Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003863TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003864 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3865 if (LHS.isInvalid())
3866 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003867
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3869 if (RHS.isInvalid())
3870 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003871
Douglas Gregorb98b1992009-08-11 05:31:07 +00003872 if (!getDerived().AlwaysRebuild() &&
3873 LHS.get() == E->getLHS() &&
3874 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003875 return SemaRef.Owned(E->Retain());
3876
Douglas Gregorb98b1992009-08-11 05:31:07 +00003877 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3878 move(LHS), move(RHS));
3879}
3880
Mike Stump1eb44332009-09-09 15:08:12 +00003881template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003882Sema::OwningExprResult
3883TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003884 CompoundAssignOperator *E) {
3885 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003886}
Mike Stump1eb44332009-09-09 15:08:12 +00003887
Douglas Gregorb98b1992009-08-11 05:31:07 +00003888template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003889Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003890TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003891 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3892 if (Cond.isInvalid())
3893 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003894
Douglas Gregorb98b1992009-08-11 05:31:07 +00003895 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3896 if (LHS.isInvalid())
3897 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003898
Douglas Gregorb98b1992009-08-11 05:31:07 +00003899 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3900 if (RHS.isInvalid())
3901 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003902
Douglas Gregorb98b1992009-08-11 05:31:07 +00003903 if (!getDerived().AlwaysRebuild() &&
3904 Cond.get() == E->getCond() &&
3905 LHS.get() == E->getLHS() &&
3906 RHS.get() == E->getRHS())
3907 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003908
3909 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003910 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003911 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003912 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003913 move(RHS));
3914}
Mike Stump1eb44332009-09-09 15:08:12 +00003915
3916template<typename Derived>
3917Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003918TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003919 // Implicit casts are eliminated during transformation, since they
3920 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003921 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003922}
Mike Stump1eb44332009-09-09 15:08:12 +00003923
Douglas Gregorb98b1992009-08-11 05:31:07 +00003924template<typename Derived>
3925Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003926TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003927 TypeSourceInfo *OldT;
3928 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003929 {
3930 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003931 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003932 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3933 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003934
John McCall9d125032010-01-15 18:39:57 +00003935 OldT = E->getTypeInfoAsWritten();
3936 NewT = getDerived().TransformType(OldT);
3937 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003938 return SemaRef.ExprError();
3939 }
Mike Stump1eb44332009-09-09 15:08:12 +00003940
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003941 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003942 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003943 if (SubExpr.isInvalid())
3944 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003945
Douglas Gregorb98b1992009-08-11 05:31:07 +00003946 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00003947 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003948 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003949 return SemaRef.Owned(E->Retain());
3950
John McCall9d125032010-01-15 18:39:57 +00003951 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3952 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003953 E->getRParenLoc(),
3954 move(SubExpr));
3955}
Mike Stump1eb44332009-09-09 15:08:12 +00003956
Douglas Gregorb98b1992009-08-11 05:31:07 +00003957template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003958Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003959TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00003960 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3961 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3962 if (!NewT)
3963 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003964
Douglas Gregorb98b1992009-08-11 05:31:07 +00003965 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3966 if (Init.isInvalid())
3967 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003968
Douglas Gregorb98b1992009-08-11 05:31:07 +00003969 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00003970 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003971 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003972 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003973
John McCall1d7d8d62010-01-19 22:33:45 +00003974 // Note: the expression type doesn't necessarily match the
3975 // type-as-written, but that's okay, because it should always be
3976 // derivable from the initializer.
3977
John McCall42f56b52010-01-18 19:35:47 +00003978 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003979 /*FIXME:*/E->getInitializer()->getLocEnd(),
3980 move(Init));
3981}
Mike Stump1eb44332009-09-09 15:08:12 +00003982
Douglas Gregorb98b1992009-08-11 05:31:07 +00003983template<typename Derived>
3984Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003985TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003986 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3987 if (Base.isInvalid())
3988 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003989
Douglas Gregorb98b1992009-08-11 05:31:07 +00003990 if (!getDerived().AlwaysRebuild() &&
3991 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003992 return SemaRef.Owned(E->Retain());
3993
Douglas Gregorb98b1992009-08-11 05:31:07 +00003994 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00003995 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003996 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3997 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3998 E->getAccessorLoc(),
3999 E->getAccessor());
4000}
Mike Stump1eb44332009-09-09 15:08:12 +00004001
Douglas Gregorb98b1992009-08-11 05:31:07 +00004002template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004003Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004004TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004005 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004006
Douglas Gregorb98b1992009-08-11 05:31:07 +00004007 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4008 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4009 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4010 if (Init.isInvalid())
4011 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004012
Douglas Gregorb98b1992009-08-11 05:31:07 +00004013 InitChanged = InitChanged || Init.get() != E->getInit(I);
4014 Inits.push_back(Init.takeAs<Expr>());
4015 }
Mike Stump1eb44332009-09-09 15:08:12 +00004016
Douglas Gregorb98b1992009-08-11 05:31:07 +00004017 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004018 return SemaRef.Owned(E->Retain());
4019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004021 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004022}
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024template<typename Derived>
4025Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004026TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004027 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004028
Douglas Gregor43959a92009-08-20 07:17:43 +00004029 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004030 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4031 if (Init.isInvalid())
4032 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004033
Douglas Gregor43959a92009-08-20 07:17:43 +00004034 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004035 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4036 bool ExprChanged = false;
4037 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4038 DEnd = E->designators_end();
4039 D != DEnd; ++D) {
4040 if (D->isFieldDesignator()) {
4041 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4042 D->getDotLoc(),
4043 D->getFieldLoc()));
4044 continue;
4045 }
Mike Stump1eb44332009-09-09 15:08:12 +00004046
Douglas Gregorb98b1992009-08-11 05:31:07 +00004047 if (D->isArrayDesignator()) {
4048 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4049 if (Index.isInvalid())
4050 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004051
4052 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004053 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004054
Douglas Gregorb98b1992009-08-11 05:31:07 +00004055 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4056 ArrayExprs.push_back(Index.release());
4057 continue;
4058 }
Mike Stump1eb44332009-09-09 15:08:12 +00004059
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004061 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004062 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4063 if (Start.isInvalid())
4064 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004065
Douglas Gregorb98b1992009-08-11 05:31:07 +00004066 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4067 if (End.isInvalid())
4068 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004069
4070 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004071 End.get(),
4072 D->getLBracketLoc(),
4073 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004074
Douglas Gregorb98b1992009-08-11 05:31:07 +00004075 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4076 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004077
Douglas Gregorb98b1992009-08-11 05:31:07 +00004078 ArrayExprs.push_back(Start.release());
4079 ArrayExprs.push_back(End.release());
4080 }
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregorb98b1992009-08-11 05:31:07 +00004082 if (!getDerived().AlwaysRebuild() &&
4083 Init.get() == E->getInit() &&
4084 !ExprChanged)
4085 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004086
Douglas Gregorb98b1992009-08-11 05:31:07 +00004087 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4088 E->getEqualOrColonLoc(),
4089 E->usesGNUSyntax(), move(Init));
4090}
Mike Stump1eb44332009-09-09 15:08:12 +00004091
Douglas Gregorb98b1992009-08-11 05:31:07 +00004092template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004093Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004094TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004095 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004096 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4097
4098 // FIXME: Will we ever have proper type location here? Will we actually
4099 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004100 QualType T = getDerived().TransformType(E->getType());
4101 if (T.isNull())
4102 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004103
Douglas Gregorb98b1992009-08-11 05:31:07 +00004104 if (!getDerived().AlwaysRebuild() &&
4105 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004106 return SemaRef.Owned(E->Retain());
4107
Douglas Gregorb98b1992009-08-11 05:31:07 +00004108 return getDerived().RebuildImplicitValueInitExpr(T);
4109}
Mike Stump1eb44332009-09-09 15:08:12 +00004110
Douglas Gregorb98b1992009-08-11 05:31:07 +00004111template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004112Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004113TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004114 // FIXME: Do we want the type as written?
4115 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004116
Douglas Gregorb98b1992009-08-11 05:31:07 +00004117 {
4118 // FIXME: Source location isn't quite accurate.
4119 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4120 T = getDerived().TransformType(E->getType());
4121 if (T.isNull())
4122 return SemaRef.ExprError();
4123 }
Mike Stump1eb44332009-09-09 15:08:12 +00004124
Douglas Gregorb98b1992009-08-11 05:31:07 +00004125 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4126 if (SubExpr.isInvalid())
4127 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004128
Douglas Gregorb98b1992009-08-11 05:31:07 +00004129 if (!getDerived().AlwaysRebuild() &&
4130 T == E->getType() &&
4131 SubExpr.get() == E->getSubExpr())
4132 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004133
Douglas Gregorb98b1992009-08-11 05:31:07 +00004134 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4135 T, E->getRParenLoc());
4136}
4137
4138template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004139Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004140TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004141 bool ArgumentChanged = false;
4142 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4143 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4144 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4145 if (Init.isInvalid())
4146 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004147
Douglas Gregorb98b1992009-08-11 05:31:07 +00004148 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4149 Inits.push_back(Init.takeAs<Expr>());
4150 }
Mike Stump1eb44332009-09-09 15:08:12 +00004151
Douglas Gregorb98b1992009-08-11 05:31:07 +00004152 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4153 move_arg(Inits),
4154 E->getRParenLoc());
4155}
Mike Stump1eb44332009-09-09 15:08:12 +00004156
Douglas Gregorb98b1992009-08-11 05:31:07 +00004157/// \brief Transform an address-of-label expression.
4158///
4159/// By default, the transformation of an address-of-label expression always
4160/// rebuilds the expression, so that the label identifier can be resolved to
4161/// the corresponding label statement by semantic analysis.
4162template<typename Derived>
4163Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004164TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004165 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4166 E->getLabel());
4167}
Mike Stump1eb44332009-09-09 15:08:12 +00004168
4169template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004170Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004172 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004173 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4174 if (SubStmt.isInvalid())
4175 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004176
Douglas Gregorb98b1992009-08-11 05:31:07 +00004177 if (!getDerived().AlwaysRebuild() &&
4178 SubStmt.get() == E->getSubStmt())
4179 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004180
4181 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004182 move(SubStmt),
4183 E->getRParenLoc());
4184}
Mike Stump1eb44332009-09-09 15:08:12 +00004185
Douglas Gregorb98b1992009-08-11 05:31:07 +00004186template<typename Derived>
4187Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004188TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004189 QualType T1, T2;
4190 {
4191 // FIXME: Source location isn't quite accurate.
4192 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004193
Douglas Gregorb98b1992009-08-11 05:31:07 +00004194 T1 = getDerived().TransformType(E->getArgType1());
4195 if (T1.isNull())
4196 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004197
Douglas Gregorb98b1992009-08-11 05:31:07 +00004198 T2 = getDerived().TransformType(E->getArgType2());
4199 if (T2.isNull())
4200 return SemaRef.ExprError();
4201 }
4202
4203 if (!getDerived().AlwaysRebuild() &&
4204 T1 == E->getArgType1() &&
4205 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004206 return SemaRef.Owned(E->Retain());
4207
Douglas Gregorb98b1992009-08-11 05:31:07 +00004208 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4209 T1, T2, E->getRParenLoc());
4210}
Mike Stump1eb44332009-09-09 15:08:12 +00004211
Douglas Gregorb98b1992009-08-11 05:31:07 +00004212template<typename Derived>
4213Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004214TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004215 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4216 if (Cond.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004218
Douglas Gregorb98b1992009-08-11 05:31:07 +00004219 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4220 if (LHS.isInvalid())
4221 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004222
Douglas Gregorb98b1992009-08-11 05:31:07 +00004223 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4224 if (RHS.isInvalid())
4225 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004226
Douglas Gregorb98b1992009-08-11 05:31:07 +00004227 if (!getDerived().AlwaysRebuild() &&
4228 Cond.get() == E->getCond() &&
4229 LHS.get() == E->getLHS() &&
4230 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004231 return SemaRef.Owned(E->Retain());
4232
Douglas Gregorb98b1992009-08-11 05:31:07 +00004233 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4234 move(Cond), move(LHS), move(RHS),
4235 E->getRParenLoc());
4236}
Mike Stump1eb44332009-09-09 15:08:12 +00004237
Douglas Gregorb98b1992009-08-11 05:31:07 +00004238template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004239Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004240TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004241 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004242}
4243
4244template<typename Derived>
4245Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004246TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004247 switch (E->getOperator()) {
4248 case OO_New:
4249 case OO_Delete:
4250 case OO_Array_New:
4251 case OO_Array_Delete:
4252 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4253 return SemaRef.ExprError();
4254
4255 case OO_Call: {
4256 // This is a call to an object's operator().
4257 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4258
4259 // Transform the object itself.
4260 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4261 if (Object.isInvalid())
4262 return SemaRef.ExprError();
4263
4264 // FIXME: Poor location information
4265 SourceLocation FakeLParenLoc
4266 = SemaRef.PP.getLocForEndOfToken(
4267 static_cast<Expr *>(Object.get())->getLocEnd());
4268
4269 // Transform the call arguments.
4270 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4271 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4272 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004273 if (getDerived().DropCallArgument(E->getArg(I)))
4274 break;
4275
Douglas Gregor668d6d92009-12-13 20:44:55 +00004276 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4277 if (Arg.isInvalid())
4278 return SemaRef.ExprError();
4279
4280 // FIXME: Poor source location information.
4281 SourceLocation FakeCommaLoc
4282 = SemaRef.PP.getLocForEndOfToken(
4283 static_cast<Expr *>(Arg.get())->getLocEnd());
4284 FakeCommaLocs.push_back(FakeCommaLoc);
4285 Args.push_back(Arg.release());
4286 }
4287
4288 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4289 move_arg(Args),
4290 FakeCommaLocs.data(),
4291 E->getLocEnd());
4292 }
4293
4294#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4295 case OO_##Name:
4296#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4297#include "clang/Basic/OperatorKinds.def"
4298 case OO_Subscript:
4299 // Handled below.
4300 break;
4301
4302 case OO_Conditional:
4303 llvm_unreachable("conditional operator is not actually overloadable");
4304 return SemaRef.ExprError();
4305
4306 case OO_None:
4307 case NUM_OVERLOADED_OPERATORS:
4308 llvm_unreachable("not an overloaded operator?");
4309 return SemaRef.ExprError();
4310 }
4311
Douglas Gregorb98b1992009-08-11 05:31:07 +00004312 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4313 if (Callee.isInvalid())
4314 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004315
John McCall454feb92009-12-08 09:21:05 +00004316 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004317 if (First.isInvalid())
4318 return SemaRef.ExprError();
4319
4320 OwningExprResult Second(SemaRef);
4321 if (E->getNumArgs() == 2) {
4322 Second = getDerived().TransformExpr(E->getArg(1));
4323 if (Second.isInvalid())
4324 return SemaRef.ExprError();
4325 }
Mike Stump1eb44332009-09-09 15:08:12 +00004326
Douglas Gregorb98b1992009-08-11 05:31:07 +00004327 if (!getDerived().AlwaysRebuild() &&
4328 Callee.get() == E->getCallee() &&
4329 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004330 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4331 return SemaRef.Owned(E->Retain());
4332
Douglas Gregorb98b1992009-08-11 05:31:07 +00004333 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4334 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004335 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004336 move(First),
4337 move(Second));
4338}
Mike Stump1eb44332009-09-09 15:08:12 +00004339
Douglas Gregorb98b1992009-08-11 05:31:07 +00004340template<typename Derived>
4341Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004342TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4343 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004344}
Mike Stump1eb44332009-09-09 15:08:12 +00004345
Douglas Gregorb98b1992009-08-11 05:31:07 +00004346template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004347Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004348TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004349 TypeSourceInfo *OldT;
4350 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004351 {
4352 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004353 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004354 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4355 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004356
John McCall9d125032010-01-15 18:39:57 +00004357 OldT = E->getTypeInfoAsWritten();
4358 NewT = getDerived().TransformType(OldT);
4359 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004360 return SemaRef.ExprError();
4361 }
Mike Stump1eb44332009-09-09 15:08:12 +00004362
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004363 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004364 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004365 if (SubExpr.isInvalid())
4366 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004367
Douglas Gregorb98b1992009-08-11 05:31:07 +00004368 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004369 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004370 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004371 return SemaRef.Owned(E->Retain());
4372
Douglas Gregorb98b1992009-08-11 05:31:07 +00004373 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004374 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004375 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4376 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4377 SourceLocation FakeRParenLoc
4378 = SemaRef.PP.getLocForEndOfToken(
4379 E->getSubExpr()->getSourceRange().getEnd());
4380 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004381 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004383 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004384 FakeRAngleLoc,
4385 FakeRAngleLoc,
4386 move(SubExpr),
4387 FakeRParenLoc);
4388}
Mike Stump1eb44332009-09-09 15:08:12 +00004389
Douglas Gregorb98b1992009-08-11 05:31:07 +00004390template<typename Derived>
4391Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004392TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4393 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004394}
Mike Stump1eb44332009-09-09 15:08:12 +00004395
4396template<typename Derived>
4397Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004398TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4399 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004400}
4401
Douglas Gregorb98b1992009-08-11 05:31:07 +00004402template<typename Derived>
4403Sema::OwningExprResult
4404TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004405 CXXReinterpretCastExpr *E) {
4406 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004407}
Mike Stump1eb44332009-09-09 15:08:12 +00004408
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409template<typename Derived>
4410Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004411TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4412 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004413}
Mike Stump1eb44332009-09-09 15:08:12 +00004414
Douglas Gregorb98b1992009-08-11 05:31:07 +00004415template<typename Derived>
4416Sema::OwningExprResult
4417TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004418 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004419 TypeSourceInfo *OldT;
4420 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004421 {
4422 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004423
John McCall9d125032010-01-15 18:39:57 +00004424 OldT = E->getTypeInfoAsWritten();
4425 NewT = getDerived().TransformType(OldT);
4426 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004427 return SemaRef.ExprError();
4428 }
Mike Stump1eb44332009-09-09 15:08:12 +00004429
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004430 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004431 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004432 if (SubExpr.isInvalid())
4433 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004434
Douglas Gregorb98b1992009-08-11 05:31:07 +00004435 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004436 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004437 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004438 return SemaRef.Owned(E->Retain());
4439
Douglas Gregorb98b1992009-08-11 05:31:07 +00004440 // FIXME: The end of the type's source range is wrong
4441 return getDerived().RebuildCXXFunctionalCastExpr(
4442 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004443 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 /*FIXME:*/E->getSubExpr()->getLocStart(),
4445 move(SubExpr),
4446 E->getRParenLoc());
4447}
Mike Stump1eb44332009-09-09 15:08:12 +00004448
Douglas Gregorb98b1992009-08-11 05:31:07 +00004449template<typename Derived>
4450Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004451TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004452 if (E->isTypeOperand()) {
4453 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004454
Douglas Gregorb98b1992009-08-11 05:31:07 +00004455 QualType T = getDerived().TransformType(E->getTypeOperand());
4456 if (T.isNull())
4457 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004458
Douglas Gregorb98b1992009-08-11 05:31:07 +00004459 if (!getDerived().AlwaysRebuild() &&
4460 T == E->getTypeOperand())
4461 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004462
Douglas Gregorb98b1992009-08-11 05:31:07 +00004463 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4464 /*FIXME:*/E->getLocStart(),
4465 T,
4466 E->getLocEnd());
4467 }
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Douglas Gregorb98b1992009-08-11 05:31:07 +00004469 // We don't know whether the expression is potentially evaluated until
4470 // after we perform semantic analysis, so the expression is potentially
4471 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004472 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004473 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004474
Douglas Gregorb98b1992009-08-11 05:31:07 +00004475 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4476 if (SubExpr.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregorb98b1992009-08-11 05:31:07 +00004479 if (!getDerived().AlwaysRebuild() &&
4480 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004481 return SemaRef.Owned(E->Retain());
4482
Douglas Gregorb98b1992009-08-11 05:31:07 +00004483 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4484 /*FIXME:*/E->getLocStart(),
4485 move(SubExpr),
4486 E->getLocEnd());
4487}
4488
4489template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004490Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004491TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004492 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004493}
Mike Stump1eb44332009-09-09 15:08:12 +00004494
Douglas Gregorb98b1992009-08-11 05:31:07 +00004495template<typename Derived>
4496Sema::OwningExprResult
4497TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004498 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004499 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004500}
Mike Stump1eb44332009-09-09 15:08:12 +00004501
Douglas Gregorb98b1992009-08-11 05:31:07 +00004502template<typename Derived>
4503Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004504TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004505 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004506
Douglas Gregorb98b1992009-08-11 05:31:07 +00004507 QualType T = getDerived().TransformType(E->getType());
4508 if (T.isNull())
4509 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004510
Douglas Gregorb98b1992009-08-11 05:31:07 +00004511 if (!getDerived().AlwaysRebuild() &&
4512 T == E->getType())
4513 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004514
Douglas Gregor828a1972010-01-07 23:12:05 +00004515 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004516}
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518template<typename Derived>
4519Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004520TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004521 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4522 if (SubExpr.isInvalid())
4523 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004524
Douglas Gregorb98b1992009-08-11 05:31:07 +00004525 if (!getDerived().AlwaysRebuild() &&
4526 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004527 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004528
4529 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4530}
Mike Stump1eb44332009-09-09 15:08:12 +00004531
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532template<typename Derived>
4533Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004534TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004535 ParmVarDecl *Param
Douglas Gregorb98b1992009-08-11 05:31:07 +00004536 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4537 if (!Param)
4538 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004539
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004540 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004541 Param == E->getParam())
4542 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004543
Douglas Gregor036aed12009-12-23 23:03:06 +00004544 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545}
Mike Stump1eb44332009-09-09 15:08:12 +00004546
Douglas Gregorb98b1992009-08-11 05:31:07 +00004547template<typename Derived>
4548Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004549TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004550 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4551
4552 QualType T = getDerived().TransformType(E->getType());
4553 if (T.isNull())
4554 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004555
Douglas Gregorb98b1992009-08-11 05:31:07 +00004556 if (!getDerived().AlwaysRebuild() &&
4557 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004558 return SemaRef.Owned(E->Retain());
4559
4560 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004561 /*FIXME:*/E->getTypeBeginLoc(),
4562 T,
4563 E->getRParenLoc());
4564}
Mike Stump1eb44332009-09-09 15:08:12 +00004565
Douglas Gregorb98b1992009-08-11 05:31:07 +00004566template<typename Derived>
4567Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004568TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004569 // Transform the type that we're allocating
4570 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4571 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4572 if (AllocType.isNull())
4573 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004574
Douglas Gregorb98b1992009-08-11 05:31:07 +00004575 // Transform the size of the array we're allocating (if any).
4576 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4577 if (ArraySize.isInvalid())
4578 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004579
Douglas Gregorb98b1992009-08-11 05:31:07 +00004580 // Transform the placement arguments (if any).
4581 bool ArgumentChanged = false;
4582 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4583 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4584 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4585 if (Arg.isInvalid())
4586 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004587
Douglas Gregorb98b1992009-08-11 05:31:07 +00004588 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4589 PlacementArgs.push_back(Arg.take());
4590 }
Mike Stump1eb44332009-09-09 15:08:12 +00004591
Douglas Gregor43959a92009-08-20 07:17:43 +00004592 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004593 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4594 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4595 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4596 if (Arg.isInvalid())
4597 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004598
Douglas Gregorb98b1992009-08-11 05:31:07 +00004599 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4600 ConstructorArgs.push_back(Arg.take());
4601 }
Mike Stump1eb44332009-09-09 15:08:12 +00004602
Douglas Gregorb98b1992009-08-11 05:31:07 +00004603 if (!getDerived().AlwaysRebuild() &&
4604 AllocType == E->getAllocatedType() &&
4605 ArraySize.get() == E->getArraySize() &&
4606 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004607 return SemaRef.Owned(E->Retain());
4608
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004609 if (!ArraySize.get()) {
4610 // If no array size was specified, but the new expression was
4611 // instantiated with an array type (e.g., "new T" where T is
4612 // instantiated with "int[4]"), extract the outer bound from the
4613 // array type as our array size. We do this with constant and
4614 // dependently-sized array types.
4615 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4616 if (!ArrayT) {
4617 // Do nothing
4618 } else if (const ConstantArrayType *ConsArrayT
4619 = dyn_cast<ConstantArrayType>(ArrayT)) {
4620 ArraySize
4621 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4622 ConsArrayT->getSize(),
4623 SemaRef.Context.getSizeType(),
4624 /*FIXME:*/E->getLocStart()));
4625 AllocType = ConsArrayT->getElementType();
4626 } else if (const DependentSizedArrayType *DepArrayT
4627 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4628 if (DepArrayT->getSizeExpr()) {
4629 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4630 AllocType = DepArrayT->getElementType();
4631 }
4632 }
4633 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004634 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4635 E->isGlobalNew(),
4636 /*FIXME:*/E->getLocStart(),
4637 move_arg(PlacementArgs),
4638 /*FIXME:*/E->getLocStart(),
4639 E->isParenTypeId(),
4640 AllocType,
4641 /*FIXME:*/E->getLocStart(),
4642 /*FIXME:*/SourceRange(),
4643 move(ArraySize),
4644 /*FIXME:*/E->getLocStart(),
4645 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004646 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004647}
Mike Stump1eb44332009-09-09 15:08:12 +00004648
Douglas Gregorb98b1992009-08-11 05:31:07 +00004649template<typename Derived>
4650Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004651TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004652 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4653 if (Operand.isInvalid())
4654 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004655
Douglas Gregorb98b1992009-08-11 05:31:07 +00004656 if (!getDerived().AlwaysRebuild() &&
Mike Stump1eb44332009-09-09 15:08:12 +00004657 Operand.get() == E->getArgument())
4658 return SemaRef.Owned(E->Retain());
4659
Douglas Gregorb98b1992009-08-11 05:31:07 +00004660 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4661 E->isGlobalDelete(),
4662 E->isArrayForm(),
4663 move(Operand));
4664}
Mike Stump1eb44332009-09-09 15:08:12 +00004665
Douglas Gregorb98b1992009-08-11 05:31:07 +00004666template<typename Derived>
4667Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004668TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004669 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004670 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4671 if (Base.isInvalid())
4672 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004673
Douglas Gregora71d8192009-09-04 17:36:40 +00004674 NestedNameSpecifier *Qualifier
4675 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004676 E->getQualifierRange(),
4677 true);
Douglas Gregora71d8192009-09-04 17:36:40 +00004678 if (E->getQualifier() && !Qualifier)
4679 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004680
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004681 // FIXME: Object type!
4682 TypeSourceInfo *DestroyedTypeInfo
4683 = getDerived().TransformType(E->getDestroyedTypeInfo());
4684 if (!DestroyedTypeInfo)
4685 return SemaRef.ExprError();
4686
4687 // FIXME: Object type!
4688 TypeSourceInfo *ScopeTypeInfo = 0;
4689 if (E->getScopeTypeInfo()) {
4690 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
4691 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00004692 return SemaRef.ExprError();
4693 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004694
Douglas Gregora71d8192009-09-04 17:36:40 +00004695 if (!getDerived().AlwaysRebuild() &&
4696 Base.get() == E->getBase() &&
4697 Qualifier == E->getQualifier() &&
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004698 ScopeTypeInfo == E->getScopeTypeInfo() &&
4699 DestroyedTypeInfo == E->getDestroyedTypeInfo())
Douglas Gregora71d8192009-09-04 17:36:40 +00004700 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004701
Douglas Gregora71d8192009-09-04 17:36:40 +00004702 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4703 E->getOperatorLoc(),
4704 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00004705 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004706 E->getQualifierRange(),
4707 ScopeTypeInfo,
4708 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00004709 E->getTildeLoc(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004710 DestroyedTypeInfo);
Douglas Gregora71d8192009-09-04 17:36:40 +00004711}
Mike Stump1eb44332009-09-09 15:08:12 +00004712
Douglas Gregora71d8192009-09-04 17:36:40 +00004713template<typename Derived>
4714Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004715TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004716 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004717 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4718
4719 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4720 Sema::LookupOrdinaryName);
4721
4722 // Transform all the decls.
4723 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4724 E = Old->decls_end(); I != E; ++I) {
4725 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00004726 if (!InstD) {
4727 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4728 // This can happen because of dependent hiding.
4729 if (isa<UsingShadowDecl>(*I))
4730 continue;
4731 else
4732 return SemaRef.ExprError();
4733 }
John McCallf7a1a742009-11-24 19:00:30 +00004734
4735 // Expand using declarations.
4736 if (isa<UsingDecl>(InstD)) {
4737 UsingDecl *UD = cast<UsingDecl>(InstD);
4738 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4739 E = UD->shadow_end(); I != E; ++I)
4740 R.addDecl(*I);
4741 continue;
4742 }
4743
4744 R.addDecl(InstD);
4745 }
4746
4747 // Resolve a kind, but don't do any further analysis. If it's
4748 // ambiguous, the callee needs to deal with it.
4749 R.resolveKind();
4750
4751 // Rebuild the nested-name qualifier, if present.
4752 CXXScopeSpec SS;
4753 NestedNameSpecifier *Qualifier = 0;
4754 if (Old->getQualifier()) {
4755 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004756 Old->getQualifierRange(),
4757 false);
John McCallf7a1a742009-11-24 19:00:30 +00004758 if (!Qualifier)
4759 return SemaRef.ExprError();
4760
4761 SS.setScopeRep(Qualifier);
4762 SS.setRange(Old->getQualifierRange());
4763 }
4764
4765 // If we have no template arguments, it's a normal declaration name.
4766 if (!Old->hasExplicitTemplateArgs())
4767 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4768
4769 // If we have template arguments, rebuild them, then rebuild the
4770 // templateid expression.
4771 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4772 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4773 TemplateArgumentLoc Loc;
4774 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4775 return SemaRef.ExprError();
4776 TransArgs.addArgument(Loc);
4777 }
4778
4779 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4780 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004781}
Mike Stump1eb44332009-09-09 15:08:12 +00004782
Douglas Gregorb98b1992009-08-11 05:31:07 +00004783template<typename Derived>
4784Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004785TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004786 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004787
Douglas Gregorb98b1992009-08-11 05:31:07 +00004788 QualType T = getDerived().TransformType(E->getQueriedType());
4789 if (T.isNull())
4790 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004791
Douglas Gregorb98b1992009-08-11 05:31:07 +00004792 if (!getDerived().AlwaysRebuild() &&
4793 T == E->getQueriedType())
4794 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004795
Douglas Gregorb98b1992009-08-11 05:31:07 +00004796 // FIXME: Bad location information
4797 SourceLocation FakeLParenLoc
4798 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004799
4800 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004801 E->getLocStart(),
4802 /*FIXME:*/FakeLParenLoc,
4803 T,
4804 E->getLocEnd());
4805}
Mike Stump1eb44332009-09-09 15:08:12 +00004806
Douglas Gregorb98b1992009-08-11 05:31:07 +00004807template<typename Derived>
4808Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004809TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004810 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004811 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004812 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004813 E->getQualifierRange(),
4814 false);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004815 if (!NNS)
4816 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004817
4818 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004819 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4820 if (!Name)
4821 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004822
John McCallf7a1a742009-11-24 19:00:30 +00004823 if (!E->hasExplicitTemplateArgs()) {
4824 if (!getDerived().AlwaysRebuild() &&
4825 NNS == E->getQualifier() &&
4826 Name == E->getDeclName())
4827 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004828
John McCallf7a1a742009-11-24 19:00:30 +00004829 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4830 E->getQualifierRange(),
4831 Name, E->getLocation(),
4832 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004833 }
John McCalld5532b62009-11-23 01:53:49 +00004834
4835 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004836 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004837 TemplateArgumentLoc Loc;
4838 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004839 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004840 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004841 }
4842
John McCallf7a1a742009-11-24 19:00:30 +00004843 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4844 E->getQualifierRange(),
4845 Name, E->getLocation(),
4846 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004847}
4848
4849template<typename Derived>
4850Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004851TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00004852 // CXXConstructExprs are always implicit, so when we have a
4853 // 1-argument construction we just transform that argument.
4854 if (E->getNumArgs() == 1 ||
4855 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4856 return getDerived().TransformExpr(E->getArg(0));
4857
Douglas Gregorb98b1992009-08-11 05:31:07 +00004858 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4859
4860 QualType T = getDerived().TransformType(E->getType());
4861 if (T.isNull())
4862 return SemaRef.ExprError();
4863
4864 CXXConstructorDecl *Constructor
4865 = cast_or_null<CXXConstructorDecl>(
4866 getDerived().TransformDecl(E->getConstructor()));
4867 if (!Constructor)
4868 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Douglas Gregorb98b1992009-08-11 05:31:07 +00004870 bool ArgumentChanged = false;
4871 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004872 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004873 ArgEnd = E->arg_end();
4874 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004875 if (getDerived().DropCallArgument(*Arg)) {
4876 ArgumentChanged = true;
4877 break;
4878 }
4879
Douglas Gregorb98b1992009-08-11 05:31:07 +00004880 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4881 if (TransArg.isInvalid())
4882 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004883
Douglas Gregorb98b1992009-08-11 05:31:07 +00004884 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4885 Args.push_back(TransArg.takeAs<Expr>());
4886 }
4887
4888 if (!getDerived().AlwaysRebuild() &&
4889 T == E->getType() &&
4890 Constructor == E->getConstructor() &&
4891 !ArgumentChanged)
4892 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004893
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004894 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4895 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004896 move_arg(Args));
4897}
Mike Stump1eb44332009-09-09 15:08:12 +00004898
Douglas Gregorb98b1992009-08-11 05:31:07 +00004899/// \brief Transform a C++ temporary-binding expression.
4900///
Douglas Gregor51326552009-12-24 18:51:59 +00004901/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4902/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004903template<typename Derived>
4904Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004905TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00004906 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004907}
Mike Stump1eb44332009-09-09 15:08:12 +00004908
Anders Carlssoneb60edf2010-01-29 02:39:32 +00004909/// \brief Transform a C++ reference-binding expression.
4910///
4911/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4912/// transform the subexpression and return that.
4913template<typename Derived>
4914Sema::OwningExprResult
4915TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4916 return getDerived().TransformExpr(E->getSubExpr());
4917}
4918
Mike Stump1eb44332009-09-09 15:08:12 +00004919/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00004920/// be destroyed after the expression is evaluated.
4921///
Douglas Gregor51326552009-12-24 18:51:59 +00004922/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4923/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004924template<typename Derived>
4925Sema::OwningExprResult
4926TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00004927 CXXExprWithTemporaries *E) {
4928 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004929}
Mike Stump1eb44332009-09-09 15:08:12 +00004930
Douglas Gregorb98b1992009-08-11 05:31:07 +00004931template<typename Derived>
4932Sema::OwningExprResult
4933TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00004934 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004935 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4936 QualType T = getDerived().TransformType(E->getType());
4937 if (T.isNull())
4938 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004939
Douglas Gregorb98b1992009-08-11 05:31:07 +00004940 CXXConstructorDecl *Constructor
4941 = cast_or_null<CXXConstructorDecl>(
4942 getDerived().TransformDecl(E->getConstructor()));
4943 if (!Constructor)
4944 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004945
Douglas Gregorb98b1992009-08-11 05:31:07 +00004946 bool ArgumentChanged = false;
4947 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4948 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00004949 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004950 ArgEnd = E->arg_end();
4951 Arg != ArgEnd; ++Arg) {
4952 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4953 if (TransArg.isInvalid())
4954 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004955
Douglas Gregorb98b1992009-08-11 05:31:07 +00004956 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4957 Args.push_back((Expr *)TransArg.release());
4958 }
Mike Stump1eb44332009-09-09 15:08:12 +00004959
Douglas Gregorb98b1992009-08-11 05:31:07 +00004960 if (!getDerived().AlwaysRebuild() &&
4961 T == E->getType() &&
4962 Constructor == E->getConstructor() &&
4963 !ArgumentChanged)
4964 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004965
Douglas Gregorb98b1992009-08-11 05:31:07 +00004966 // FIXME: Bogus location information
4967 SourceLocation CommaLoc;
4968 if (Args.size() > 1) {
4969 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00004970 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004971 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4972 }
4973 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4974 T,
4975 /*FIXME:*/E->getTypeBeginLoc(),
4976 move_arg(Args),
4977 &CommaLoc,
4978 E->getLocEnd());
4979}
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981template<typename Derived>
4982Sema::OwningExprResult
4983TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00004984 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004985 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4986 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4987 if (T.isNull())
4988 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004989
Douglas Gregorb98b1992009-08-11 05:31:07 +00004990 bool ArgumentChanged = false;
4991 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4992 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4993 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4994 ArgEnd = E->arg_end();
4995 Arg != ArgEnd; ++Arg) {
4996 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4997 if (TransArg.isInvalid())
4998 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregorb98b1992009-08-11 05:31:07 +00005000 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5001 FakeCommaLocs.push_back(
5002 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5003 Args.push_back(TransArg.takeAs<Expr>());
5004 }
Mike Stump1eb44332009-09-09 15:08:12 +00005005
Douglas Gregorb98b1992009-08-11 05:31:07 +00005006 if (!getDerived().AlwaysRebuild() &&
5007 T == E->getTypeAsWritten() &&
5008 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005009 return SemaRef.Owned(E->Retain());
5010
Douglas Gregorb98b1992009-08-11 05:31:07 +00005011 // FIXME: we're faking the locations of the commas
5012 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5013 T,
5014 E->getLParenLoc(),
5015 move_arg(Args),
5016 FakeCommaLocs.data(),
5017 E->getRParenLoc());
5018}
Mike Stump1eb44332009-09-09 15:08:12 +00005019
Douglas Gregorb98b1992009-08-11 05:31:07 +00005020template<typename Derived>
5021Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005022TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005023 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005024 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005025 OwningExprResult Base(SemaRef, (Expr*) 0);
5026 Expr *OldBase;
5027 QualType BaseType;
5028 QualType ObjectType;
5029 if (!E->isImplicitAccess()) {
5030 OldBase = E->getBase();
5031 Base = getDerived().TransformExpr(OldBase);
5032 if (Base.isInvalid())
5033 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005034
John McCallaa81e162009-12-01 22:10:20 +00005035 // Start the member reference and compute the object's type.
5036 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005037 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005038 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5039 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005040 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005041 ObjectTy,
5042 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005043 if (Base.isInvalid())
5044 return SemaRef.ExprError();
5045
5046 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5047 BaseType = ((Expr*) Base.get())->getType();
5048 } else {
5049 OldBase = 0;
5050 BaseType = getDerived().TransformType(E->getBaseType());
5051 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5052 }
Mike Stump1eb44332009-09-09 15:08:12 +00005053
Douglas Gregor6cd21982009-10-20 05:58:46 +00005054 // Transform the first part of the nested-name-specifier that qualifies
5055 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005056 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005057 = getDerived().TransformFirstQualifierInScope(
5058 E->getFirstQualifierFoundInScope(),
5059 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005060
Douglas Gregora38c6872009-09-03 16:14:30 +00005061 NestedNameSpecifier *Qualifier = 0;
5062 if (E->getQualifier()) {
Douglas Gregorb10cd042010-02-21 18:36:56 +00005063 bool MayBePseudoDestructor
5064 = E->getMember().getNameKind() == DeclarationName::CXXDestructorName;
Douglas Gregora38c6872009-09-03 16:14:30 +00005065 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5066 E->getQualifierRange(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005067 MayBePseudoDestructor,
John McCallaa81e162009-12-01 22:10:20 +00005068 ObjectType,
5069 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005070 if (!Qualifier)
5071 return SemaRef.ExprError();
5072 }
Mike Stump1eb44332009-09-09 15:08:12 +00005073
5074 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005075 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005076 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005077 if (!Name)
5078 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005079
John McCallaa81e162009-12-01 22:10:20 +00005080 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005081 // This is a reference to a member without an explicitly-specified
5082 // template argument list. Optimize for this common case.
5083 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005084 Base.get() == OldBase &&
5085 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005086 Qualifier == E->getQualifier() &&
5087 Name == E->getMember() &&
5088 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005089 return SemaRef.Owned(E->Retain());
5090
John McCall865d4472009-11-19 22:55:06 +00005091 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005092 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005093 E->isArrow(),
5094 E->getOperatorLoc(),
5095 Qualifier,
5096 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005097 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005098 Name,
5099 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005100 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005101 }
5102
John McCalld5532b62009-11-23 01:53:49 +00005103 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005104 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005105 TemplateArgumentLoc Loc;
5106 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005107 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005108 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005109 }
Mike Stump1eb44332009-09-09 15:08:12 +00005110
John McCall865d4472009-11-19 22:55:06 +00005111 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005112 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113 E->isArrow(),
5114 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005115 Qualifier,
5116 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005117 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005118 Name,
5119 E->getMemberLoc(),
5120 &TransArgs);
5121}
5122
5123template<typename Derived>
5124Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005126 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005127 OwningExprResult Base(SemaRef, (Expr*) 0);
5128 QualType BaseType;
5129 if (!Old->isImplicitAccess()) {
5130 Base = getDerived().TransformExpr(Old->getBase());
5131 if (Base.isInvalid())
5132 return SemaRef.ExprError();
5133 BaseType = ((Expr*) Base.get())->getType();
5134 } else {
5135 BaseType = getDerived().TransformType(Old->getBaseType());
5136 }
John McCall129e2df2009-11-30 22:42:35 +00005137
5138 NestedNameSpecifier *Qualifier = 0;
5139 if (Old->getQualifier()) {
5140 Qualifier
5141 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00005142 Old->getQualifierRange(),
5143 false);
John McCall129e2df2009-11-30 22:42:35 +00005144 if (Qualifier == 0)
5145 return SemaRef.ExprError();
5146 }
5147
5148 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5149 Sema::LookupOrdinaryName);
5150
5151 // Transform all the decls.
5152 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5153 E = Old->decls_end(); I != E; ++I) {
5154 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall9f54ad42009-12-10 09:41:52 +00005155 if (!InstD) {
5156 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5157 // This can happen because of dependent hiding.
5158 if (isa<UsingShadowDecl>(*I))
5159 continue;
5160 else
5161 return SemaRef.ExprError();
5162 }
John McCall129e2df2009-11-30 22:42:35 +00005163
5164 // Expand using declarations.
5165 if (isa<UsingDecl>(InstD)) {
5166 UsingDecl *UD = cast<UsingDecl>(InstD);
5167 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5168 E = UD->shadow_end(); I != E; ++I)
5169 R.addDecl(*I);
5170 continue;
5171 }
5172
5173 R.addDecl(InstD);
5174 }
5175
5176 R.resolveKind();
5177
5178 TemplateArgumentListInfo TransArgs;
5179 if (Old->hasExplicitTemplateArgs()) {
5180 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5181 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5182 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5183 TemplateArgumentLoc Loc;
5184 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5185 Loc))
5186 return SemaRef.ExprError();
5187 TransArgs.addArgument(Loc);
5188 }
5189 }
John McCallc2233c52010-01-15 08:34:02 +00005190
5191 // FIXME: to do this check properly, we will need to preserve the
5192 // first-qualifier-in-scope here, just in case we had a dependent
5193 // base (and therefore couldn't do the check) and a
5194 // nested-name-qualifier (and therefore could do the lookup).
5195 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005196
5197 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005198 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005199 Old->getOperatorLoc(),
5200 Old->isArrow(),
5201 Qualifier,
5202 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005203 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005204 R,
5205 (Old->hasExplicitTemplateArgs()
5206 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005207}
5208
5209template<typename Derived>
5210Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005211TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005212 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005213}
5214
Mike Stump1eb44332009-09-09 15:08:12 +00005215template<typename Derived>
5216Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005217TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218 // FIXME: poor source location
5219 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5220 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5221 if (EncodedType.isNull())
5222 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregorb98b1992009-08-11 05:31:07 +00005224 if (!getDerived().AlwaysRebuild() &&
5225 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005226 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227
5228 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5229 EncodedType,
5230 E->getRParenLoc());
5231}
Mike Stump1eb44332009-09-09 15:08:12 +00005232
Douglas Gregorb98b1992009-08-11 05:31:07 +00005233template<typename Derived>
5234Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005235TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005236 // FIXME: Implement this!
5237 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005238 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239}
5240
Mike Stump1eb44332009-09-09 15:08:12 +00005241template<typename Derived>
5242Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005243TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005244 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005245}
5246
Mike Stump1eb44332009-09-09 15:08:12 +00005247template<typename Derived>
5248Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005249TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005250 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 = cast_or_null<ObjCProtocolDecl>(
5252 getDerived().TransformDecl(E->getProtocol()));
5253 if (!Protocol)
5254 return SemaRef.ExprError();
5255
5256 if (!getDerived().AlwaysRebuild() &&
5257 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005258 return SemaRef.Owned(E->Retain());
5259
Douglas Gregorb98b1992009-08-11 05:31:07 +00005260 return getDerived().RebuildObjCProtocolExpr(Protocol,
5261 E->getAtLoc(),
5262 /*FIXME:*/E->getAtLoc(),
5263 /*FIXME:*/E->getAtLoc(),
5264 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005265
Douglas Gregorb98b1992009-08-11 05:31:07 +00005266}
5267
Mike Stump1eb44332009-09-09 15:08:12 +00005268template<typename Derived>
5269Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005270TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005271 // FIXME: Implement this!
5272 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005273 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274}
5275
Mike Stump1eb44332009-09-09 15:08:12 +00005276template<typename Derived>
5277Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005278TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005279 // FIXME: Implement this!
5280 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005281 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282}
5283
Mike Stump1eb44332009-09-09 15:08:12 +00005284template<typename Derived>
5285Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005286TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005287 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005288 // FIXME: Implement this!
5289 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005290 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005291}
5292
Mike Stump1eb44332009-09-09 15:08:12 +00005293template<typename Derived>
5294Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005295TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005296 // FIXME: Implement this!
5297 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005298 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005299}
5300
Mike Stump1eb44332009-09-09 15:08:12 +00005301template<typename Derived>
5302Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005303TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005304 // FIXME: Implement this!
5305 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005306 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005307}
5308
Mike Stump1eb44332009-09-09 15:08:12 +00005309template<typename Derived>
5310Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005311TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005312 bool ArgumentChanged = false;
5313 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5314 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5315 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5316 if (SubExpr.isInvalid())
5317 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregorb98b1992009-08-11 05:31:07 +00005319 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5320 SubExprs.push_back(SubExpr.takeAs<Expr>());
5321 }
Mike Stump1eb44332009-09-09 15:08:12 +00005322
Douglas Gregorb98b1992009-08-11 05:31:07 +00005323 if (!getDerived().AlwaysRebuild() &&
5324 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005325 return SemaRef.Owned(E->Retain());
5326
Douglas Gregorb98b1992009-08-11 05:31:07 +00005327 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5328 move_arg(SubExprs),
5329 E->getRParenLoc());
5330}
5331
Mike Stump1eb44332009-09-09 15:08:12 +00005332template<typename Derived>
5333Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005334TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005335 // FIXME: Implement this!
5336 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005337 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005338}
5339
Mike Stump1eb44332009-09-09 15:08:12 +00005340template<typename Derived>
5341Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005342TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005343 // FIXME: Implement this!
5344 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005345 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005346}
Mike Stump1eb44332009-09-09 15:08:12 +00005347
Douglas Gregorb98b1992009-08-11 05:31:07 +00005348//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005349// Type reconstruction
5350//===----------------------------------------------------------------------===//
5351
Mike Stump1eb44332009-09-09 15:08:12 +00005352template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005353QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5354 SourceLocation Star) {
5355 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005356 getDerived().getBaseEntity());
5357}
5358
Mike Stump1eb44332009-09-09 15:08:12 +00005359template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005360QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5361 SourceLocation Star) {
5362 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005363 getDerived().getBaseEntity());
5364}
5365
Mike Stump1eb44332009-09-09 15:08:12 +00005366template<typename Derived>
5367QualType
John McCall85737a72009-10-30 00:06:24 +00005368TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5369 bool WrittenAsLValue,
5370 SourceLocation Sigil) {
5371 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5372 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005373}
5374
5375template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005376QualType
John McCall85737a72009-10-30 00:06:24 +00005377TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5378 QualType ClassType,
5379 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005380 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005381 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005382}
5383
5384template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005385QualType
John McCall85737a72009-10-30 00:06:24 +00005386TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5387 SourceLocation Sigil) {
5388 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005389 getDerived().getBaseEntity());
5390}
5391
5392template<typename Derived>
5393QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005394TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5395 ArrayType::ArraySizeModifier SizeMod,
5396 const llvm::APInt *Size,
5397 Expr *SizeExpr,
5398 unsigned IndexTypeQuals,
5399 SourceRange BracketsRange) {
5400 if (SizeExpr || !Size)
5401 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5402 IndexTypeQuals, BracketsRange,
5403 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005404
5405 QualType Types[] = {
5406 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5407 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5408 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005409 };
5410 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5411 QualType SizeType;
5412 for (unsigned I = 0; I != NumTypes; ++I)
5413 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5414 SizeType = Types[I];
5415 break;
5416 }
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor577f75a2009-08-04 16:50:30 +00005418 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005419 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005420 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005421 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005422}
Mike Stump1eb44332009-09-09 15:08:12 +00005423
Douglas Gregor577f75a2009-08-04 16:50:30 +00005424template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005425QualType
5426TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005427 ArrayType::ArraySizeModifier SizeMod,
5428 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005429 unsigned IndexTypeQuals,
5430 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005431 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005432 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005433}
5434
5435template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005436QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005437TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005438 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005439 unsigned IndexTypeQuals,
5440 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005441 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005442 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005443}
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor577f75a2009-08-04 16:50:30 +00005445template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005446QualType
5447TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005448 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005449 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005450 unsigned IndexTypeQuals,
5451 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005452 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005453 SizeExpr.takeAs<Expr>(),
5454 IndexTypeQuals, BracketsRange);
5455}
5456
5457template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005458QualType
5459TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005460 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005461 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005462 unsigned IndexTypeQuals,
5463 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005464 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005465 SizeExpr.takeAs<Expr>(),
5466 IndexTypeQuals, BracketsRange);
5467}
5468
5469template<typename Derived>
5470QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005471 unsigned NumElements,
5472 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005473 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005474 return SemaRef.Context.getVectorType(ElementType, NumElements,
5475 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005476}
Mike Stump1eb44332009-09-09 15:08:12 +00005477
Douglas Gregor577f75a2009-08-04 16:50:30 +00005478template<typename Derived>
5479QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5480 unsigned NumElements,
5481 SourceLocation AttributeLoc) {
5482 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5483 NumElements, true);
5484 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005485 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005486 AttributeLoc);
5487 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5488 AttributeLoc);
5489}
Mike Stump1eb44332009-09-09 15:08:12 +00005490
Douglas Gregor577f75a2009-08-04 16:50:30 +00005491template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005492QualType
5493TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005495 SourceLocation AttributeLoc) {
5496 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5497}
Mike Stump1eb44332009-09-09 15:08:12 +00005498
Douglas Gregor577f75a2009-08-04 16:50:30 +00005499template<typename Derived>
5500QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005501 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005502 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005503 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005504 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005505 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005506 Quals,
5507 getDerived().getBaseLocation(),
5508 getDerived().getBaseEntity());
5509}
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregor577f75a2009-08-04 16:50:30 +00005511template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005512QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5513 return SemaRef.Context.getFunctionNoProtoType(T);
5514}
5515
5516template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005517QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5518 assert(D && "no decl found");
5519 if (D->isInvalidDecl()) return QualType();
5520
5521 TypeDecl *Ty;
5522 if (isa<UsingDecl>(D)) {
5523 UsingDecl *Using = cast<UsingDecl>(D);
5524 assert(Using->isTypeName() &&
5525 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5526
5527 // A valid resolved using typename decl points to exactly one type decl.
5528 assert(++Using->shadow_begin() == Using->shadow_end());
5529 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5530
5531 } else {
5532 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5533 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5534 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5535 }
5536
5537 return SemaRef.Context.getTypeDeclType(Ty);
5538}
5539
5540template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005541QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005542 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5543}
5544
5545template<typename Derived>
5546QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5547 return SemaRef.Context.getTypeOfType(Underlying);
5548}
5549
5550template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005552 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5553}
5554
5555template<typename Derived>
5556QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005557 TemplateName Template,
5558 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005559 const TemplateArgumentListInfo &TemplateArgs) {
5560 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005561}
Mike Stump1eb44332009-09-09 15:08:12 +00005562
Douglas Gregordcee1a12009-08-06 05:28:30 +00005563template<typename Derived>
5564NestedNameSpecifier *
5565TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5566 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005567 IdentifierInfo &II,
Douglas Gregorb10cd042010-02-21 18:36:56 +00005568 bool MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005569 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005570 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005571 CXXScopeSpec SS;
5572 // FIXME: The source location information is all wrong.
5573 SS.setRange(Range);
5574 SS.setScopeRep(Prefix);
5575 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005576 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005577 Range.getEnd(), II,
Douglas Gregorb10cd042010-02-21 18:36:56 +00005578 MayBePseudoDestructor,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005579 ObjectType,
5580 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005581 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005582}
5583
5584template<typename Derived>
5585NestedNameSpecifier *
5586TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5587 SourceRange Range,
5588 NamespaceDecl *NS) {
5589 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5590}
5591
5592template<typename Derived>
5593NestedNameSpecifier *
5594TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5595 SourceRange Range,
5596 bool TemplateKW,
Douglas Gregorb10cd042010-02-21 18:36:56 +00005597 QualType T,
5598 bool MayBePseudoDestructor) {
5599 if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00005600 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005601 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005602 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5603 T.getTypePtr());
5604 }
Mike Stump1eb44332009-09-09 15:08:12 +00005605
Douglas Gregordcee1a12009-08-06 05:28:30 +00005606 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5607 return 0;
5608}
Mike Stump1eb44332009-09-09 15:08:12 +00005609
Douglas Gregord1067e52009-08-06 06:41:21 +00005610template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005611TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005612TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5613 bool TemplateKW,
5614 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005615 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005616 Template);
5617}
5618
5619template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005620TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005621TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005622 const IdentifierInfo &II,
5623 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005624 CXXScopeSpec SS;
5625 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005626 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005627 UnqualifiedId Name;
5628 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005629 return getSema().ActOnDependentTemplateName(
5630 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005631 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005632 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005633 ObjectType.getAsOpaquePtr(),
5634 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005635 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005636}
Mike Stump1eb44332009-09-09 15:08:12 +00005637
Douglas Gregorb98b1992009-08-11 05:31:07 +00005638template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005639TemplateName
5640TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5641 OverloadedOperatorKind Operator,
5642 QualType ObjectType) {
5643 CXXScopeSpec SS;
5644 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5645 SS.setScopeRep(Qualifier);
5646 UnqualifiedId Name;
5647 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5648 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5649 Operator, SymbolLocations);
5650 return getSema().ActOnDependentTemplateName(
5651 /*FIXME:*/getDerived().getBaseLocation(),
5652 SS,
5653 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005654 ObjectType.getAsOpaquePtr(),
5655 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005656 .template getAsVal<TemplateName>();
5657}
5658
5659template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005660Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5662 SourceLocation OpLoc,
5663 ExprArg Callee,
5664 ExprArg First,
5665 ExprArg Second) {
5666 Expr *FirstExpr = (Expr *)First.get();
5667 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005668 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005670
Douglas Gregorb98b1992009-08-11 05:31:07 +00005671 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005672 if (Op == OO_Subscript) {
5673 if (!FirstExpr->getType()->isOverloadableType() &&
5674 !SecondExpr->getType()->isOverloadableType())
5675 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005676 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005677 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005678 } else if (Op == OO_Arrow) {
5679 // -> is never a builtin operation.
5680 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005681 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005682 if (!FirstExpr->getType()->isOverloadableType()) {
5683 // The argument is not of overloadable type, so try to create a
5684 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005685 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5689 }
5690 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005691 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005692 !SecondExpr->getType()->isOverloadableType()) {
5693 // Neither of the arguments is an overloadable type, so try to
5694 // create a built-in binary operation.
5695 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005696 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5698 if (Result.isInvalid())
5699 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005700
Douglas Gregorb98b1992009-08-11 05:31:07 +00005701 First.release();
5702 Second.release();
5703 return move(Result);
5704 }
5705 }
Mike Stump1eb44332009-09-09 15:08:12 +00005706
5707 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005708 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005709 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005710
John McCallba135432009-11-21 08:51:07 +00005711 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5712 assert(ULE->requiresADL());
5713
5714 // FIXME: Do we have to check
5715 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005716 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005717 } else {
John McCall6e266892010-01-26 03:27:55 +00005718 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005719 }
Mike Stump1eb44332009-09-09 15:08:12 +00005720
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721 // Add any functions found via argument-dependent lookup.
5722 Expr *Args[2] = { FirstExpr, SecondExpr };
5723 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregorb98b1992009-08-11 05:31:07 +00005725 // Create the overloaded operator invocation for unary operators.
5726 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005727 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005728 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5729 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5730 }
Mike Stump1eb44332009-09-09 15:08:12 +00005731
Sebastian Redlf322ed62009-10-29 20:17:01 +00005732 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005733 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5734 OpLoc,
5735 move(First),
5736 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005737
Douglas Gregorb98b1992009-08-11 05:31:07 +00005738 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005739 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005741 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005742 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5743 if (Result.isInvalid())
5744 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005745
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746 First.release();
5747 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005748 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005749}
Mike Stump1eb44332009-09-09 15:08:12 +00005750
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005751template<typename Derived>
5752Sema::OwningExprResult
5753TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5754 SourceLocation OperatorLoc,
5755 bool isArrow,
5756 NestedNameSpecifier *Qualifier,
5757 SourceRange QualifierRange,
5758 TypeSourceInfo *ScopeType,
5759 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005760 SourceLocation TildeLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005761 TypeSourceInfo *DestroyedType) {
5762 CXXScopeSpec SS;
5763 if (Qualifier) {
5764 SS.setRange(QualifierRange);
5765 SS.setScopeRep(Qualifier);
5766 }
5767
5768 Expr *BaseE = (Expr *)Base.get();
5769 QualType BaseType = BaseE->getType();
5770 if (BaseE->isTypeDependent() ||
5771 (!isArrow && !BaseType->getAs<RecordType>()) ||
5772 (isArrow && BaseType->getAs<PointerType>() &&
5773 !BaseType->getAs<PointerType>()->getAs<RecordType>())) {
5774 // This pseudo-destructor expression is still a pseudo-destructor.
5775 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5776 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005777 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005778 DestroyedType,
5779 /*FIXME?*/true);
5780 }
5781
5782 DeclarationName Name
5783 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5784 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5785
5786 // FIXME: the ScopeType should be tacked onto SS.
5787
5788 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5789 OperatorLoc, isArrow,
5790 SS, /*FIXME: FirstQualifier*/ 0,
5791 Name,
5792 DestroyedType->getTypeLoc().getSourceRange().getBegin(),
5793 /*TemplateArgs*/ 0);
5794}
5795
Douglas Gregor577f75a2009-08-04 16:50:30 +00005796} // end namespace clang
5797
5798#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H