blob: 24ea62cde1b4a663f866a04f8c1ece0840db54eb [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.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, 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.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000248 }
Mike Stump1eb44332009-09-09 15:08:12 +0000249
Douglas Gregor6cd21982009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000261 }
262
Douglas Gregor577f75a2009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000272
Douglas Gregor81499bb2009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000284 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Douglas Gregor577f75a2009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCalla93c9342009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
John McCalla2becad2009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregor124b8782010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCalla2becad2009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000317
Douglas Gregor124b8782010-02-16 19:09:40 +0000318 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
319 QualType ObjectType);
John McCall85737a72009-10-30 00:06:24 +0000320
Douglas Gregordd62b152009-10-19 22:04:39 +0000321 QualType
322 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
323 QualType ObjectType);
John McCall833ca992009-10-29 08:12:44 +0000324
Douglas Gregor43959a92009-08-20 07:17:43 +0000325 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump1eb44332009-09-09 15:08:12 +0000326
Douglas Gregor43959a92009-08-20 07:17:43 +0000327#define STMT(Node, Parent) \
328 OwningStmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000329#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +0000330 OwningExprResult Transform##Node(Node *E);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000331#define ABSTRACT_EXPR(Node, Parent)
332#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +0000333
Douglas Gregor577f75a2009-08-04 16:50:30 +0000334 /// \brief Build a new pointer type given its pointee type.
335 ///
336 /// By default, performs semantic analysis when building the pointer type.
337 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000338 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000339
340 /// \brief Build a new block pointer type given its pointee type.
341 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000342 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000343 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000344 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000345
John McCall85737a72009-10-30 00:06:24 +0000346 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000347 ///
John McCall85737a72009-10-30 00:06:24 +0000348 /// By default, performs semantic analysis when building the
349 /// reference type. Subclasses may override this routine to provide
350 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 ///
John McCall85737a72009-10-30 00:06:24 +0000352 /// \param LValue whether the type was written with an lvalue sigil
353 /// or an rvalue sigil.
354 QualType RebuildReferenceType(QualType ReferentType,
355 bool LValue,
356 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000357
Douglas Gregor577f75a2009-08-04 16:50:30 +0000358 /// \brief Build a new member pointer type given the pointee type and the
359 /// class type it refers into.
360 ///
361 /// By default, performs semantic analysis when building the member pointer
362 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000363 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
364 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000365
John McCalla2becad2009-10-21 00:40:46 +0000366 /// \brief Build a new Objective C object pointer type.
John McCall85737a72009-10-30 00:06:24 +0000367 QualType RebuildObjCObjectPointerType(QualType PointeeType,
368 SourceLocation Sigil);
John McCalla2becad2009-10-21 00:40:46 +0000369
Douglas Gregor577f75a2009-08-04 16:50:30 +0000370 /// \brief Build a new array type given the element type, size
371 /// modifier, size of the array (if known), size expression, and index type
372 /// qualifiers.
373 ///
374 /// By default, performs semantic analysis when building the array type.
375 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000376 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000377 QualType RebuildArrayType(QualType ElementType,
378 ArrayType::ArraySizeModifier SizeMod,
379 const llvm::APInt *Size,
380 Expr *SizeExpr,
381 unsigned IndexTypeQuals,
382 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000383
Douglas Gregor577f75a2009-08-04 16:50:30 +0000384 /// \brief Build a new constant array type given the element type, size
385 /// modifier, (known) size of the array, and index type qualifiers.
386 ///
387 /// By default, performs semantic analysis when building the array type.
388 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000389 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000392 unsigned IndexTypeQuals,
393 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000394
Douglas Gregor577f75a2009-08-04 16:50:30 +0000395 /// \brief Build a new incomplete array type given the element type, size
396 /// modifier, and index type qualifiers.
397 ///
398 /// By default, performs semantic analysis when building the array type.
399 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000401 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000404
Mike Stump1eb44332009-09-09 15:08:12 +0000405 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000406 /// size modifier, size expression, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000410 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000412 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000413 unsigned IndexTypeQuals,
414 SourceRange BracketsRange);
415
Mike Stump1eb44332009-09-09 15:08:12 +0000416 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000417 /// size modifier, size expression, and index type qualifiers.
418 ///
419 /// By default, performs semantic analysis when building the array type.
420 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000421 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000422 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000423 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000424 unsigned IndexTypeQuals,
425 SourceRange BracketsRange);
426
427 /// \brief Build a new vector type given the element type and
428 /// number of elements.
429 ///
430 /// By default, performs semantic analysis when building the vector type.
431 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000432 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
433 bool IsAltiVec, bool IsPixel);
Mike Stump1eb44332009-09-09 15:08:12 +0000434
Douglas Gregor577f75a2009-08-04 16:50:30 +0000435 /// \brief Build a new extended vector type given the element type and
436 /// number of elements.
437 ///
438 /// By default, performs semantic analysis when building the vector type.
439 /// Subclasses may override this routine to provide different behavior.
440 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
441 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000442
443 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000444 /// given the element type and number of elements.
445 ///
446 /// By default, performs semantic analysis when building the vector type.
447 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000448 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000449 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000450 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000451
Douglas Gregor577f75a2009-08-04 16:50:30 +0000452 /// \brief Build a new function type.
453 ///
454 /// By default, performs semantic analysis when building the function type.
455 /// Subclasses may override this routine to provide different behavior.
456 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000457 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000458 unsigned NumParamTypes,
459 bool Variadic, unsigned Quals);
Mike Stump1eb44332009-09-09 15:08:12 +0000460
John McCalla2becad2009-10-21 00:40:46 +0000461 /// \brief Build a new unprototyped function type.
462 QualType RebuildFunctionNoProtoType(QualType ResultType);
463
John McCalled976492009-12-04 22:46:56 +0000464 /// \brief Rebuild an unresolved typename type, given the decl that
465 /// the UnresolvedUsingTypenameDecl was transformed to.
466 QualType RebuildUnresolvedUsingType(Decl *D);
467
Douglas Gregor577f75a2009-08-04 16:50:30 +0000468 /// \brief Build a new typedef type.
469 QualType RebuildTypedefType(TypedefDecl *Typedef) {
470 return SemaRef.Context.getTypeDeclType(Typedef);
471 }
472
473 /// \brief Build a new class/struct/union type.
474 QualType RebuildRecordType(RecordDecl *Record) {
475 return SemaRef.Context.getTypeDeclType(Record);
476 }
477
478 /// \brief Build a new Enum type.
479 QualType RebuildEnumType(EnumDecl *Enum) {
480 return SemaRef.Context.getTypeDeclType(Enum);
481 }
John McCall7da24312009-09-05 00:15:47 +0000482
483 /// \brief Build a new elaborated type.
484 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
485 return SemaRef.Context.getElaboratedType(T, Tag);
486 }
Mike Stump1eb44332009-09-09 15:08:12 +0000487
488 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000489 ///
490 /// By default, performs semantic analysis when building the typeof type.
491 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000492 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
Mike Stump1eb44332009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000495 ///
496 /// By default, builds a new TypeOfType with the given underlying type.
497 QualType RebuildTypeOfType(QualType Underlying);
498
Mike Stump1eb44332009-09-09 15:08:12 +0000499 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000500 ///
501 /// By default, performs semantic analysis when building the decltype type.
502 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb98b1992009-08-11 05:31:07 +0000503 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump1eb44332009-09-09 15:08:12 +0000504
Douglas Gregor577f75a2009-08-04 16:50:30 +0000505 /// \brief Build a new template specialization type.
506 ///
507 /// By default, performs semantic analysis when building the template
508 /// specialization type. Subclasses may override this routine to provide
509 /// different behavior.
510 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000511 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000512 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000513
Douglas Gregor577f75a2009-08-04 16:50:30 +0000514 /// \brief Build a new qualified name type.
515 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000516 /// By default, builds a new QualifiedNameType type from the
517 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregor577f75a2009-08-04 16:50:30 +0000518 /// this routine to provide different behavior.
519 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
520 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000521 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000522
523 /// \brief Build a new typename type that refers to a template-id.
524 ///
525 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump1eb44332009-09-09 15:08:12 +0000526 /// and the given type. Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000527 /// different behavior.
528 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregorae628892010-02-13 06:05:33 +0000529 if (NNS->isDependent()) {
530 CXXScopeSpec SS;
531 SS.setScopeRep(NNS);
532 if (!SemaRef.computeDeclContext(SS))
533 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000534 cast<TemplateSpecializationType>(T));
Douglas Gregorae628892010-02-13 06:05:33 +0000535 }
Mike Stump1eb44332009-09-09 15:08:12 +0000536
Douglas Gregor577f75a2009-08-04 16:50:30 +0000537 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000538 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000539
540 /// \brief Build a new typename type that refers to an identifier.
541 ///
542 /// By default, performs semantic analysis when building the typename type
Mike Stump1eb44332009-09-09 15:08:12 +0000543 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000544 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000545 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall833ca992009-10-29 08:12:44 +0000546 const IdentifierInfo *Id,
547 SourceRange SR) {
548 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000549 }
Mike Stump1eb44332009-09-09 15:08:12 +0000550
Douglas Gregordcee1a12009-08-06 05:28:30 +0000551 /// \brief Build a new nested-name-specifier given the prefix and an
552 /// identifier that names the next step in the nested-name-specifier.
553 ///
554 /// By default, performs semantic analysis when building the new
555 /// nested-name-specifier. Subclasses may override this routine to provide
556 /// different behavior.
557 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
558 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000559 IdentifierInfo &II,
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 Gregoredc90502010-02-25 04:46:04 +0000582 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000583
584 /// \brief Build a new template name given a nested name specifier, a flag
585 /// indicating whether the "template" keyword was provided, and the template
586 /// that the template name refers to.
587 ///
588 /// By default, builds the new template name directly. Subclasses may override
589 /// this routine to provide different behavior.
590 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
591 bool TemplateKW,
592 TemplateDecl *Template);
593
Douglas Gregord1067e52009-08-06 06:41:21 +0000594 /// \brief Build a new template name given a nested name specifier and the
595 /// name that is referred to as a template.
596 ///
597 /// By default, performs semantic analysis to determine whether the name can
598 /// be resolved to a specific template, then builds the appropriate kind of
599 /// template name. Subclasses may override this routine to provide different
600 /// behavior.
601 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000602 const IdentifierInfo &II,
603 QualType ObjectType);
Mike Stump1eb44332009-09-09 15:08:12 +0000604
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000605 /// \brief Build a new template name given a nested name specifier and the
606 /// overloaded operator name that is referred to as a template.
607 ///
608 /// By default, performs semantic analysis to determine whether the name can
609 /// be resolved to a specific template, then builds the appropriate kind of
610 /// template name. Subclasses may override this routine to provide different
611 /// behavior.
612 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
613 OverloadedOperatorKind Operator,
614 QualType ObjectType);
615
Douglas Gregor43959a92009-08-20 07:17:43 +0000616 /// \brief Build a new compound statement.
617 ///
618 /// By default, performs semantic analysis to build the new statement.
619 /// Subclasses may override this routine to provide different behavior.
620 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
621 MultiStmtArg Statements,
622 SourceLocation RBraceLoc,
623 bool IsStmtExpr) {
624 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
625 IsStmtExpr);
626 }
627
628 /// \brief Build a new case statement.
629 ///
630 /// By default, performs semantic analysis to build the new statement.
631 /// Subclasses may override this routine to provide different behavior.
632 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
633 ExprArg LHS,
634 SourceLocation EllipsisLoc,
635 ExprArg RHS,
636 SourceLocation ColonLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000637 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregor43959a92009-08-20 07:17:43 +0000638 ColonLoc);
639 }
Mike Stump1eb44332009-09-09 15:08:12 +0000640
Douglas Gregor43959a92009-08-20 07:17:43 +0000641 /// \brief Attach the body to a new case statement.
642 ///
643 /// By default, performs semantic analysis to build the new statement.
644 /// Subclasses may override this routine to provide different behavior.
645 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
646 getSema().ActOnCaseStmtBody(S.get(), move(Body));
647 return move(S);
648 }
Mike Stump1eb44332009-09-09 15:08:12 +0000649
Douglas Gregor43959a92009-08-20 07:17:43 +0000650 /// \brief Build a new default statement.
651 ///
652 /// By default, performs semantic analysis to build the new statement.
653 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000654 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000655 SourceLocation ColonLoc,
656 StmtArg SubStmt) {
Mike Stump1eb44332009-09-09 15:08:12 +0000657 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregor43959a92009-08-20 07:17:43 +0000658 /*CurScope=*/0);
659 }
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor43959a92009-08-20 07:17:43 +0000661 /// \brief Build a new label statement.
662 ///
663 /// By default, performs semantic analysis to build the new statement.
664 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000665 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000666 IdentifierInfo *Id,
667 SourceLocation ColonLoc,
668 StmtArg SubStmt) {
669 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
670 }
Mike Stump1eb44332009-09-09 15:08:12 +0000671
Douglas Gregor43959a92009-08-20 07:17:43 +0000672 /// \brief Build a new "if" statement.
673 ///
674 /// By default, performs semantic analysis to build the new statement.
675 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000676 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000677 VarDecl *CondVar, StmtArg Then,
678 SourceLocation ElseLoc, StmtArg Else) {
679 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
680 move(Then), ElseLoc, move(Else));
Douglas Gregor43959a92009-08-20 07:17:43 +0000681 }
Mike Stump1eb44332009-09-09 15:08:12 +0000682
Douglas Gregor43959a92009-08-20 07:17:43 +0000683 /// \brief Start building a new switch statement.
684 ///
685 /// By default, performs semantic analysis to build the new statement.
686 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000687 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
688 VarDecl *CondVar) {
689 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregor43959a92009-08-20 07:17:43 +0000690 }
Mike Stump1eb44332009-09-09 15:08:12 +0000691
Douglas Gregor43959a92009-08-20 07:17:43 +0000692 /// \brief Attach the body to the switch statement.
693 ///
694 /// By default, performs semantic analysis to build the new statement.
695 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000696 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000697 StmtArg Switch, StmtArg Body) {
698 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
699 move(Body));
700 }
701
702 /// \brief Build a new while statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
706 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
707 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000708 VarDecl *CondVar,
Douglas Gregor43959a92009-08-20 07:17:43 +0000709 StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000710 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
711 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000712 }
Mike Stump1eb44332009-09-09 15:08:12 +0000713
Douglas Gregor43959a92009-08-20 07:17:43 +0000714 /// \brief Build a new do-while statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
719 SourceLocation WhileLoc,
720 SourceLocation LParenLoc,
721 ExprArg Cond,
722 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +0000723 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000724 move(Cond), RParenLoc);
725 }
726
727 /// \brief Build a new for statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000731 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000732 SourceLocation LParenLoc,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000733 StmtArg Init, Sema::FullExprArg Cond,
734 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000735 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000736 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
737 DeclPtrTy::make(CondVar),
738 Inc, RParenLoc, move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +0000739 }
Mike Stump1eb44332009-09-09 15:08:12 +0000740
Douglas Gregor43959a92009-08-20 07:17:43 +0000741 /// \brief Build a new goto statement.
742 ///
743 /// By default, performs semantic analysis to build the new statement.
744 /// Subclasses may override this routine to provide different behavior.
745 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
746 SourceLocation LabelLoc,
747 LabelStmt *Label) {
748 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
749 }
750
751 /// \brief Build a new indirect goto statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
755 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
756 SourceLocation StarLoc,
757 ExprArg Target) {
758 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
759 }
Mike Stump1eb44332009-09-09 15:08:12 +0000760
Douglas Gregor43959a92009-08-20 07:17:43 +0000761 /// \brief Build a new return statement.
762 ///
763 /// By default, performs semantic analysis to build the new statement.
764 /// Subclasses may override this routine to provide different behavior.
765 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
766 ExprArg Result) {
Mike Stump1eb44332009-09-09 15:08:12 +0000767
Douglas Gregor43959a92009-08-20 07:17:43 +0000768 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
769 }
Mike Stump1eb44332009-09-09 15:08:12 +0000770
Douglas Gregor43959a92009-08-20 07:17:43 +0000771 /// \brief Build a new declaration statement.
772 ///
773 /// By default, performs semantic analysis to build the new statement.
774 /// Subclasses may override this routine to provide different behavior.
775 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +0000776 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000777 SourceLocation EndLoc) {
778 return getSema().Owned(
779 new (getSema().Context) DeclStmt(
780 DeclGroupRef::Create(getSema().Context,
781 Decls, NumDecls),
782 StartLoc, EndLoc));
783 }
Mike Stump1eb44332009-09-09 15:08:12 +0000784
Anders Carlsson703e3942010-01-24 05:50:09 +0000785 /// \brief Build a new inline asm statement.
786 ///
787 /// By default, performs semantic analysis to build the new statement.
788 /// Subclasses may override this routine to provide different behavior.
789 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
790 bool IsSimple,
791 bool IsVolatile,
792 unsigned NumOutputs,
793 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000794 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +0000795 MultiExprArg Constraints,
796 MultiExprArg Exprs,
797 ExprArg AsmString,
798 MultiExprArg Clobbers,
799 SourceLocation RParenLoc,
800 bool MSAsm) {
801 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
802 NumInputs, Names, move(Constraints),
803 move(Exprs), move(AsmString), move(Clobbers),
804 RParenLoc, MSAsm);
805 }
806
Douglas Gregor43959a92009-08-20 07:17:43 +0000807 /// \brief Build a new C++ exception declaration.
808 ///
809 /// By default, performs semantic analysis to build the new decaration.
810 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000811 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCalla93c9342009-12-07 02:54:59 +0000812 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +0000813 IdentifierInfo *Name,
814 SourceLocation Loc,
815 SourceRange TypeRange) {
Mike Stump1eb44332009-09-09 15:08:12 +0000816 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000817 TypeRange);
818 }
819
820 /// \brief Build a new C++ catch statement.
821 ///
822 /// By default, performs semantic analysis to build the new statement.
823 /// Subclasses may override this routine to provide different behavior.
824 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
825 VarDecl *ExceptionDecl,
826 StmtArg Handler) {
827 return getSema().Owned(
Mike Stump1eb44332009-09-09 15:08:12 +0000828 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregor43959a92009-08-20 07:17:43 +0000829 Handler.takeAs<Stmt>()));
830 }
Mike Stump1eb44332009-09-09 15:08:12 +0000831
Douglas Gregor43959a92009-08-20 07:17:43 +0000832 /// \brief Build a new C++ try statement.
833 ///
834 /// By default, performs semantic analysis to build the new statement.
835 /// Subclasses may override this routine to provide different behavior.
836 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
837 StmtArg TryBlock,
838 MultiStmtArg Handlers) {
839 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
840 }
Mike Stump1eb44332009-09-09 15:08:12 +0000841
Douglas Gregorb98b1992009-08-11 05:31:07 +0000842 /// \brief Build a new expression that references a declaration.
843 ///
844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +0000846 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
847 LookupResult &R,
848 bool RequiresADL) {
849 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
850 }
851
852
853 /// \brief Build a new expression that references a declaration.
854 ///
855 /// By default, performs semantic analysis to build the new expression.
856 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora2813ce2009-10-23 18:54:35 +0000857 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
858 SourceRange QualifierRange,
John McCalldbd872f2009-12-08 09:08:17 +0000859 ValueDecl *VD, SourceLocation Loc,
860 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +0000861 CXXScopeSpec SS;
862 SS.setScopeRep(Qualifier);
863 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +0000864
865 // FIXME: loses template args.
866
867 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000868 }
Mike Stump1eb44332009-09-09 15:08:12 +0000869
Douglas Gregorb98b1992009-08-11 05:31:07 +0000870 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +0000871 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000872 /// By default, performs semantic analysis to build the new expression.
873 /// Subclasses may override this routine to provide different behavior.
874 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
875 SourceLocation RParen) {
876 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
877 }
878
Douglas Gregora71d8192009-09-04 17:36:40 +0000879 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000880 ///
Douglas Gregora71d8192009-09-04 17:36:40 +0000881 /// By default, performs semantic analysis to build the new expression.
882 /// Subclasses may override this routine to provide different behavior.
883 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
884 SourceLocation OperatorLoc,
885 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000886 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +0000887 SourceRange QualifierRange,
888 TypeSourceInfo *ScopeType,
889 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +0000890 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +0000891 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +0000892
Douglas Gregorb98b1992009-08-11 05:31:07 +0000893 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000894 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000895 /// By default, performs semantic analysis to build the new expression.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
898 UnaryOperator::Opcode Opc,
899 ExprArg SubExpr) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +0000900 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +0000901 }
Mike Stump1eb44332009-09-09 15:08:12 +0000902
Douglas Gregorb98b1992009-08-11 05:31:07 +0000903 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000904 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000905 /// By default, performs semantic analysis to build the new expression.
906 /// Subclasses may override this routine to provide different behavior.
John McCalla93c9342009-12-07 02:54:59 +0000907 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +0000908 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000909 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +0000910 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000911 }
912
Mike Stump1eb44332009-09-09 15:08:12 +0000913 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +0000914 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +0000915 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000916 /// By default, performs semantic analysis to build the new expression.
917 /// Subclasses may override this routine to provide different behavior.
918 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
919 bool isSizeOf, SourceRange R) {
Mike Stump1eb44332009-09-09 15:08:12 +0000920 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +0000921 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
922 OpLoc, isSizeOf, R);
923 if (Result.isInvalid())
924 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +0000925
Douglas Gregorb98b1992009-08-11 05:31:07 +0000926 SubExpr.release();
927 return move(Result);
928 }
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Douglas Gregorb98b1992009-08-11 05:31:07 +0000930 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000931 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000932 /// By default, performs semantic analysis to build the new expression.
933 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000934 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +0000935 SourceLocation LBracketLoc,
936 ExprArg RHS,
937 SourceLocation RBracketLoc) {
938 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump1eb44332009-09-09 15:08:12 +0000939 LBracketLoc, move(RHS),
Douglas Gregorb98b1992009-08-11 05:31:07 +0000940 RBracketLoc);
941 }
942
943 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000944 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
948 MultiExprArg Args,
949 SourceLocation *CommaLocs,
950 SourceLocation RParenLoc) {
951 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
952 move(Args), CommaLocs, RParenLoc);
953 }
954
955 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +0000956 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000957 /// By default, performs semantic analysis to build the new expression.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000960 bool isArrow,
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000961 NestedNameSpecifier *Qualifier,
962 SourceRange QualifierRange,
963 SourceLocation MemberLoc,
Eli Friedmanf595cc42009-12-04 06:40:45 +0000964 ValueDecl *Member,
John McCalld5532b62009-11-23 01:53:49 +0000965 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregor8a4386b2009-11-04 23:20:05 +0000966 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +0000967 if (!Member->getDeclName()) {
968 // We have a reference to an unnamed field.
969 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump1eb44332009-09-09 15:08:12 +0000970
Douglas Gregor83a56c42009-12-24 20:02:50 +0000971 Expr *BaseExpr = Base.takeAs<Expr>();
Douglas Gregor5fccd362010-03-03 23:55:11 +0000972 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member))
Douglas Gregor83a56c42009-12-24 20:02:50 +0000973 return getSema().ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +0000974
Mike Stump1eb44332009-09-09 15:08:12 +0000975 MemberExpr *ME =
Douglas Gregor83a56c42009-12-24 20:02:50 +0000976 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlssond8b285f2009-09-01 04:26:58 +0000977 Member, MemberLoc,
978 cast<FieldDecl>(Member)->getType());
979 return getSema().Owned(ME);
980 }
Mike Stump1eb44332009-09-09 15:08:12 +0000981
Douglas Gregor83f6faf2009-08-31 23:41:50 +0000982 CXXScopeSpec SS;
983 if (Qualifier) {
984 SS.setRange(QualifierRange);
985 SS.setScopeRep(Qualifier);
986 }
987
John McCallaa81e162009-12-01 22:10:20 +0000988 QualType BaseType = ((Expr*) Base.get())->getType();
989
John McCallc2233c52010-01-15 08:34:02 +0000990 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
991 Sema::LookupMemberName);
992 R.addDecl(Member);
993 R.resolveKind();
994
John McCallaa81e162009-12-01 22:10:20 +0000995 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
996 OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +0000997 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +0000998 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000999 }
Mike Stump1eb44332009-09-09 15:08:12 +00001000
Douglas Gregorb98b1992009-08-11 05:31:07 +00001001 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001002 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001003 /// By default, performs semantic analysis to build the new expression.
1004 /// Subclasses may override this routine to provide different behavior.
1005 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1006 BinaryOperator::Opcode Opc,
1007 ExprArg LHS, ExprArg RHS) {
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +00001008 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1009 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregorb98b1992009-08-11 05:31:07 +00001010 }
1011
1012 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001013 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001014 /// By default, performs semantic analysis to build the new expression.
1015 /// Subclasses may override this routine to provide different behavior.
1016 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1017 SourceLocation QuestionLoc,
1018 ExprArg LHS,
1019 SourceLocation ColonLoc,
1020 ExprArg RHS) {
Mike Stump1eb44332009-09-09 15:08:12 +00001021 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001022 move(LHS), move(RHS));
1023 }
1024
Douglas Gregorb98b1992009-08-11 05:31:07 +00001025 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001026 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall9d125032010-01-15 18:39:57 +00001029 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1030 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001031 SourceLocation RParenLoc,
1032 ExprArg SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001033 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1034 move(SubExpr));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001035 }
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Douglas Gregorb98b1992009-08-11 05:31:07 +00001037 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001038 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001042 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001043 SourceLocation RParenLoc,
1044 ExprArg Init) {
John McCall42f56b52010-01-18 19:35:47 +00001045 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1046 move(Init));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001047 }
Mike Stump1eb44332009-09-09 15:08:12 +00001048
Douglas Gregorb98b1992009-08-11 05:31:07 +00001049 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001050 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001051 /// By default, performs semantic analysis to build the new expression.
1052 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001053 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001054 SourceLocation OpLoc,
1055 SourceLocation AccessorLoc,
1056 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001057
John McCall129e2df2009-11-30 22:42:35 +00001058 CXXScopeSpec SS;
John McCallaa81e162009-12-01 22:10:20 +00001059 QualType BaseType = ((Expr*) Base.get())->getType();
1060 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001061 OpLoc, /*IsArrow*/ false,
1062 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor2d1c2142009-11-03 19:44:04 +00001063 DeclarationName(&Accessor),
John McCall129e2df2009-11-30 22:42:35 +00001064 AccessorLoc,
1065 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001066 }
Mike Stump1eb44332009-09-09 15:08:12 +00001067
Douglas Gregorb98b1992009-08-11 05:31:07 +00001068 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001069 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001070 /// By default, performs semantic analysis to build the new expression.
1071 /// Subclasses may override this routine to provide different behavior.
1072 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1073 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001074 SourceLocation RBraceLoc,
1075 QualType ResultTy) {
1076 OwningExprResult Result
1077 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1078 if (Result.isInvalid() || ResultTy->isDependentType())
1079 return move(Result);
1080
1081 // Patch in the result type we were given, which may have been computed
1082 // when the initial InitListExpr was built.
1083 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1084 ILE->setType(ResultTy);
1085 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001086 }
Mike Stump1eb44332009-09-09 15:08:12 +00001087
Douglas Gregorb98b1992009-08-11 05:31:07 +00001088 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001089 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001090 /// By default, performs semantic analysis to build the new expression.
1091 /// Subclasses may override this routine to provide different behavior.
1092 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1093 MultiExprArg ArrayExprs,
1094 SourceLocation EqualOrColonLoc,
1095 bool GNUSyntax,
1096 ExprArg Init) {
1097 OwningExprResult Result
1098 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1099 move(Init));
1100 if (Result.isInvalid())
1101 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregorb98b1992009-08-11 05:31:07 +00001103 ArrayExprs.release();
1104 return move(Result);
1105 }
Mike Stump1eb44332009-09-09 15:08:12 +00001106
Douglas Gregorb98b1992009-08-11 05:31:07 +00001107 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001108 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001109 /// By default, builds the implicit value initialization without performing
1110 /// any semantic analysis. Subclasses may override this routine to provide
1111 /// different behavior.
1112 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1113 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1114 }
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Douglas Gregorb98b1992009-08-11 05:31:07 +00001116 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001117 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001118 /// By default, performs semantic analysis to build the new expression.
1119 /// Subclasses may override this routine to provide different behavior.
1120 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1121 QualType T, SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001122 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001123 RParenLoc);
1124 }
1125
1126 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001127 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1131 MultiExprArg SubExprs,
1132 SourceLocation RParenLoc) {
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001133 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1134 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001135 }
Mike Stump1eb44332009-09-09 15:08:12 +00001136
Douglas Gregorb98b1992009-08-11 05:31:07 +00001137 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001138 ///
1139 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001140 /// rather than attempting to map the label statement itself.
1141 /// Subclasses may override this routine to provide different behavior.
1142 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1143 SourceLocation LabelLoc,
1144 LabelStmt *Label) {
1145 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1146 }
Mike Stump1eb44332009-09-09 15:08:12 +00001147
Douglas Gregorb98b1992009-08-11 05:31:07 +00001148 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001149 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001150 /// By default, performs semantic analysis to build the new expression.
1151 /// Subclasses may override this routine to provide different behavior.
1152 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1153 StmtArg SubStmt,
1154 SourceLocation RParenLoc) {
1155 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1156 }
Mike Stump1eb44332009-09-09 15:08:12 +00001157
Douglas Gregorb98b1992009-08-11 05:31:07 +00001158 /// \brief Build a new __builtin_types_compatible_p expression.
1159 ///
1160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1163 QualType T1, QualType T2,
1164 SourceLocation RParenLoc) {
1165 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1166 T1.getAsOpaquePtr(),
1167 T2.getAsOpaquePtr(),
1168 RParenLoc);
1169 }
Mike Stump1eb44332009-09-09 15:08:12 +00001170
Douglas Gregorb98b1992009-08-11 05:31:07 +00001171 /// \brief Build a new __builtin_choose_expr expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// Subclasses may override this routine to provide different behavior.
1175 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1176 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1177 SourceLocation RParenLoc) {
1178 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1179 move(Cond), move(LHS), move(RHS),
1180 RParenLoc);
1181 }
Mike Stump1eb44332009-09-09 15:08:12 +00001182
Douglas Gregorb98b1992009-08-11 05:31:07 +00001183 /// \brief Build a new overloaded operator call expression.
1184 ///
1185 /// By default, performs semantic analysis to build the new expression.
1186 /// The semantic analysis provides the behavior of template instantiation,
1187 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001188 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001189 /// argument-dependent lookup, etc. Subclasses may override this routine to
1190 /// provide different behavior.
1191 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1192 SourceLocation OpLoc,
1193 ExprArg Callee,
1194 ExprArg First,
1195 ExprArg Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001196
1197 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001198 /// reinterpret_cast.
1199 ///
1200 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001201 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001202 /// Subclasses may override this routine to provide different behavior.
1203 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1204 Stmt::StmtClass Class,
1205 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001206 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001207 SourceLocation RAngleLoc,
1208 SourceLocation LParenLoc,
1209 ExprArg SubExpr,
1210 SourceLocation RParenLoc) {
1211 switch (Class) {
1212 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001213 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001214 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 move(SubExpr), RParenLoc);
1216
1217 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001218 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001219 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001220 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001221
Douglas Gregorb98b1992009-08-11 05:31:07 +00001222 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001223 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001224 RAngleLoc, LParenLoc,
1225 move(SubExpr),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001226 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001227
Douglas Gregorb98b1992009-08-11 05:31:07 +00001228 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001229 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001230 RAngleLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001231 move(SubExpr), RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 default:
1234 assert(false && "Invalid C++ named cast");
1235 break;
1236 }
Mike Stump1eb44332009-09-09 15:08:12 +00001237
Douglas Gregorb98b1992009-08-11 05:31:07 +00001238 return getSema().ExprError();
1239 }
Mike Stump1eb44332009-09-09 15:08:12 +00001240
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 /// \brief Build a new C++ static_cast expression.
1242 ///
1243 /// By default, performs semantic analysis to build the new expression.
1244 /// Subclasses may override this routine to provide different behavior.
1245 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1246 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001247 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001248 SourceLocation RAngleLoc,
1249 SourceLocation LParenLoc,
1250 ExprArg SubExpr,
1251 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001252 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1253 TInfo, move(SubExpr),
1254 SourceRange(LAngleLoc, RAngleLoc),
1255 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 }
1257
1258 /// \brief Build a new C++ dynamic_cast expression.
1259 ///
1260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
1262 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1263 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001264 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001265 SourceLocation RAngleLoc,
1266 SourceLocation LParenLoc,
1267 ExprArg SubExpr,
1268 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001269 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1270 TInfo, move(SubExpr),
1271 SourceRange(LAngleLoc, RAngleLoc),
1272 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001273 }
1274
1275 /// \brief Build a new C++ reinterpret_cast expression.
1276 ///
1277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
1279 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1280 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001281 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001282 SourceLocation RAngleLoc,
1283 SourceLocation LParenLoc,
1284 ExprArg SubExpr,
1285 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001286 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1287 TInfo, move(SubExpr),
1288 SourceRange(LAngleLoc, RAngleLoc),
1289 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001290 }
1291
1292 /// \brief Build a new C++ const_cast expression.
1293 ///
1294 /// By default, performs semantic analysis to build the new expression.
1295 /// Subclasses may override this routine to provide different behavior.
1296 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1297 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001298 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 SourceLocation RAngleLoc,
1300 SourceLocation LParenLoc,
1301 ExprArg SubExpr,
1302 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001303 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1304 TInfo, move(SubExpr),
1305 SourceRange(LAngleLoc, RAngleLoc),
1306 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 }
Mike Stump1eb44332009-09-09 15:08:12 +00001308
Douglas Gregorb98b1992009-08-11 05:31:07 +00001309 /// \brief Build a new C++ functional-style cast expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001314 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
Chris Lattner88650c32009-08-24 05:19:01 +00001318 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001319 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall9d125032010-01-15 18:39:57 +00001320 TInfo->getType().getAsOpaquePtr(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 LParenLoc,
Chris Lattner88650c32009-08-24 05:19:01 +00001322 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump1eb44332009-09-09 15:08:12 +00001323 /*CommaLocs=*/0,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 RParenLoc);
1325 }
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// \brief Build a new C++ typeid(type) expression.
1328 ///
1329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
1331 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1332 SourceLocation LParenLoc,
1333 QualType T,
1334 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001335 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 T.getAsOpaquePtr(), RParenLoc);
1337 }
Mike Stump1eb44332009-09-09 15:08:12 +00001338
Douglas Gregorb98b1992009-08-11 05:31:07 +00001339 /// \brief Build a new C++ typeid(expr) expression.
1340 ///
1341 /// By default, performs semantic analysis to build the new expression.
1342 /// Subclasses may override this routine to provide different behavior.
1343 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1344 SourceLocation LParenLoc,
1345 ExprArg Operand,
1346 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001347 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1349 RParenLoc);
1350 if (Result.isInvalid())
1351 return getSema().ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001352
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1354 return move(Result);
Mike Stump1eb44332009-09-09 15:08:12 +00001355 }
1356
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 /// \brief Build a new C++ "this" expression.
1358 ///
1359 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001360 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001362 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor828a1972010-01-07 23:12:05 +00001363 QualType ThisType,
1364 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001366 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1367 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 }
1369
1370 /// \brief Build a new C++ throw expression.
1371 ///
1372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
1374 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1375 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1376 }
1377
1378 /// \brief Build a new C++ default-argument expression.
1379 ///
1380 /// By default, builds a new default-argument expression, which does not
1381 /// require any semantic analysis. Subclasses may override this routine to
1382 /// provide different behavior.
Douglas Gregor036aed12009-12-23 23:03:06 +00001383 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1384 ParmVarDecl *Param) {
1385 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1386 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 }
1388
1389 /// \brief Build a new C++ zero-initialization expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001393 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 SourceLocation LParenLoc,
1395 QualType T,
1396 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001397 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1398 T.getAsOpaquePtr(), LParenLoc,
1399 MultiExprArg(getSema(), 0, 0),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 0, RParenLoc);
1401 }
Mike Stump1eb44332009-09-09 15:08:12 +00001402
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 /// \brief Build a new C++ "new" expression.
1404 ///
1405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +00001407 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 bool UseGlobal,
1409 SourceLocation PlacementLParen,
1410 MultiExprArg PlacementArgs,
1411 SourceLocation PlacementRParen,
Mike Stump1eb44332009-09-09 15:08:12 +00001412 bool ParenTypeId,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001413 QualType AllocType,
1414 SourceLocation TypeLoc,
1415 SourceRange TypeRange,
1416 ExprArg ArraySize,
1417 SourceLocation ConstructorLParen,
1418 MultiExprArg ConstructorArgs,
1419 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001420 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 PlacementLParen,
1422 move(PlacementArgs),
1423 PlacementRParen,
1424 ParenTypeId,
1425 AllocType,
1426 TypeLoc,
1427 TypeRange,
1428 move(ArraySize),
1429 ConstructorLParen,
1430 move(ConstructorArgs),
1431 ConstructorRParen);
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new C++ "delete" expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1439 bool IsGlobalDelete,
1440 bool IsArrayForm,
1441 ExprArg Operand) {
1442 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1443 move(Operand));
1444 }
Mike Stump1eb44332009-09-09 15:08:12 +00001445
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 /// \brief Build a new unary type trait expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1451 SourceLocation StartLoc,
1452 SourceLocation LParenLoc,
1453 QualType T,
1454 SourceLocation RParenLoc) {
Mike Stump1eb44332009-09-09 15:08:12 +00001455 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 T.getAsOpaquePtr(), RParenLoc);
1457 }
1458
Mike Stump1eb44332009-09-09 15:08:12 +00001459 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001460 /// expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001464 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 SourceRange QualifierRange,
1466 DeclarationName Name,
1467 SourceLocation Location,
John McCallf7a1a742009-11-24 19:00:30 +00001468 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 CXXScopeSpec SS;
1470 SS.setRange(QualifierRange);
1471 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001472
1473 if (TemplateArgs)
1474 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1475 *TemplateArgs);
1476
1477 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
1479
1480 /// \brief Build a new template-id expression.
1481 ///
1482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCallf7a1a742009-11-24 19:00:30 +00001484 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1485 LookupResult &R,
1486 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001487 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001488 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new object-construction expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001496 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001497 CXXConstructorDecl *Constructor,
1498 bool IsElidable,
1499 MultiExprArg Args) {
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001500 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1501 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1502 ConvertedArgs))
1503 return getSema().ExprError();
1504
1505 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1506 move_arg(ConvertedArgs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 }
1508
1509 /// \brief Build a new object-construction expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
1513 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1514 QualType T,
1515 SourceLocation LParenLoc,
1516 MultiExprArg Args,
1517 SourceLocation *Commas,
1518 SourceLocation RParenLoc) {
1519 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1520 T.getAsOpaquePtr(),
1521 LParenLoc,
1522 move(Args),
1523 Commas,
1524 RParenLoc);
1525 }
1526
1527 /// \brief Build a new object-construction expression.
1528 ///
1529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
1531 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1532 QualType T,
1533 SourceLocation LParenLoc,
1534 MultiExprArg Args,
1535 SourceLocation *Commas,
1536 SourceLocation RParenLoc) {
1537 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1538 /*FIXME*/LParenLoc),
1539 T.getAsOpaquePtr(),
1540 LParenLoc,
1541 move(Args),
1542 Commas,
1543 RParenLoc);
1544 }
Mike Stump1eb44332009-09-09 15:08:12 +00001545
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 /// \brief Build a new member reference expression.
1547 ///
1548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCall865d4472009-11-19 22:55:06 +00001550 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001551 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 bool IsArrow,
1553 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001554 NestedNameSpecifier *Qualifier,
1555 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001556 NamedDecl *FirstQualifierInScope,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001557 DeclarationName Name,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001558 SourceLocation MemberLoc,
John McCall129e2df2009-11-30 22:42:35 +00001559 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001560 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001561 SS.setRange(QualifierRange);
1562 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001563
John McCallaa81e162009-12-01 22:10:20 +00001564 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1565 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001566 SS, FirstQualifierInScope,
1567 Name, MemberLoc, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001568 }
1569
John McCall129e2df2009-11-30 22:42:35 +00001570 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001571 ///
1572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
John McCall129e2df2009-11-30 22:42:35 +00001574 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001575 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001576 SourceLocation OperatorLoc,
1577 bool IsArrow,
1578 NestedNameSpecifier *Qualifier,
1579 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001580 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001581 LookupResult &R,
1582 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001583 CXXScopeSpec SS;
1584 SS.setRange(QualifierRange);
1585 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001586
John McCallaa81e162009-12-01 22:10:20 +00001587 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1588 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001589 SS, FirstQualifierInScope,
1590 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001591 }
Mike Stump1eb44332009-09-09 15:08:12 +00001592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new Objective-C @encode expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
1597 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1598 QualType T,
1599 SourceLocation RParenLoc) {
1600 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1601 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001602 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603
1604 /// \brief Build a new Objective-C protocol expression.
1605 ///
1606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
1608 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1609 SourceLocation AtLoc,
1610 SourceLocation ProtoLoc,
1611 SourceLocation LParenLoc,
1612 SourceLocation RParenLoc) {
1613 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1614 Protocol->getIdentifier(),
1615 AtLoc,
1616 ProtoLoc,
1617 LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001618 RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 }
Mike Stump1eb44332009-09-09 15:08:12 +00001620
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 /// \brief Build a new shuffle vector expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1626 MultiExprArg SubExprs,
1627 SourceLocation RParenLoc) {
1628 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00001629 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1631 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1632 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1633 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00001634
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 // Build a reference to the __builtin_shufflevector builtin
1636 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00001637 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregor0da76df2009-11-23 11:41:28 +00001639 BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001640 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00001641
1642 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 unsigned NumSubExprs = SubExprs.size();
1644 Expr **Subs = (Expr **)SubExprs.release();
1645 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1646 Subs, NumSubExprs,
1647 Builtin->getResultType(),
1648 RParenLoc);
1649 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00001650
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 // Type-check the __builtin_shufflevector expression.
1652 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1653 if (Result.isInvalid())
1654 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001655
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00001657 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00001659};
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660
Douglas Gregor43959a92009-08-20 07:17:43 +00001661template<typename Derived>
1662Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1663 if (!S)
1664 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00001665
Douglas Gregor43959a92009-08-20 07:17:43 +00001666 switch (S->getStmtClass()) {
1667 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00001668
Douglas Gregor43959a92009-08-20 07:17:43 +00001669 // Transform individual statement nodes
1670#define STMT(Node, Parent) \
1671 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1672#define EXPR(Node, Parent)
1673#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregor43959a92009-08-20 07:17:43 +00001675 // Transform expressions by calling TransformExpr.
1676#define STMT(Node, Parent)
John McCall09cc1412010-02-03 00:55:45 +00001677#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregor43959a92009-08-20 07:17:43 +00001678#define EXPR(Node, Parent) case Stmt::Node##Class:
1679#include "clang/AST/StmtNodes.def"
1680 {
1681 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1682 if (E.isInvalid())
1683 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00001684
Anders Carlsson5ee56e92009-12-16 02:09:40 +00001685 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregor43959a92009-08-20 07:17:43 +00001686 }
Mike Stump1eb44332009-09-09 15:08:12 +00001687 }
1688
Douglas Gregor43959a92009-08-20 07:17:43 +00001689 return SemaRef.Owned(S->Retain());
1690}
Mike Stump1eb44332009-09-09 15:08:12 +00001691
1692
Douglas Gregor670444e2009-08-04 22:27:00 +00001693template<typename Derived>
John McCall454feb92009-12-08 09:21:05 +00001694Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 if (!E)
1696 return SemaRef.Owned(E);
1697
1698 switch (E->getStmtClass()) {
1699 case Stmt::NoStmtClass: break;
1700#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall09cc1412010-02-03 00:55:45 +00001701#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00001703 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704#include "clang/AST/StmtNodes.def"
Mike Stump1eb44332009-09-09 15:08:12 +00001705 }
1706
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 return SemaRef.Owned(E->Retain());
Douglas Gregor657c1ac2009-08-06 22:17:10 +00001708}
1709
1710template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00001711NestedNameSpecifier *
1712TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00001713 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001714 QualType ObjectType,
1715 NamedDecl *FirstQualifierInScope) {
Douglas Gregor0979c802009-08-31 21:41:48 +00001716 if (!NNS)
1717 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001718
Douglas Gregor43959a92009-08-20 07:17:43 +00001719 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00001720 NestedNameSpecifier *Prefix = NNS->getPrefix();
1721 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00001722 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00001723 ObjectType,
1724 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001725 if (!Prefix)
1726 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001727
1728 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregorc68afe22009-09-03 21:38:09 +00001729 // apply to the first element in the nested-name-specifier.
Douglas Gregora38c6872009-09-03 16:14:30 +00001730 ObjectType = QualType();
Douglas Gregorc68afe22009-09-03 21:38:09 +00001731 FirstQualifierInScope = 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001732 }
Mike Stump1eb44332009-09-09 15:08:12 +00001733
Douglas Gregordcee1a12009-08-06 05:28:30 +00001734 switch (NNS->getKind()) {
1735 case NestedNameSpecifier::Identifier:
Mike Stump1eb44332009-09-09 15:08:12 +00001736 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00001737 "Identifier nested-name-specifier with no prefix or object type");
1738 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1739 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00001740 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001741
1742 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00001743 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00001744 ObjectType,
1745 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00001746
Douglas Gregordcee1a12009-08-06 05:28:30 +00001747 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00001748 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00001749 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001750 getDerived().TransformDecl(Range.getBegin(),
1751 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00001752 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00001753 Prefix == NNS->getPrefix() &&
1754 NS == NNS->getAsNamespace())
1755 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001756
Douglas Gregordcee1a12009-08-06 05:28:30 +00001757 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1758 }
Mike Stump1eb44332009-09-09 15:08:12 +00001759
Douglas Gregordcee1a12009-08-06 05:28:30 +00001760 case NestedNameSpecifier::Global:
1761 // There is no meaningful transformation that one could perform on the
1762 // global scope.
1763 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001764
Douglas Gregordcee1a12009-08-06 05:28:30 +00001765 case NestedNameSpecifier::TypeSpecWithTemplate:
1766 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00001767 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor124b8782010-02-16 19:09:40 +00001768 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1769 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001770 if (T.isNull())
1771 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00001772
Douglas Gregordcee1a12009-08-06 05:28:30 +00001773 if (!getDerived().AlwaysRebuild() &&
1774 Prefix == NNS->getPrefix() &&
1775 T == QualType(NNS->getAsType(), 0))
1776 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00001777
1778 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1779 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00001780 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00001781 }
1782 }
Mike Stump1eb44332009-09-09 15:08:12 +00001783
Douglas Gregordcee1a12009-08-06 05:28:30 +00001784 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00001785 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00001786}
1787
1788template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001789DeclarationName
Douglas Gregor81499bb2009-09-03 22:13:48 +00001790TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregordd62b152009-10-19 22:04:39 +00001791 SourceLocation Loc,
1792 QualType ObjectType) {
Douglas Gregor81499bb2009-09-03 22:13:48 +00001793 if (!Name)
1794 return Name;
1795
1796 switch (Name.getNameKind()) {
1797 case DeclarationName::Identifier:
1798 case DeclarationName::ObjCZeroArgSelector:
1799 case DeclarationName::ObjCOneArgSelector:
1800 case DeclarationName::ObjCMultiArgSelector:
1801 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00001802 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00001803 case DeclarationName::CXXUsingDirective:
1804 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001805
Douglas Gregor81499bb2009-09-03 22:13:48 +00001806 case DeclarationName::CXXConstructorName:
1807 case DeclarationName::CXXDestructorName:
1808 case DeclarationName::CXXConversionFunctionName: {
1809 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregor124b8782010-02-16 19:09:40 +00001810 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1811 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00001812 if (T.isNull())
1813 return DeclarationName();
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Douglas Gregor81499bb2009-09-03 22:13:48 +00001815 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump1eb44332009-09-09 15:08:12 +00001816 Name.getNameKind(),
Douglas Gregor81499bb2009-09-03 22:13:48 +00001817 SemaRef.Context.getCanonicalType(T));
Douglas Gregor81499bb2009-09-03 22:13:48 +00001818 }
Mike Stump1eb44332009-09-09 15:08:12 +00001819 }
1820
Douglas Gregor81499bb2009-09-03 22:13:48 +00001821 return DeclarationName();
1822}
1823
1824template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00001825TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001826TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1827 QualType ObjectType) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001828 SourceLocation Loc = getDerived().getBaseLocation();
1829
Douglas Gregord1067e52009-08-06 06:41:21 +00001830 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001831 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001832 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001833 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1834 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001835 if (!NNS)
1836 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001837
Douglas Gregord1067e52009-08-06 06:41:21 +00001838 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001839 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001840 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001841 if (!TransTemplate)
1842 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001843
Douglas Gregord1067e52009-08-06 06:41:21 +00001844 if (!getDerived().AlwaysRebuild() &&
1845 NNS == QTN->getQualifier() &&
1846 TransTemplate == Template)
1847 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001848
Douglas Gregord1067e52009-08-06 06:41:21 +00001849 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1850 TransTemplate);
1851 }
Mike Stump1eb44332009-09-09 15:08:12 +00001852
John McCallf7a1a742009-11-24 19:00:30 +00001853 // These should be getting filtered out before they make it into the AST.
1854 assert(false && "overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00001855 }
Mike Stump1eb44332009-09-09 15:08:12 +00001856
Douglas Gregord1067e52009-08-06 06:41:21 +00001857 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001858 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00001859 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00001860 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1861 ObjectType);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001862 if (!NNS && DTN->getQualifier())
Douglas Gregord1067e52009-08-06 06:41:21 +00001863 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001864
Douglas Gregord1067e52009-08-06 06:41:21 +00001865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00001866 NNS == DTN->getQualifier() &&
1867 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00001868 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001869
Douglas Gregorca1bdd72009-11-04 00:56:37 +00001870 if (DTN->isIdentifier())
1871 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1872 ObjectType);
1873
1874 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1875 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00001876 }
Mike Stump1eb44332009-09-09 15:08:12 +00001877
Douglas Gregord1067e52009-08-06 06:41:21 +00001878 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001879 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001880 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00001881 if (!TransTemplate)
1882 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00001883
Douglas Gregord1067e52009-08-06 06:41:21 +00001884 if (!getDerived().AlwaysRebuild() &&
1885 TransTemplate == Template)
1886 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00001887
Douglas Gregord1067e52009-08-06 06:41:21 +00001888 return TemplateName(TransTemplate);
1889 }
Mike Stump1eb44332009-09-09 15:08:12 +00001890
John McCallf7a1a742009-11-24 19:00:30 +00001891 // These should be getting filtered out before they reach the AST.
1892 assert(false && "overloaded function decl survived to here");
1893 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00001894}
1895
1896template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00001897void TreeTransform<Derived>::InventTemplateArgumentLoc(
1898 const TemplateArgument &Arg,
1899 TemplateArgumentLoc &Output) {
1900 SourceLocation Loc = getDerived().getBaseLocation();
1901 switch (Arg.getKind()) {
1902 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00001903 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00001904 break;
1905
1906 case TemplateArgument::Type:
1907 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00001908 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall833ca992009-10-29 08:12:44 +00001909
1910 break;
1911
Douglas Gregor788cd062009-11-11 01:00:40 +00001912 case TemplateArgument::Template:
1913 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1914 break;
1915
John McCall833ca992009-10-29 08:12:44 +00001916 case TemplateArgument::Expression:
1917 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1918 break;
1919
1920 case TemplateArgument::Declaration:
1921 case TemplateArgument::Integral:
1922 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00001923 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00001924 break;
1925 }
1926}
1927
1928template<typename Derived>
1929bool TreeTransform<Derived>::TransformTemplateArgument(
1930 const TemplateArgumentLoc &Input,
1931 TemplateArgumentLoc &Output) {
1932 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00001933 switch (Arg.getKind()) {
1934 case TemplateArgument::Null:
1935 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00001936 Output = Input;
1937 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001938
Douglas Gregor670444e2009-08-04 22:27:00 +00001939 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00001940 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00001941 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00001942 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00001943
1944 DI = getDerived().TransformType(DI);
1945 if (!DI) return true;
1946
1947 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1948 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001949 }
Mike Stump1eb44332009-09-09 15:08:12 +00001950
Douglas Gregor670444e2009-08-04 22:27:00 +00001951 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00001952 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00001953 DeclarationName Name;
1954 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1955 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00001956 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00001957 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00001958 if (!D) return true;
1959
John McCall828bff22009-10-29 18:45:58 +00001960 Expr *SourceExpr = Input.getSourceDeclExpression();
1961 if (SourceExpr) {
1962 EnterExpressionEvaluationContext Unevaluated(getSema(),
1963 Action::Unevaluated);
1964 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1965 if (E.isInvalid())
1966 SourceExpr = NULL;
1967 else {
1968 SourceExpr = E.takeAs<Expr>();
1969 SourceExpr->Retain();
1970 }
1971 }
1972
1973 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00001974 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregor788cd062009-11-11 01:00:40 +00001977 case TemplateArgument::Template: {
1978 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1979 TemplateName Template
1980 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1981 if (Template.isNull())
1982 return true;
1983
1984 Output = TemplateArgumentLoc(TemplateArgument(Template),
1985 Input.getTemplateQualifierRange(),
1986 Input.getTemplateNameLoc());
1987 return false;
1988 }
1989
Douglas Gregor670444e2009-08-04 22:27:00 +00001990 case TemplateArgument::Expression: {
1991 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00001992 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregor670444e2009-08-04 22:27:00 +00001993 Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00001994
John McCall833ca992009-10-29 08:12:44 +00001995 Expr *InputExpr = Input.getSourceExpression();
1996 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1997
1998 Sema::OwningExprResult E
1999 = getDerived().TransformExpr(InputExpr);
2000 if (E.isInvalid()) return true;
2001
2002 Expr *ETaken = E.takeAs<Expr>();
John McCall828bff22009-10-29 18:45:58 +00002003 ETaken->Retain();
John McCall833ca992009-10-29 08:12:44 +00002004 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2005 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002006 }
Mike Stump1eb44332009-09-09 15:08:12 +00002007
Douglas Gregor670444e2009-08-04 22:27:00 +00002008 case TemplateArgument::Pack: {
2009 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2010 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002011 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002012 AEnd = Arg.pack_end();
2013 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002014
John McCall833ca992009-10-29 08:12:44 +00002015 // FIXME: preserve source information here when we start
2016 // caring about parameter packs.
2017
John McCall828bff22009-10-29 18:45:58 +00002018 TemplateArgumentLoc InputArg;
2019 TemplateArgumentLoc OutputArg;
2020 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2021 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002022 return true;
2023
John McCall828bff22009-10-29 18:45:58 +00002024 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002025 }
2026 TemplateArgument Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002027 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002028 true);
John McCall828bff22009-10-29 18:45:58 +00002029 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002030 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002031 }
2032 }
Mike Stump1eb44332009-09-09 15:08:12 +00002033
Douglas Gregor670444e2009-08-04 22:27:00 +00002034 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002035 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002036}
2037
Douglas Gregor577f75a2009-08-04 16:50:30 +00002038//===----------------------------------------------------------------------===//
2039// Type transformation
2040//===----------------------------------------------------------------------===//
2041
2042template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002043QualType TreeTransform<Derived>::TransformType(QualType T,
2044 QualType ObjectType) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002045 if (getDerived().AlreadyTransformed(T))
2046 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002047
John McCalla2becad2009-10-21 00:40:46 +00002048 // Temporary workaround. All of these transformations should
2049 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002050 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002051 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCalla2becad2009-10-21 00:40:46 +00002052
Douglas Gregor124b8782010-02-16 19:09:40 +00002053 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall0953e762009-09-24 19:53:00 +00002054
John McCalla2becad2009-10-21 00:40:46 +00002055 if (!NewDI)
2056 return QualType();
2057
2058 return NewDI->getType();
2059}
2060
2061template<typename Derived>
Douglas Gregor124b8782010-02-16 19:09:40 +00002062TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2063 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002064 if (getDerived().AlreadyTransformed(DI->getType()))
2065 return DI;
2066
2067 TypeLocBuilder TLB;
2068
2069 TypeLoc TL = DI->getTypeLoc();
2070 TLB.reserve(TL.getFullDataSize());
2071
Douglas Gregor124b8782010-02-16 19:09:40 +00002072 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002073 if (Result.isNull())
2074 return 0;
2075
John McCalla93c9342009-12-07 02:54:59 +00002076 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002077}
2078
2079template<typename Derived>
2080QualType
Douglas Gregor124b8782010-02-16 19:09:40 +00002081TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2082 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002083 switch (T.getTypeLocClass()) {
2084#define ABSTRACT_TYPELOC(CLASS, PARENT)
2085#define TYPELOC(CLASS, PARENT) \
2086 case TypeLoc::CLASS: \
Douglas Gregor124b8782010-02-16 19:09:40 +00002087 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2088 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002089#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002090 }
Mike Stump1eb44332009-09-09 15:08:12 +00002091
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002092 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002093 return QualType();
2094}
2095
2096/// FIXME: By default, this routine adds type qualifiers only to types
2097/// that can have qualifiers, and silently suppresses those qualifiers
2098/// that are not permitted (e.g., qualifiers on reference or function
2099/// types). This is the right thing for template instantiation, but
2100/// probably not for other clients.
2101template<typename Derived>
2102QualType
2103TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002104 QualifiedTypeLoc T,
2105 QualType ObjectType) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002106 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002107
Douglas Gregor124b8782010-02-16 19:09:40 +00002108 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2109 ObjectType);
John McCalla2becad2009-10-21 00:40:46 +00002110 if (Result.isNull())
2111 return QualType();
2112
2113 // Silently suppress qualifiers if the result type can't be qualified.
2114 // FIXME: this is the right thing for template instantiation, but
2115 // probably not for other clients.
2116 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002117 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002118
John McCalla2becad2009-10-21 00:40:46 +00002119 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2120
2121 TLB.push<QualifiedTypeLoc>(Result);
2122
2123 // No location information to preserve.
2124
2125 return Result;
2126}
2127
2128template <class TyLoc> static inline
2129QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2130 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2131 NewT.setNameLoc(T.getNameLoc());
2132 return T.getType();
2133}
2134
2135// Ugly metaprogramming macros because I couldn't be bothered to make
2136// the equivalent template version work.
2137#define TransformPointerLikeType(TypeClass) do { \
2138 QualType PointeeType \
2139 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2140 if (PointeeType.isNull()) \
2141 return QualType(); \
2142 \
2143 QualType Result = TL.getType(); \
2144 if (getDerived().AlwaysRebuild() || \
2145 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall85737a72009-10-30 00:06:24 +00002146 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2147 TL.getSigilLoc()); \
John McCalla2becad2009-10-21 00:40:46 +00002148 if (Result.isNull()) \
2149 return QualType(); \
2150 } \
2151 \
2152 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2153 NewT.setSigilLoc(TL.getSigilLoc()); \
2154 \
2155 return Result; \
2156} while(0)
2157
John McCalla2becad2009-10-21 00:40:46 +00002158template<typename Derived>
2159QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002160 BuiltinTypeLoc T,
2161 QualType ObjectType) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00002162 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2163 NewT.setBuiltinLoc(T.getBuiltinLoc());
2164 if (T.needsExtraLocalData())
2165 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2166 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002167}
Mike Stump1eb44332009-09-09 15:08:12 +00002168
Douglas Gregor577f75a2009-08-04 16:50:30 +00002169template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002170QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002171 ComplexTypeLoc T,
2172 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002173 // FIXME: recurse?
2174 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002175}
Mike Stump1eb44332009-09-09 15:08:12 +00002176
Douglas Gregor577f75a2009-08-04 16:50:30 +00002177template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002178QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002179 PointerTypeLoc TL,
2180 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002181 TransformPointerLikeType(PointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002182}
Mike Stump1eb44332009-09-09 15:08:12 +00002183
2184template<typename Derived>
2185QualType
John McCalla2becad2009-10-21 00:40:46 +00002186TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002187 BlockPointerTypeLoc TL,
2188 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002189 TransformPointerLikeType(BlockPointerType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002190}
2191
John McCall85737a72009-10-30 00:06:24 +00002192/// Transforms a reference type. Note that somewhat paradoxically we
2193/// don't care whether the type itself is an l-value type or an r-value
2194/// type; we only care if the type was *written* as an l-value type
2195/// or an r-value type.
2196template<typename Derived>
2197QualType
2198TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002199 ReferenceTypeLoc TL,
2200 QualType ObjectType) {
John McCall85737a72009-10-30 00:06:24 +00002201 const ReferenceType *T = TL.getTypePtr();
2202
2203 // Note that this works with the pointee-as-written.
2204 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2205 if (PointeeType.isNull())
2206 return QualType();
2207
2208 QualType Result = TL.getType();
2209 if (getDerived().AlwaysRebuild() ||
2210 PointeeType != T->getPointeeTypeAsWritten()) {
2211 Result = getDerived().RebuildReferenceType(PointeeType,
2212 T->isSpelledAsLValue(),
2213 TL.getSigilLoc());
2214 if (Result.isNull())
2215 return QualType();
2216 }
2217
2218 // r-value references can be rebuilt as l-value references.
2219 ReferenceTypeLoc NewTL;
2220 if (isa<LValueReferenceType>(Result))
2221 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2222 else
2223 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2224 NewTL.setSigilLoc(TL.getSigilLoc());
2225
2226 return Result;
2227}
2228
Mike Stump1eb44332009-09-09 15:08:12 +00002229template<typename Derived>
2230QualType
John McCalla2becad2009-10-21 00:40:46 +00002231TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002232 LValueReferenceTypeLoc TL,
2233 QualType ObjectType) {
2234 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002235}
2236
Mike Stump1eb44332009-09-09 15:08:12 +00002237template<typename Derived>
2238QualType
John McCalla2becad2009-10-21 00:40:46 +00002239TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002240 RValueReferenceTypeLoc TL,
2241 QualType ObjectType) {
2242 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002243}
Mike Stump1eb44332009-09-09 15:08:12 +00002244
Douglas Gregor577f75a2009-08-04 16:50:30 +00002245template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002246QualType
John McCalla2becad2009-10-21 00:40:46 +00002247TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002248 MemberPointerTypeLoc TL,
2249 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002250 MemberPointerType *T = TL.getTypePtr();
2251
2252 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002253 if (PointeeType.isNull())
2254 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002255
John McCalla2becad2009-10-21 00:40:46 +00002256 // TODO: preserve source information for this.
2257 QualType ClassType
2258 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002259 if (ClassType.isNull())
2260 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002261
John McCalla2becad2009-10-21 00:40:46 +00002262 QualType Result = TL.getType();
2263 if (getDerived().AlwaysRebuild() ||
2264 PointeeType != T->getPointeeType() ||
2265 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00002266 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2267 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00002268 if (Result.isNull())
2269 return QualType();
2270 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002271
John McCalla2becad2009-10-21 00:40:46 +00002272 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2273 NewTL.setSigilLoc(TL.getSigilLoc());
2274
2275 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002276}
2277
Mike Stump1eb44332009-09-09 15:08:12 +00002278template<typename Derived>
2279QualType
John McCalla2becad2009-10-21 00:40:46 +00002280TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002281 ConstantArrayTypeLoc TL,
2282 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002283 ConstantArrayType *T = TL.getTypePtr();
2284 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002285 if (ElementType.isNull())
2286 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002287
John McCalla2becad2009-10-21 00:40:46 +00002288 QualType Result = TL.getType();
2289 if (getDerived().AlwaysRebuild() ||
2290 ElementType != T->getElementType()) {
2291 Result = getDerived().RebuildConstantArrayType(ElementType,
2292 T->getSizeModifier(),
2293 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00002294 T->getIndexTypeCVRQualifiers(),
2295 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002296 if (Result.isNull())
2297 return QualType();
2298 }
2299
2300 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2301 NewTL.setLBracketLoc(TL.getLBracketLoc());
2302 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002303
John McCalla2becad2009-10-21 00:40:46 +00002304 Expr *Size = TL.getSizeExpr();
2305 if (Size) {
2306 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2307 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2308 }
2309 NewTL.setSizeExpr(Size);
2310
2311 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002312}
Mike Stump1eb44332009-09-09 15:08:12 +00002313
Douglas Gregor577f75a2009-08-04 16:50:30 +00002314template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002315QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00002316 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002317 IncompleteArrayTypeLoc TL,
2318 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002319 IncompleteArrayType *T = TL.getTypePtr();
2320 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002321 if (ElementType.isNull())
2322 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002323
John McCalla2becad2009-10-21 00:40:46 +00002324 QualType Result = TL.getType();
2325 if (getDerived().AlwaysRebuild() ||
2326 ElementType != T->getElementType()) {
2327 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002328 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00002329 T->getIndexTypeCVRQualifiers(),
2330 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002331 if (Result.isNull())
2332 return QualType();
2333 }
2334
2335 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2336 NewTL.setLBracketLoc(TL.getLBracketLoc());
2337 NewTL.setRBracketLoc(TL.getRBracketLoc());
2338 NewTL.setSizeExpr(0);
2339
2340 return Result;
2341}
2342
2343template<typename Derived>
2344QualType
2345TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002346 VariableArrayTypeLoc TL,
2347 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002348 VariableArrayType *T = TL.getTypePtr();
2349 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2350 if (ElementType.isNull())
2351 return QualType();
2352
2353 // Array bounds are not potentially evaluated contexts
2354 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2355
2356 Sema::OwningExprResult SizeResult
2357 = getDerived().TransformExpr(T->getSizeExpr());
2358 if (SizeResult.isInvalid())
2359 return QualType();
2360
2361 Expr *Size = static_cast<Expr*>(SizeResult.get());
2362
2363 QualType Result = TL.getType();
2364 if (getDerived().AlwaysRebuild() ||
2365 ElementType != T->getElementType() ||
2366 Size != T->getSizeExpr()) {
2367 Result = getDerived().RebuildVariableArrayType(ElementType,
2368 T->getSizeModifier(),
2369 move(SizeResult),
2370 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002371 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002372 if (Result.isNull())
2373 return QualType();
2374 }
2375 else SizeResult.take();
2376
2377 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2378 NewTL.setLBracketLoc(TL.getLBracketLoc());
2379 NewTL.setRBracketLoc(TL.getRBracketLoc());
2380 NewTL.setSizeExpr(Size);
2381
2382 return Result;
2383}
2384
2385template<typename Derived>
2386QualType
2387TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002388 DependentSizedArrayTypeLoc TL,
2389 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002390 DependentSizedArrayType *T = TL.getTypePtr();
2391 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2392 if (ElementType.isNull())
2393 return QualType();
2394
2395 // Array bounds are not potentially evaluated contexts
2396 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2397
2398 Sema::OwningExprResult SizeResult
2399 = getDerived().TransformExpr(T->getSizeExpr());
2400 if (SizeResult.isInvalid())
2401 return QualType();
2402
2403 Expr *Size = static_cast<Expr*>(SizeResult.get());
2404
2405 QualType Result = TL.getType();
2406 if (getDerived().AlwaysRebuild() ||
2407 ElementType != T->getElementType() ||
2408 Size != T->getSizeExpr()) {
2409 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2410 T->getSizeModifier(),
2411 move(SizeResult),
2412 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00002413 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00002414 if (Result.isNull())
2415 return QualType();
2416 }
2417 else SizeResult.take();
2418
2419 // We might have any sort of array type now, but fortunately they
2420 // all have the same location layout.
2421 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2422 NewTL.setLBracketLoc(TL.getLBracketLoc());
2423 NewTL.setRBracketLoc(TL.getRBracketLoc());
2424 NewTL.setSizeExpr(Size);
2425
2426 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002427}
Mike Stump1eb44332009-09-09 15:08:12 +00002428
2429template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002430QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00002431 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002432 DependentSizedExtVectorTypeLoc TL,
2433 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002434 DependentSizedExtVectorType *T = TL.getTypePtr();
2435
2436 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00002437 QualType ElementType = getDerived().TransformType(T->getElementType());
2438 if (ElementType.isNull())
2439 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002440
Douglas Gregor670444e2009-08-04 22:27:00 +00002441 // Vector sizes are not potentially evaluated contexts
2442 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2443
Douglas Gregor577f75a2009-08-04 16:50:30 +00002444 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2445 if (Size.isInvalid())
2446 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002447
John McCalla2becad2009-10-21 00:40:46 +00002448 QualType Result = TL.getType();
2449 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00002450 ElementType != T->getElementType() ||
2451 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002452 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00002453 move(Size),
2454 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00002455 if (Result.isNull())
2456 return QualType();
2457 }
2458 else Size.take();
2459
2460 // Result might be dependent or not.
2461 if (isa<DependentSizedExtVectorType>(Result)) {
2462 DependentSizedExtVectorTypeLoc NewTL
2463 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2464 NewTL.setNameLoc(TL.getNameLoc());
2465 } else {
2466 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2467 NewTL.setNameLoc(TL.getNameLoc());
2468 }
2469
2470 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002471}
Mike Stump1eb44332009-09-09 15:08:12 +00002472
2473template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002474QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002475 VectorTypeLoc TL,
2476 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002477 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002478 QualType ElementType = getDerived().TransformType(T->getElementType());
2479 if (ElementType.isNull())
2480 return QualType();
2481
John McCalla2becad2009-10-21 00:40:46 +00002482 QualType Result = TL.getType();
2483 if (getDerived().AlwaysRebuild() ||
2484 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00002485 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2486 T->isAltiVec(), T->isPixel());
John McCalla2becad2009-10-21 00:40:46 +00002487 if (Result.isNull())
2488 return QualType();
2489 }
2490
2491 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2492 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00002493
John McCalla2becad2009-10-21 00:40:46 +00002494 return Result;
2495}
2496
2497template<typename Derived>
2498QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002499 ExtVectorTypeLoc TL,
2500 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002501 VectorType *T = TL.getTypePtr();
2502 QualType ElementType = getDerived().TransformType(T->getElementType());
2503 if (ElementType.isNull())
2504 return QualType();
2505
2506 QualType Result = TL.getType();
2507 if (getDerived().AlwaysRebuild() ||
2508 ElementType != T->getElementType()) {
2509 Result = getDerived().RebuildExtVectorType(ElementType,
2510 T->getNumElements(),
2511 /*FIXME*/ SourceLocation());
2512 if (Result.isNull())
2513 return QualType();
2514 }
2515
2516 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2517 NewTL.setNameLoc(TL.getNameLoc());
2518
2519 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002520}
Mike Stump1eb44332009-09-09 15:08:12 +00002521
2522template<typename Derived>
2523QualType
John McCalla2becad2009-10-21 00:40:46 +00002524TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002525 FunctionProtoTypeLoc TL,
2526 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002527 FunctionProtoType *T = TL.getTypePtr();
2528 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002529 if (ResultType.isNull())
2530 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002531
John McCalla2becad2009-10-21 00:40:46 +00002532 // Transform the parameters.
Douglas Gregor577f75a2009-08-04 16:50:30 +00002533 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00002534 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2535 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2536 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump1eb44332009-09-09 15:08:12 +00002537
John McCalla2becad2009-10-21 00:40:46 +00002538 QualType NewType;
2539 ParmVarDecl *NewParm;
2540
2541 if (OldParm) {
John McCalla93c9342009-12-07 02:54:59 +00002542 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCalla2becad2009-10-21 00:40:46 +00002543 assert(OldDI->getType() == T->getArgType(i));
2544
John McCalla93c9342009-12-07 02:54:59 +00002545 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCalla2becad2009-10-21 00:40:46 +00002546 if (!NewDI)
2547 return QualType();
2548
2549 if (NewDI == OldDI)
2550 NewParm = OldParm;
2551 else
2552 NewParm = ParmVarDecl::Create(SemaRef.Context,
2553 OldParm->getDeclContext(),
2554 OldParm->getLocation(),
2555 OldParm->getIdentifier(),
2556 NewDI->getType(),
2557 NewDI,
2558 OldParm->getStorageClass(),
2559 /* DefArg */ NULL);
2560 NewType = NewParm->getType();
2561
2562 // Deal with the possibility that we don't have a parameter
2563 // declaration for this parameter.
2564 } else {
2565 NewParm = 0;
2566
2567 QualType OldType = T->getArgType(i);
2568 NewType = getDerived().TransformType(OldType);
2569 if (NewType.isNull())
2570 return QualType();
2571 }
2572
2573 ParamTypes.push_back(NewType);
2574 ParamDecls.push_back(NewParm);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002575 }
Mike Stump1eb44332009-09-09 15:08:12 +00002576
John McCalla2becad2009-10-21 00:40:46 +00002577 QualType Result = TL.getType();
2578 if (getDerived().AlwaysRebuild() ||
2579 ResultType != T->getResultType() ||
2580 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2581 Result = getDerived().RebuildFunctionProtoType(ResultType,
2582 ParamTypes.data(),
2583 ParamTypes.size(),
2584 T->isVariadic(),
2585 T->getTypeQuals());
2586 if (Result.isNull())
2587 return QualType();
2588 }
Mike Stump1eb44332009-09-09 15:08:12 +00002589
John McCalla2becad2009-10-21 00:40:46 +00002590 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2591 NewTL.setLParenLoc(TL.getLParenLoc());
2592 NewTL.setRParenLoc(TL.getRParenLoc());
2593 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2594 NewTL.setArg(i, ParamDecls[i]);
2595
2596 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002597}
Mike Stump1eb44332009-09-09 15:08:12 +00002598
Douglas Gregor577f75a2009-08-04 16:50:30 +00002599template<typename Derived>
2600QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00002601 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002602 FunctionNoProtoTypeLoc TL,
2603 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002604 FunctionNoProtoType *T = TL.getTypePtr();
2605 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2606 if (ResultType.isNull())
2607 return QualType();
2608
2609 QualType Result = TL.getType();
2610 if (getDerived().AlwaysRebuild() ||
2611 ResultType != T->getResultType())
2612 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2613
2614 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2615 NewTL.setLParenLoc(TL.getLParenLoc());
2616 NewTL.setRParenLoc(TL.getRParenLoc());
2617
2618 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002619}
Mike Stump1eb44332009-09-09 15:08:12 +00002620
John McCalled976492009-12-04 22:46:56 +00002621template<typename Derived> QualType
2622TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002623 UnresolvedUsingTypeLoc TL,
2624 QualType ObjectType) {
John McCalled976492009-12-04 22:46:56 +00002625 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002626 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00002627 if (!D)
2628 return QualType();
2629
2630 QualType Result = TL.getType();
2631 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2632 Result = getDerived().RebuildUnresolvedUsingType(D);
2633 if (Result.isNull())
2634 return QualType();
2635 }
2636
2637 // We might get an arbitrary type spec type back. We should at
2638 // least always get a type spec type, though.
2639 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2640 NewTL.setNameLoc(TL.getNameLoc());
2641
2642 return Result;
2643}
2644
Douglas Gregor577f75a2009-08-04 16:50:30 +00002645template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002646QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002647 TypedefTypeLoc TL,
2648 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002649 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002650 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002651 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2652 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002653 if (!Typedef)
2654 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002655
John McCalla2becad2009-10-21 00:40:46 +00002656 QualType Result = TL.getType();
2657 if (getDerived().AlwaysRebuild() ||
2658 Typedef != T->getDecl()) {
2659 Result = getDerived().RebuildTypedefType(Typedef);
2660 if (Result.isNull())
2661 return QualType();
2662 }
Mike Stump1eb44332009-09-09 15:08:12 +00002663
John McCalla2becad2009-10-21 00:40:46 +00002664 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2665 NewTL.setNameLoc(TL.getNameLoc());
2666
2667 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002668}
Mike Stump1eb44332009-09-09 15:08:12 +00002669
Douglas Gregor577f75a2009-08-04 16:50:30 +00002670template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002671QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002672 TypeOfExprTypeLoc TL,
2673 QualType ObjectType) {
Douglas Gregor670444e2009-08-04 22:27:00 +00002674 // typeof expressions are not potentially evaluated contexts
2675 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002676
John McCallcfb708c2010-01-13 20:03:27 +00002677 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002678 if (E.isInvalid())
2679 return QualType();
2680
John McCalla2becad2009-10-21 00:40:46 +00002681 QualType Result = TL.getType();
2682 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00002683 E.get() != TL.getUnderlyingExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00002684 Result = getDerived().RebuildTypeOfExprType(move(E));
2685 if (Result.isNull())
2686 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002687 }
John McCalla2becad2009-10-21 00:40:46 +00002688 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002689
John McCalla2becad2009-10-21 00:40:46 +00002690 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002691 NewTL.setTypeofLoc(TL.getTypeofLoc());
2692 NewTL.setLParenLoc(TL.getLParenLoc());
2693 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00002694
2695 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002696}
Mike Stump1eb44332009-09-09 15:08:12 +00002697
2698template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002699QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002700 TypeOfTypeLoc TL,
2701 QualType ObjectType) {
John McCallcfb708c2010-01-13 20:03:27 +00002702 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2703 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2704 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00002705 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002706
John McCalla2becad2009-10-21 00:40:46 +00002707 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00002708 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2709 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00002710 if (Result.isNull())
2711 return QualType();
2712 }
Mike Stump1eb44332009-09-09 15:08:12 +00002713
John McCalla2becad2009-10-21 00:40:46 +00002714 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00002715 NewTL.setTypeofLoc(TL.getTypeofLoc());
2716 NewTL.setLParenLoc(TL.getLParenLoc());
2717 NewTL.setRParenLoc(TL.getRParenLoc());
2718 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00002719
2720 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002721}
Mike Stump1eb44332009-09-09 15:08:12 +00002722
2723template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002724QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002725 DecltypeTypeLoc TL,
2726 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002727 DecltypeType *T = TL.getTypePtr();
2728
Douglas Gregor670444e2009-08-04 22:27:00 +00002729 // decltype expressions are not potentially evaluated contexts
2730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002731
Douglas Gregor577f75a2009-08-04 16:50:30 +00002732 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2733 if (E.isInvalid())
2734 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002735
John McCalla2becad2009-10-21 00:40:46 +00002736 QualType Result = TL.getType();
2737 if (getDerived().AlwaysRebuild() ||
2738 E.get() != T->getUnderlyingExpr()) {
2739 Result = getDerived().RebuildDecltypeType(move(E));
2740 if (Result.isNull())
2741 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002742 }
John McCalla2becad2009-10-21 00:40:46 +00002743 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00002744
John McCalla2becad2009-10-21 00:40:46 +00002745 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2746 NewTL.setNameLoc(TL.getNameLoc());
2747
2748 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002749}
2750
2751template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002752QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002753 RecordTypeLoc TL,
2754 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002755 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002756 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002757 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2758 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002759 if (!Record)
2760 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002761
John McCalla2becad2009-10-21 00:40:46 +00002762 QualType Result = TL.getType();
2763 if (getDerived().AlwaysRebuild() ||
2764 Record != T->getDecl()) {
2765 Result = getDerived().RebuildRecordType(Record);
2766 if (Result.isNull())
2767 return QualType();
2768 }
Mike Stump1eb44332009-09-09 15:08:12 +00002769
John McCalla2becad2009-10-21 00:40:46 +00002770 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2771 NewTL.setNameLoc(TL.getNameLoc());
2772
2773 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002774}
Mike Stump1eb44332009-09-09 15:08:12 +00002775
2776template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002777QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002778 EnumTypeLoc TL,
2779 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002780 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002781 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002782 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2783 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00002784 if (!Enum)
2785 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002786
John McCalla2becad2009-10-21 00:40:46 +00002787 QualType Result = TL.getType();
2788 if (getDerived().AlwaysRebuild() ||
2789 Enum != T->getDecl()) {
2790 Result = getDerived().RebuildEnumType(Enum);
2791 if (Result.isNull())
2792 return QualType();
2793 }
Mike Stump1eb44332009-09-09 15:08:12 +00002794
John McCalla2becad2009-10-21 00:40:46 +00002795 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797
2798 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002799}
John McCall7da24312009-09-05 00:15:47 +00002800
2801template <typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002803 ElaboratedTypeLoc TL,
2804 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002805 ElaboratedType *T = TL.getTypePtr();
2806
2807 // FIXME: this should be a nested type.
John McCall7da24312009-09-05 00:15:47 +00002808 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2809 if (Underlying.isNull())
2810 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002811
John McCalla2becad2009-10-21 00:40:46 +00002812 QualType Result = TL.getType();
2813 if (getDerived().AlwaysRebuild() ||
2814 Underlying != T->getUnderlyingType()) {
2815 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2816 if (Result.isNull())
2817 return QualType();
2818 }
Mike Stump1eb44332009-09-09 15:08:12 +00002819
John McCalla2becad2009-10-21 00:40:46 +00002820 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
2822
2823 return Result;
John McCall7da24312009-09-05 00:15:47 +00002824}
Mike Stump1eb44332009-09-09 15:08:12 +00002825
2826
Douglas Gregor577f75a2009-08-04 16:50:30 +00002827template<typename Derived>
2828QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002829 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002830 TemplateTypeParmTypeLoc TL,
2831 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002832 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002833}
2834
Mike Stump1eb44332009-09-09 15:08:12 +00002835template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00002836QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00002837 TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002838 SubstTemplateTypeParmTypeLoc TL,
2839 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002840 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00002841}
2842
2843template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002844QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2845 const TemplateSpecializationType *TST,
2846 QualType ObjectType) {
2847 // FIXME: this entire method is a temporary workaround; callers
2848 // should be rewritten to provide real type locs.
John McCalla2becad2009-10-21 00:40:46 +00002849
John McCall833ca992009-10-29 08:12:44 +00002850 // Fake up a TemplateSpecializationTypeLoc.
2851 TypeLocBuilder TLB;
2852 TemplateSpecializationTypeLoc TL
2853 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2854
John McCall828bff22009-10-29 18:45:58 +00002855 SourceLocation BaseLoc = getDerived().getBaseLocation();
2856
2857 TL.setTemplateNameLoc(BaseLoc);
2858 TL.setLAngleLoc(BaseLoc);
2859 TL.setRAngleLoc(BaseLoc);
John McCall833ca992009-10-29 08:12:44 +00002860 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2861 const TemplateArgument &TA = TST->getArg(i);
2862 TemplateArgumentLoc TAL;
2863 getDerived().InventTemplateArgumentLoc(TA, TAL);
2864 TL.setArgLocInfo(i, TAL.getLocInfo());
2865 }
2866
2867 TypeLocBuilder IgnoredTLB;
2868 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregordd62b152009-10-19 22:04:39 +00002869}
2870
2871template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00002872QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00002873 TypeLocBuilder &TLB,
2874 TemplateSpecializationTypeLoc TL,
2875 QualType ObjectType) {
2876 const TemplateSpecializationType *T = TL.getTypePtr();
2877
Mike Stump1eb44332009-09-09 15:08:12 +00002878 TemplateName Template
Douglas Gregordd62b152009-10-19 22:04:39 +00002879 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002880 if (Template.isNull())
2881 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002882
John McCalld5532b62009-11-23 01:53:49 +00002883 TemplateArgumentListInfo NewTemplateArgs;
2884 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2885 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2886
2887 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2888 TemplateArgumentLoc Loc;
2889 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregor577f75a2009-08-04 16:50:30 +00002890 return QualType();
John McCalld5532b62009-11-23 01:53:49 +00002891 NewTemplateArgs.addArgument(Loc);
2892 }
Mike Stump1eb44332009-09-09 15:08:12 +00002893
John McCall833ca992009-10-29 08:12:44 +00002894 // FIXME: maybe don't rebuild if all the template arguments are the same.
2895
2896 QualType Result =
2897 getDerived().RebuildTemplateSpecializationType(Template,
2898 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00002899 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00002900
2901 if (!Result.isNull()) {
2902 TemplateSpecializationTypeLoc NewTL
2903 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2904 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2905 NewTL.setLAngleLoc(TL.getLAngleLoc());
2906 NewTL.setRAngleLoc(TL.getRAngleLoc());
2907 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2908 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00002909 }
Mike Stump1eb44332009-09-09 15:08:12 +00002910
John McCall833ca992009-10-29 08:12:44 +00002911 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002912}
Mike Stump1eb44332009-09-09 15:08:12 +00002913
2914template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002915QualType
2916TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002917 QualifiedNameTypeLoc TL,
2918 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002919 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002920 NestedNameSpecifier *NNS
2921 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregor124b8782010-02-16 19:09:40 +00002922 SourceRange(),
2923 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002924 if (!NNS)
2925 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002926
Douglas Gregor577f75a2009-08-04 16:50:30 +00002927 QualType Named = getDerived().TransformType(T->getNamedType());
2928 if (Named.isNull())
2929 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002930
John McCalla2becad2009-10-21 00:40:46 +00002931 QualType Result = TL.getType();
2932 if (getDerived().AlwaysRebuild() ||
2933 NNS != T->getQualifier() ||
2934 Named != T->getNamedType()) {
2935 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2936 if (Result.isNull())
2937 return QualType();
2938 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00002939
John McCalla2becad2009-10-21 00:40:46 +00002940 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2941 NewTL.setNameLoc(TL.getNameLoc());
2942
2943 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002944}
Mike Stump1eb44332009-09-09 15:08:12 +00002945
2946template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002947QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002948 TypenameTypeLoc TL,
2949 QualType ObjectType) {
John McCalla2becad2009-10-21 00:40:46 +00002950 TypenameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00002951
2952 /* FIXME: preserve source information better than this */
2953 SourceRange SR(TL.getNameLoc());
2954
Douglas Gregor577f75a2009-08-04 16:50:30 +00002955 NestedNameSpecifier *NNS
Douglas Gregor124b8782010-02-16 19:09:40 +00002956 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregoredc90502010-02-25 04:46:04 +00002957 ObjectType);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002958 if (!NNS)
2959 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002960
John McCalla2becad2009-10-21 00:40:46 +00002961 QualType Result;
2962
Douglas Gregor577f75a2009-08-04 16:50:30 +00002963 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002964 QualType NewTemplateId
Douglas Gregor577f75a2009-08-04 16:50:30 +00002965 = getDerived().TransformType(QualType(TemplateId, 0));
2966 if (NewTemplateId.isNull())
2967 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00002968
Douglas Gregor577f75a2009-08-04 16:50:30 +00002969 if (!getDerived().AlwaysRebuild() &&
2970 NNS == T->getQualifier() &&
2971 NewTemplateId == QualType(TemplateId, 0))
2972 return QualType(T, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00002973
John McCalla2becad2009-10-21 00:40:46 +00002974 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2975 } else {
John McCall833ca992009-10-29 08:12:44 +00002976 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002977 }
John McCalla2becad2009-10-21 00:40:46 +00002978 if (Result.isNull())
2979 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002980
John McCalla2becad2009-10-21 00:40:46 +00002981 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2982 NewTL.setNameLoc(TL.getNameLoc());
2983
2984 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00002985}
Mike Stump1eb44332009-09-09 15:08:12 +00002986
Douglas Gregor577f75a2009-08-04 16:50:30 +00002987template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002988QualType
2989TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002990 ObjCInterfaceTypeLoc TL,
2991 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00002992 assert(false && "TransformObjCInterfaceType unimplemented");
2993 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00002994}
Mike Stump1eb44332009-09-09 15:08:12 +00002995
2996template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00002997QualType
2998TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregor124b8782010-02-16 19:09:40 +00002999 ObjCObjectPointerTypeLoc TL,
3000 QualType ObjectType) {
John McCall54e14c42009-10-22 22:37:11 +00003001 assert(false && "TransformObjCObjectPointerType unimplemented");
3002 return QualType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00003003}
3004
Douglas Gregor577f75a2009-08-04 16:50:30 +00003005//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00003006// Statement transformation
3007//===----------------------------------------------------------------------===//
3008template<typename Derived>
3009Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003010TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3011 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003012}
3013
3014template<typename Derived>
3015Sema::OwningStmtResult
3016TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3017 return getDerived().TransformCompoundStmt(S, false);
3018}
3019
3020template<typename Derived>
3021Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003022TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00003023 bool IsStmtExpr) {
3024 bool SubStmtChanged = false;
3025 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3026 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3027 B != BEnd; ++B) {
3028 OwningStmtResult Result = getDerived().TransformStmt(*B);
3029 if (Result.isInvalid())
3030 return getSema().StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003031
Douglas Gregor43959a92009-08-20 07:17:43 +00003032 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3033 Statements.push_back(Result.takeAs<Stmt>());
3034 }
Mike Stump1eb44332009-09-09 15:08:12 +00003035
Douglas Gregor43959a92009-08-20 07:17:43 +00003036 if (!getDerived().AlwaysRebuild() &&
3037 !SubStmtChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003038 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003039
3040 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3041 move_arg(Statements),
3042 S->getRBracLoc(),
3043 IsStmtExpr);
3044}
Mike Stump1eb44332009-09-09 15:08:12 +00003045
Douglas Gregor43959a92009-08-20 07:17:43 +00003046template<typename Derived>
3047Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003048TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman264c1f82009-11-19 03:14:00 +00003049 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3050 {
3051 // The case value expressions are not potentially evaluated.
3052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Eli Friedman264c1f82009-11-19 03:14:00 +00003054 // Transform the left-hand case value.
3055 LHS = getDerived().TransformExpr(S->getLHS());
3056 if (LHS.isInvalid())
3057 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003058
Eli Friedman264c1f82009-11-19 03:14:00 +00003059 // Transform the right-hand case value (for the GNU case-range extension).
3060 RHS = getDerived().TransformExpr(S->getRHS());
3061 if (RHS.isInvalid())
3062 return SemaRef.StmtError();
3063 }
Mike Stump1eb44332009-09-09 15:08:12 +00003064
Douglas Gregor43959a92009-08-20 07:17:43 +00003065 // Build the case statement.
3066 // Case statements are always rebuilt so that they will attached to their
3067 // transformed switch statement.
3068 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3069 move(LHS),
3070 S->getEllipsisLoc(),
3071 move(RHS),
3072 S->getColonLoc());
3073 if (Case.isInvalid())
3074 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003075
Douglas Gregor43959a92009-08-20 07:17:43 +00003076 // Transform the statement following the case
3077 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3078 if (SubStmt.isInvalid())
3079 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003080
Douglas Gregor43959a92009-08-20 07:17:43 +00003081 // Attach the body to the case statement
3082 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3083}
3084
3085template<typename Derived>
3086Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003087TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003088 // Transform the statement following the default case
3089 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3090 if (SubStmt.isInvalid())
3091 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003092
Douglas Gregor43959a92009-08-20 07:17:43 +00003093 // Default statements are always rebuilt
3094 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3095 move(SubStmt));
3096}
Mike Stump1eb44332009-09-09 15:08:12 +00003097
Douglas Gregor43959a92009-08-20 07:17:43 +00003098template<typename Derived>
3099Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003100TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003101 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3102 if (SubStmt.isInvalid())
3103 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003104
Douglas Gregor43959a92009-08-20 07:17:43 +00003105 // FIXME: Pass the real colon location in.
3106 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3107 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3108 move(SubStmt));
3109}
Mike Stump1eb44332009-09-09 15:08:12 +00003110
Douglas Gregor43959a92009-08-20 07:17:43 +00003111template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003112Sema::OwningStmtResult
3113TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003114 // Transform the condition
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003115 OwningExprResult Cond(SemaRef);
3116 VarDecl *ConditionVar = 0;
3117 if (S->getConditionVariable()) {
3118 ConditionVar
3119 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003120 getDerived().TransformDefinition(
3121 S->getConditionVariable()->getLocation(),
3122 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00003123 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>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003165 getDerived().TransformDefinition(
3166 S->getConditionVariable()->getLocation(),
3167 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00003168 if (!ConditionVar)
3169 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003170 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00003171 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003172
3173 if (Cond.isInvalid())
3174 return SemaRef.StmtError();
3175 }
Mike Stump1eb44332009-09-09 15:08:12 +00003176
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003177 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003178
Douglas Gregor43959a92009-08-20 07:17:43 +00003179 // Rebuild the switch statement.
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003180 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3181 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00003182 if (Switch.isInvalid())
3183 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003184
Douglas Gregor43959a92009-08-20 07:17:43 +00003185 // Transform the body of the switch statement.
3186 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3187 if (Body.isInvalid())
3188 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003189
Douglas Gregor43959a92009-08-20 07:17:43 +00003190 // Complete the switch statement.
3191 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3192 move(Body));
3193}
Mike Stump1eb44332009-09-09 15:08:12 +00003194
Douglas Gregor43959a92009-08-20 07:17:43 +00003195template<typename Derived>
3196Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003197TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003198 // Transform the condition
Douglas Gregor5656e142009-11-24 21:15:44 +00003199 OwningExprResult Cond(SemaRef);
3200 VarDecl *ConditionVar = 0;
3201 if (S->getConditionVariable()) {
3202 ConditionVar
3203 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003204 getDerived().TransformDefinition(
3205 S->getConditionVariable()->getLocation(),
3206 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00003207 if (!ConditionVar)
3208 return SemaRef.StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003209 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00003210 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003211
3212 if (Cond.isInvalid())
3213 return SemaRef.StmtError();
3214 }
Mike Stump1eb44332009-09-09 15:08:12 +00003215
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003216 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump1eb44332009-09-09 15:08:12 +00003217
Douglas Gregor43959a92009-08-20 07:17:43 +00003218 // Transform the body
3219 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3220 if (Body.isInvalid())
3221 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003222
Douglas Gregor43959a92009-08-20 07:17:43 +00003223 if (!getDerived().AlwaysRebuild() &&
3224 FullCond->get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003225 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00003226 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003227 return SemaRef.Owned(S->Retain());
3228
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003229 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3230 move(Body));
Douglas Gregor43959a92009-08-20 07:17:43 +00003231}
Mike Stump1eb44332009-09-09 15:08:12 +00003232
Douglas Gregor43959a92009-08-20 07:17:43 +00003233template<typename Derived>
3234Sema::OwningStmtResult
3235TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3236 // Transform the condition
3237 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3238 if (Cond.isInvalid())
3239 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003240
Douglas Gregor43959a92009-08-20 07:17:43 +00003241 // Transform the body
3242 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3243 if (Body.isInvalid())
3244 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003245
Douglas Gregor43959a92009-08-20 07:17:43 +00003246 if (!getDerived().AlwaysRebuild() &&
3247 Cond.get() == S->getCond() &&
3248 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003249 return SemaRef.Owned(S->Retain());
3250
Douglas Gregor43959a92009-08-20 07:17:43 +00003251 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3252 /*FIXME:*/S->getWhileLoc(), move(Cond),
3253 S->getRParenLoc());
3254}
Mike Stump1eb44332009-09-09 15:08:12 +00003255
Douglas Gregor43959a92009-08-20 07:17:43 +00003256template<typename Derived>
3257Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003258TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003259 // Transform the initialization statement
3260 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3261 if (Init.isInvalid())
3262 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003263
Douglas Gregor43959a92009-08-20 07:17:43 +00003264 // Transform the condition
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003265 OwningExprResult Cond(SemaRef);
3266 VarDecl *ConditionVar = 0;
3267 if (S->getConditionVariable()) {
3268 ConditionVar
3269 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00003270 getDerived().TransformDefinition(
3271 S->getConditionVariable()->getLocation(),
3272 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003273 if (!ConditionVar)
3274 return SemaRef.StmtError();
3275 } else {
3276 Cond = getDerived().TransformExpr(S->getCond());
3277
3278 if (Cond.isInvalid())
3279 return SemaRef.StmtError();
3280 }
Mike Stump1eb44332009-09-09 15:08:12 +00003281
Douglas Gregor43959a92009-08-20 07:17:43 +00003282 // Transform the increment
3283 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3284 if (Inc.isInvalid())
3285 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003286
Douglas Gregor43959a92009-08-20 07:17:43 +00003287 // Transform the body
3288 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3289 if (Body.isInvalid())
3290 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003291
Douglas Gregor43959a92009-08-20 07:17:43 +00003292 if (!getDerived().AlwaysRebuild() &&
3293 Init.get() == S->getInit() &&
3294 Cond.get() == S->getCond() &&
3295 Inc.get() == S->getInc() &&
3296 Body.get() == S->getBody())
Mike Stump1eb44332009-09-09 15:08:12 +00003297 return SemaRef.Owned(S->Retain());
3298
Douglas Gregor43959a92009-08-20 07:17:43 +00003299 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003300 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00003301 ConditionVar,
Anders Carlsson5ee56e92009-12-16 02:09:40 +00003302 getSema().MakeFullExpr(Inc),
Douglas Gregor43959a92009-08-20 07:17:43 +00003303 S->getRParenLoc(), move(Body));
3304}
3305
3306template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003307Sema::OwningStmtResult
3308TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003309 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00003310 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003311 S->getLabel());
3312}
3313
3314template<typename Derived>
3315Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003316TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003317 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3318 if (Target.isInvalid())
3319 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003320
Douglas Gregor43959a92009-08-20 07:17:43 +00003321 if (!getDerived().AlwaysRebuild() &&
3322 Target.get() == S->getTarget())
Mike Stump1eb44332009-09-09 15:08:12 +00003323 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003324
3325 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3326 move(Target));
3327}
3328
3329template<typename Derived>
3330Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003331TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *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>::TransformBreakStmt(BreakStmt *S) {
3338 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003339}
Mike Stump1eb44332009-09-09 15:08:12 +00003340
Douglas Gregor43959a92009-08-20 07:17:43 +00003341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003344 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3345 if (Result.isInvalid())
3346 return SemaRef.StmtError();
3347
Mike Stump1eb44332009-09-09 15:08:12 +00003348 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00003349 // to tell whether the return type of the function has changed.
3350 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3351}
Mike Stump1eb44332009-09-09 15:08:12 +00003352
Douglas Gregor43959a92009-08-20 07:17:43 +00003353template<typename Derived>
3354Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003355TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003356 bool DeclChanged = false;
3357 llvm::SmallVector<Decl *, 4> Decls;
3358 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3359 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00003360 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3361 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00003362 if (!Transformed)
3363 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003364
Douglas Gregor43959a92009-08-20 07:17:43 +00003365 if (Transformed != *D)
3366 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00003367
Douglas Gregor43959a92009-08-20 07:17:43 +00003368 Decls.push_back(Transformed);
3369 }
Mike Stump1eb44332009-09-09 15:08:12 +00003370
Douglas Gregor43959a92009-08-20 07:17:43 +00003371 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003372 return SemaRef.Owned(S->Retain());
3373
3374 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003375 S->getStartLoc(), S->getEndLoc());
3376}
Mike Stump1eb44332009-09-09 15:08:12 +00003377
Douglas Gregor43959a92009-08-20 07:17:43 +00003378template<typename Derived>
3379Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003380TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003381 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump1eb44332009-09-09 15:08:12 +00003382 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003383}
3384
3385template<typename Derived>
3386Sema::OwningStmtResult
3387TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlsson703e3942010-01-24 05:50:09 +00003388
3389 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3390 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003391 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00003392
Anders Carlsson703e3942010-01-24 05:50:09 +00003393 OwningExprResult AsmString(SemaRef);
3394 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3395
3396 bool ExprsChanged = false;
3397
3398 // Go through the outputs.
3399 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003400 Names.push_back(S->getOutputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003401
Anders Carlsson703e3942010-01-24 05:50:09 +00003402 // No need to transform the constraint literal.
3403 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3404
3405 // Transform the output expr.
3406 Expr *OutputExpr = S->getOutputExpr(I);
3407 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3408 if (Result.isInvalid())
3409 return SemaRef.StmtError();
3410
3411 ExprsChanged |= Result.get() != OutputExpr;
3412
3413 Exprs.push_back(Result.takeAs<Expr>());
3414 }
3415
3416 // Go through the inputs.
3417 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00003418 Names.push_back(S->getInputIdentifier(I));
Anders Carlssona5a79f72010-01-30 20:05:21 +00003419
Anders Carlsson703e3942010-01-24 05:50:09 +00003420 // No need to transform the constraint literal.
3421 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3422
3423 // Transform the input expr.
3424 Expr *InputExpr = S->getInputExpr(I);
3425 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3426 if (Result.isInvalid())
3427 return SemaRef.StmtError();
3428
3429 ExprsChanged |= Result.get() != InputExpr;
3430
3431 Exprs.push_back(Result.takeAs<Expr>());
3432 }
3433
3434 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3435 return SemaRef.Owned(S->Retain());
3436
3437 // Go through the clobbers.
3438 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3439 Clobbers.push_back(S->getClobber(I)->Retain());
3440
3441 // No need to transform the asm string literal.
3442 AsmString = SemaRef.Owned(S->getAsmString());
3443
3444 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3445 S->isSimple(),
3446 S->isVolatile(),
3447 S->getNumOutputs(),
3448 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00003449 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00003450 move_arg(Constraints),
3451 move_arg(Exprs),
3452 move(AsmString),
3453 move_arg(Clobbers),
3454 S->getRParenLoc(),
3455 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00003456}
3457
3458
3459template<typename Derived>
3460Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003461TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003462 // FIXME: Implement this
3463 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003464 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003465}
Mike Stump1eb44332009-09-09 15:08:12 +00003466
Douglas Gregor43959a92009-08-20 07:17:43 +00003467template<typename Derived>
3468Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003469TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003470 // FIXME: Implement this
3471 assert(false && "Cannot transform an Objective-C @catch statement");
3472 return SemaRef.Owned(S->Retain());
3473}
Mike Stump1eb44332009-09-09 15:08:12 +00003474
Douglas Gregor43959a92009-08-20 07:17:43 +00003475template<typename Derived>
3476Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003477TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003478 // FIXME: Implement this
3479 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003480 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003481}
Mike Stump1eb44332009-09-09 15:08:12 +00003482
Douglas Gregor43959a92009-08-20 07:17:43 +00003483template<typename Derived>
3484Sema::OwningStmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00003485TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003486 // FIXME: Implement this
3487 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003488 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003489}
Mike Stump1eb44332009-09-09 15:08:12 +00003490
Douglas Gregor43959a92009-08-20 07:17:43 +00003491template<typename Derived>
3492Sema::OwningStmtResult
3493TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003494 ObjCAtSynchronizedStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003495 // FIXME: Implement this
3496 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003497 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003498}
3499
3500template<typename Derived>
3501Sema::OwningStmtResult
3502TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00003503 ObjCForCollectionStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00003504 // FIXME: Implement this
3505 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump1eb44332009-09-09 15:08:12 +00003506 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003507}
3508
3509
3510template<typename Derived>
3511Sema::OwningStmtResult
3512TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3513 // Transform the exception declaration, if any.
3514 VarDecl *Var = 0;
3515 if (S->getExceptionDecl()) {
3516 VarDecl *ExceptionDecl = S->getExceptionDecl();
3517 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3518 ExceptionDecl->getDeclName());
3519
3520 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3521 if (T.isNull())
3522 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003523
Douglas Gregor43959a92009-08-20 07:17:43 +00003524 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3525 T,
John McCalla93c9342009-12-07 02:54:59 +00003526 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregor43959a92009-08-20 07:17:43 +00003527 ExceptionDecl->getIdentifier(),
3528 ExceptionDecl->getLocation(),
3529 /*FIXME: Inaccurate*/
3530 SourceRange(ExceptionDecl->getLocation()));
3531 if (!Var || Var->isInvalidDecl()) {
3532 if (Var)
3533 Var->Destroy(SemaRef.Context);
3534 return SemaRef.StmtError();
3535 }
3536 }
Mike Stump1eb44332009-09-09 15:08:12 +00003537
Douglas Gregor43959a92009-08-20 07:17:43 +00003538 // Transform the actual exception handler.
3539 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3540 if (Handler.isInvalid()) {
3541 if (Var)
3542 Var->Destroy(SemaRef.Context);
3543 return SemaRef.StmtError();
3544 }
Mike Stump1eb44332009-09-09 15:08:12 +00003545
Douglas Gregor43959a92009-08-20 07:17:43 +00003546 if (!getDerived().AlwaysRebuild() &&
3547 !Var &&
3548 Handler.get() == S->getHandlerBlock())
Mike Stump1eb44332009-09-09 15:08:12 +00003549 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003550
3551 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3552 Var,
3553 move(Handler));
3554}
Mike Stump1eb44332009-09-09 15:08:12 +00003555
Douglas Gregor43959a92009-08-20 07:17:43 +00003556template<typename Derived>
3557Sema::OwningStmtResult
3558TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3559 // Transform the try block itself.
Mike Stump1eb44332009-09-09 15:08:12 +00003560 OwningStmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00003561 = getDerived().TransformCompoundStmt(S->getTryBlock());
3562 if (TryBlock.isInvalid())
3563 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003564
Douglas Gregor43959a92009-08-20 07:17:43 +00003565 // Transform the handlers.
3566 bool HandlerChanged = false;
3567 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3568 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +00003569 OwningStmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00003570 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3571 if (Handler.isInvalid())
3572 return SemaRef.StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00003573
Douglas Gregor43959a92009-08-20 07:17:43 +00003574 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3575 Handlers.push_back(Handler.takeAs<Stmt>());
3576 }
Mike Stump1eb44332009-09-09 15:08:12 +00003577
Douglas Gregor43959a92009-08-20 07:17:43 +00003578 if (!getDerived().AlwaysRebuild() &&
3579 TryBlock.get() == S->getTryBlock() &&
3580 !HandlerChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00003581 return SemaRef.Owned(S->Retain());
Douglas Gregor43959a92009-08-20 07:17:43 +00003582
3583 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump1eb44332009-09-09 15:08:12 +00003584 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00003585}
Mike Stump1eb44332009-09-09 15:08:12 +00003586
Douglas Gregor43959a92009-08-20 07:17:43 +00003587//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00003588// Expression transformation
3589//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00003590template<typename Derived>
3591Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003592TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003593 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003594}
Mike Stump1eb44332009-09-09 15:08:12 +00003595
3596template<typename Derived>
3597Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003598TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00003599 NestedNameSpecifier *Qualifier = 0;
3600 if (E->getQualifier()) {
3601 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003602 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003603 if (!Qualifier)
3604 return SemaRef.ExprError();
3605 }
John McCalldbd872f2009-12-08 09:08:17 +00003606
3607 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003608 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3609 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003610 if (!ND)
3611 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003612
Douglas Gregora2813ce2009-10-23 18:54:35 +00003613 if (!getDerived().AlwaysRebuild() &&
3614 Qualifier == E->getQualifier() &&
3615 ND == E->getDecl() &&
John McCalldbd872f2009-12-08 09:08:17 +00003616 !E->hasExplicitTemplateArgumentList()) {
3617
3618 // Mark it referenced in the new context regardless.
3619 // FIXME: this is a bit instantiation-specific.
3620 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3621
Mike Stump1eb44332009-09-09 15:08:12 +00003622 return SemaRef.Owned(E->Retain());
Douglas Gregora2813ce2009-10-23 18:54:35 +00003623 }
John McCalldbd872f2009-12-08 09:08:17 +00003624
3625 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3626 if (E->hasExplicitTemplateArgumentList()) {
3627 TemplateArgs = &TransArgs;
3628 TransArgs.setLAngleLoc(E->getLAngleLoc());
3629 TransArgs.setRAngleLoc(E->getRAngleLoc());
3630 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3631 TemplateArgumentLoc Loc;
3632 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3633 return SemaRef.ExprError();
3634 TransArgs.addArgument(Loc);
3635 }
3636 }
3637
Douglas Gregora2813ce2009-10-23 18:54:35 +00003638 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCalldbd872f2009-12-08 09:08:17 +00003639 ND, E->getLocation(), TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003640}
Mike Stump1eb44332009-09-09 15:08:12 +00003641
Douglas Gregorb98b1992009-08-11 05:31:07 +00003642template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003643Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003644TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003645 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003646}
Mike Stump1eb44332009-09-09 15:08:12 +00003647
Douglas Gregorb98b1992009-08-11 05:31:07 +00003648template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003649Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003650TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003651 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003652}
Mike Stump1eb44332009-09-09 15:08:12 +00003653
Douglas Gregorb98b1992009-08-11 05:31:07 +00003654template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003655Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003656TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003657 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003658}
Mike Stump1eb44332009-09-09 15:08:12 +00003659
Douglas Gregorb98b1992009-08-11 05:31:07 +00003660template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003661Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003662TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003663 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003664}
Mike Stump1eb44332009-09-09 15:08:12 +00003665
Douglas Gregorb98b1992009-08-11 05:31:07 +00003666template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003667Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003668TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00003669 return SemaRef.Owned(E->Retain());
3670}
3671
3672template<typename Derived>
3673Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003674TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003675 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3676 if (SubExpr.isInvalid())
3677 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003678
Douglas Gregorb98b1992009-08-11 05:31:07 +00003679 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003680 return SemaRef.Owned(E->Retain());
3681
3682 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003683 E->getRParen());
3684}
3685
Mike Stump1eb44332009-09-09 15:08:12 +00003686template<typename Derived>
3687Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003688TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3689 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003690 if (SubExpr.isInvalid())
3691 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003692
Douglas Gregorb98b1992009-08-11 05:31:07 +00003693 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003694 return SemaRef.Owned(E->Retain());
3695
Douglas Gregorb98b1992009-08-11 05:31:07 +00003696 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3697 E->getOpcode(),
3698 move(SubExpr));
3699}
Mike Stump1eb44332009-09-09 15:08:12 +00003700
Douglas Gregorb98b1992009-08-11 05:31:07 +00003701template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003702Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003703TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003704 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00003705 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00003706
John McCalla93c9342009-12-07 02:54:59 +00003707 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00003708 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003709 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003710
John McCall5ab75172009-11-04 07:28:41 +00003711 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003712 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003713
John McCall5ab75172009-11-04 07:28:41 +00003714 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003715 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003716 E->getSourceRange());
3717 }
Mike Stump1eb44332009-09-09 15:08:12 +00003718
Douglas Gregorb98b1992009-08-11 05:31:07 +00003719 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00003720 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003721 // C++0x [expr.sizeof]p1:
3722 // The operand is either an expression, which is an unevaluated operand
3723 // [...]
3724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003725
Douglas Gregorb98b1992009-08-11 05:31:07 +00003726 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3727 if (SubExpr.isInvalid())
3728 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003729
Douglas Gregorb98b1992009-08-11 05:31:07 +00003730 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3731 return SemaRef.Owned(E->Retain());
3732 }
Mike Stump1eb44332009-09-09 15:08:12 +00003733
Douglas Gregorb98b1992009-08-11 05:31:07 +00003734 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3735 E->isSizeOf(),
3736 E->getSourceRange());
3737}
Mike Stump1eb44332009-09-09 15:08:12 +00003738
Douglas Gregorb98b1992009-08-11 05:31:07 +00003739template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003740Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003741TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003742 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3743 if (LHS.isInvalid())
3744 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003745
Douglas Gregorb98b1992009-08-11 05:31:07 +00003746 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3747 if (RHS.isInvalid())
3748 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003749
3750
Douglas Gregorb98b1992009-08-11 05:31:07 +00003751 if (!getDerived().AlwaysRebuild() &&
3752 LHS.get() == E->getLHS() &&
3753 RHS.get() == E->getRHS())
3754 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003755
Douglas Gregorb98b1992009-08-11 05:31:07 +00003756 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3757 /*FIXME:*/E->getLHS()->getLocStart(),
3758 move(RHS),
3759 E->getRBracketLoc());
3760}
Mike Stump1eb44332009-09-09 15:08:12 +00003761
3762template<typename Derived>
3763Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003764TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003765 // Transform the callee.
3766 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3767 if (Callee.isInvalid())
3768 return SemaRef.ExprError();
3769
3770 // Transform arguments.
3771 bool ArgChanged = false;
3772 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3773 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3774 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3775 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3776 if (Arg.isInvalid())
3777 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003778
Douglas Gregorb98b1992009-08-11 05:31:07 +00003779 // FIXME: Wrong source location information for the ','.
3780 FakeCommaLocs.push_back(
3781 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump1eb44332009-09-09 15:08:12 +00003782
3783 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003784 Args.push_back(Arg.takeAs<Expr>());
3785 }
Mike Stump1eb44332009-09-09 15:08:12 +00003786
Douglas Gregorb98b1992009-08-11 05:31:07 +00003787 if (!getDerived().AlwaysRebuild() &&
3788 Callee.get() == E->getCallee() &&
3789 !ArgChanged)
3790 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003791
Douglas Gregorb98b1992009-08-11 05:31:07 +00003792 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00003793 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003794 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3795 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3796 move_arg(Args),
3797 FakeCommaLocs.data(),
3798 E->getRParenLoc());
3799}
Mike Stump1eb44332009-09-09 15:08:12 +00003800
3801template<typename Derived>
3802Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003803TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003804 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3805 if (Base.isInvalid())
3806 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003807
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003808 NestedNameSpecifier *Qualifier = 0;
3809 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00003810 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003811 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00003812 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00003813 if (Qualifier == 0)
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003814 return SemaRef.ExprError();
3815 }
Mike Stump1eb44332009-09-09 15:08:12 +00003816
Eli Friedmanf595cc42009-12-04 06:40:45 +00003817 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003818 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3819 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00003820 if (!Member)
3821 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003822
Douglas Gregorb98b1992009-08-11 05:31:07 +00003823 if (!getDerived().AlwaysRebuild() &&
3824 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003825 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003826 Member == E->getMemberDecl() &&
Anders Carlsson1f240322009-12-22 05:24:09 +00003827 !E->hasExplicitTemplateArgumentList()) {
3828
3829 // Mark it referenced in the new context regardless.
3830 // FIXME: this is a bit instantiation-specific.
3831 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump1eb44332009-09-09 15:08:12 +00003832 return SemaRef.Owned(E->Retain());
Anders Carlsson1f240322009-12-22 05:24:09 +00003833 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00003834
John McCalld5532b62009-11-23 01:53:49 +00003835 TemplateArgumentListInfo TransArgs;
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003836 if (E->hasExplicitTemplateArgumentList()) {
John McCalld5532b62009-11-23 01:53:49 +00003837 TransArgs.setLAngleLoc(E->getLAngleLoc());
3838 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003839 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00003840 TemplateArgumentLoc Loc;
3841 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003842 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00003843 TransArgs.addArgument(Loc);
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003844 }
3845 }
3846
Douglas Gregorb98b1992009-08-11 05:31:07 +00003847 // FIXME: Bogus source location for the operator
3848 SourceLocation FakeOperatorLoc
3849 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3850
John McCallc2233c52010-01-15 08:34:02 +00003851 // FIXME: to do this check properly, we will need to preserve the
3852 // first-qualifier-in-scope here, just in case we had a dependent
3853 // base (and therefore couldn't do the check) and a
3854 // nested-name-qualifier (and therefore could do the lookup).
3855 NamedDecl *FirstQualifierInScope = 0;
3856
Douglas Gregorb98b1992009-08-11 05:31:07 +00003857 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3858 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00003859 Qualifier,
3860 E->getQualifierRange(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003861 E->getMemberLoc(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00003862 Member,
John McCalld5532b62009-11-23 01:53:49 +00003863 (E->hasExplicitTemplateArgumentList()
3864 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00003865 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003866}
Mike Stump1eb44332009-09-09 15:08:12 +00003867
Douglas Gregorb98b1992009-08-11 05:31:07 +00003868template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003869Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003870TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003871 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3872 if (LHS.isInvalid())
3873 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003874
Douglas Gregorb98b1992009-08-11 05:31:07 +00003875 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3876 if (RHS.isInvalid())
3877 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003878
Douglas Gregorb98b1992009-08-11 05:31:07 +00003879 if (!getDerived().AlwaysRebuild() &&
3880 LHS.get() == E->getLHS() &&
3881 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00003882 return SemaRef.Owned(E->Retain());
3883
Douglas Gregorb98b1992009-08-11 05:31:07 +00003884 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3885 move(LHS), move(RHS));
3886}
3887
Mike Stump1eb44332009-09-09 15:08:12 +00003888template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00003889Sema::OwningExprResult
3890TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00003891 CompoundAssignOperator *E) {
3892 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00003893}
Mike Stump1eb44332009-09-09 15:08:12 +00003894
Douglas Gregorb98b1992009-08-11 05:31:07 +00003895template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003896Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003897TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003898 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3899 if (Cond.isInvalid())
3900 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003901
Douglas Gregorb98b1992009-08-11 05:31:07 +00003902 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3903 if (LHS.isInvalid())
3904 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003905
Douglas Gregorb98b1992009-08-11 05:31:07 +00003906 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3907 if (RHS.isInvalid())
3908 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003909
Douglas Gregorb98b1992009-08-11 05:31:07 +00003910 if (!getDerived().AlwaysRebuild() &&
3911 Cond.get() == E->getCond() &&
3912 LHS.get() == E->getLHS() &&
3913 RHS.get() == E->getRHS())
3914 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00003915
3916 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003917 E->getQuestionLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00003918 move(LHS),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00003919 E->getColonLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00003920 move(RHS));
3921}
Mike Stump1eb44332009-09-09 15:08:12 +00003922
3923template<typename Derived>
3924Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003925TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003926 // Implicit casts are eliminated during transformation, since they
3927 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00003928 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003929}
Mike Stump1eb44332009-09-09 15:08:12 +00003930
Douglas Gregorb98b1992009-08-11 05:31:07 +00003931template<typename Derived>
3932Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003933TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00003934 TypeSourceInfo *OldT;
3935 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00003936 {
3937 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00003938 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00003939 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3940 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00003941
John McCall9d125032010-01-15 18:39:57 +00003942 OldT = E->getTypeInfoAsWritten();
3943 NewT = getDerived().TransformType(OldT);
3944 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00003945 return SemaRef.ExprError();
3946 }
Mike Stump1eb44332009-09-09 15:08:12 +00003947
Douglas Gregora88cfbf2009-12-12 18:16:41 +00003948 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00003949 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003950 if (SubExpr.isInvalid())
3951 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003952
Douglas Gregorb98b1992009-08-11 05:31:07 +00003953 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00003954 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003955 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00003956 return SemaRef.Owned(E->Retain());
3957
John McCall9d125032010-01-15 18:39:57 +00003958 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3959 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003960 E->getRParenLoc(),
3961 move(SubExpr));
3962}
Mike Stump1eb44332009-09-09 15:08:12 +00003963
Douglas Gregorb98b1992009-08-11 05:31:07 +00003964template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003965Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003966TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00003967 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3968 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3969 if (!NewT)
3970 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003971
Douglas Gregorb98b1992009-08-11 05:31:07 +00003972 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3973 if (Init.isInvalid())
3974 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003975
Douglas Gregorb98b1992009-08-11 05:31:07 +00003976 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00003977 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00003978 Init.get() == E->getInitializer())
Mike Stump1eb44332009-09-09 15:08:12 +00003979 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00003980
John McCall1d7d8d62010-01-19 22:33:45 +00003981 // Note: the expression type doesn't necessarily match the
3982 // type-as-written, but that's okay, because it should always be
3983 // derivable from the initializer.
3984
John McCall42f56b52010-01-18 19:35:47 +00003985 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00003986 /*FIXME:*/E->getInitializer()->getLocEnd(),
3987 move(Init));
3988}
Mike Stump1eb44332009-09-09 15:08:12 +00003989
Douglas Gregorb98b1992009-08-11 05:31:07 +00003990template<typename Derived>
3991Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00003992TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00003993 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3994 if (Base.isInvalid())
3995 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00003996
Douglas Gregorb98b1992009-08-11 05:31:07 +00003997 if (!getDerived().AlwaysRebuild() &&
3998 Base.get() == E->getBase())
Mike Stump1eb44332009-09-09 15:08:12 +00003999 return SemaRef.Owned(E->Retain());
4000
Douglas Gregorb98b1992009-08-11 05:31:07 +00004001 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00004002 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004003 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4004 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4005 E->getAccessorLoc(),
4006 E->getAccessor());
4007}
Mike Stump1eb44332009-09-09 15:08:12 +00004008
Douglas Gregorb98b1992009-08-11 05:31:07 +00004009template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004010Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004011TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004012 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00004013
Douglas Gregorb98b1992009-08-11 05:31:07 +00004014 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4015 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4016 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4017 if (Init.isInvalid())
4018 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004019
Douglas Gregorb98b1992009-08-11 05:31:07 +00004020 InitChanged = InitChanged || Init.get() != E->getInit(I);
4021 Inits.push_back(Init.takeAs<Expr>());
4022 }
Mike Stump1eb44332009-09-09 15:08:12 +00004023
Douglas Gregorb98b1992009-08-11 05:31:07 +00004024 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00004025 return SemaRef.Owned(E->Retain());
4026
Douglas Gregorb98b1992009-08-11 05:31:07 +00004027 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00004028 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004029}
Mike Stump1eb44332009-09-09 15:08:12 +00004030
Douglas Gregorb98b1992009-08-11 05:31:07 +00004031template<typename Derived>
4032Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004033TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004034 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00004035
Douglas Gregor43959a92009-08-20 07:17:43 +00004036 // transform the initializer value
Douglas Gregorb98b1992009-08-11 05:31:07 +00004037 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4038 if (Init.isInvalid())
4039 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004040
Douglas Gregor43959a92009-08-20 07:17:43 +00004041 // transform the designators.
Douglas Gregorb98b1992009-08-11 05:31:07 +00004042 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4043 bool ExprChanged = false;
4044 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4045 DEnd = E->designators_end();
4046 D != DEnd; ++D) {
4047 if (D->isFieldDesignator()) {
4048 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4049 D->getDotLoc(),
4050 D->getFieldLoc()));
4051 continue;
4052 }
Mike Stump1eb44332009-09-09 15:08:12 +00004053
Douglas Gregorb98b1992009-08-11 05:31:07 +00004054 if (D->isArrayDesignator()) {
4055 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4056 if (Index.isInvalid())
4057 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004058
4059 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004060 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004061
Douglas Gregorb98b1992009-08-11 05:31:07 +00004062 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4063 ArrayExprs.push_back(Index.release());
4064 continue;
4065 }
Mike Stump1eb44332009-09-09 15:08:12 +00004066
Douglas Gregorb98b1992009-08-11 05:31:07 +00004067 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump1eb44332009-09-09 15:08:12 +00004068 OwningExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00004069 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4070 if (Start.isInvalid())
4071 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004072
Douglas Gregorb98b1992009-08-11 05:31:07 +00004073 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4074 if (End.isInvalid())
4075 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004076
4077 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004078 End.get(),
4079 D->getLBracketLoc(),
4080 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00004081
Douglas Gregorb98b1992009-08-11 05:31:07 +00004082 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4083 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00004084
Douglas Gregorb98b1992009-08-11 05:31:07 +00004085 ArrayExprs.push_back(Start.release());
4086 ArrayExprs.push_back(End.release());
4087 }
Mike Stump1eb44332009-09-09 15:08:12 +00004088
Douglas Gregorb98b1992009-08-11 05:31:07 +00004089 if (!getDerived().AlwaysRebuild() &&
4090 Init.get() == E->getInit() &&
4091 !ExprChanged)
4092 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004093
Douglas Gregorb98b1992009-08-11 05:31:07 +00004094 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4095 E->getEqualOrColonLoc(),
4096 E->usesGNUSyntax(), move(Init));
4097}
Mike Stump1eb44332009-09-09 15:08:12 +00004098
Douglas Gregorb98b1992009-08-11 05:31:07 +00004099template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004100Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00004101TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00004102 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00004103 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4104
4105 // FIXME: Will we ever have proper type location here? Will we actually
4106 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00004107 QualType T = getDerived().TransformType(E->getType());
4108 if (T.isNull())
4109 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004110
Douglas Gregorb98b1992009-08-11 05:31:07 +00004111 if (!getDerived().AlwaysRebuild() &&
4112 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004113 return SemaRef.Owned(E->Retain());
4114
Douglas Gregorb98b1992009-08-11 05:31:07 +00004115 return getDerived().RebuildImplicitValueInitExpr(T);
4116}
Mike Stump1eb44332009-09-09 15:08:12 +00004117
Douglas Gregorb98b1992009-08-11 05:31:07 +00004118template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004119Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004120TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004121 // FIXME: Do we want the type as written?
4122 QualType T;
Mike Stump1eb44332009-09-09 15:08:12 +00004123
Douglas Gregorb98b1992009-08-11 05:31:07 +00004124 {
4125 // FIXME: Source location isn't quite accurate.
4126 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4127 T = getDerived().TransformType(E->getType());
4128 if (T.isNull())
4129 return SemaRef.ExprError();
4130 }
Mike Stump1eb44332009-09-09 15:08:12 +00004131
Douglas Gregorb98b1992009-08-11 05:31:07 +00004132 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4133 if (SubExpr.isInvalid())
4134 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004135
Douglas Gregorb98b1992009-08-11 05:31:07 +00004136 if (!getDerived().AlwaysRebuild() &&
4137 T == E->getType() &&
4138 SubExpr.get() == E->getSubExpr())
4139 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004140
Douglas Gregorb98b1992009-08-11 05:31:07 +00004141 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4142 T, E->getRParenLoc());
4143}
4144
4145template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004146Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004147TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004148 bool ArgumentChanged = false;
4149 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4150 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4151 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4152 if (Init.isInvalid())
4153 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004154
Douglas Gregorb98b1992009-08-11 05:31:07 +00004155 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4156 Inits.push_back(Init.takeAs<Expr>());
4157 }
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregorb98b1992009-08-11 05:31:07 +00004159 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4160 move_arg(Inits),
4161 E->getRParenLoc());
4162}
Mike Stump1eb44332009-09-09 15:08:12 +00004163
Douglas Gregorb98b1992009-08-11 05:31:07 +00004164/// \brief Transform an address-of-label expression.
4165///
4166/// By default, the transformation of an address-of-label expression always
4167/// rebuilds the expression, so that the label identifier can be resolved to
4168/// the corresponding label statement by semantic analysis.
4169template<typename Derived>
4170Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004172 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4173 E->getLabel());
4174}
Mike Stump1eb44332009-09-09 15:08:12 +00004175
4176template<typename Derived>
Douglas Gregorc86a6e92009-11-04 07:01:15 +00004177Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004178TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004179 OwningStmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00004180 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4181 if (SubStmt.isInvalid())
4182 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004183
Douglas Gregorb98b1992009-08-11 05:31:07 +00004184 if (!getDerived().AlwaysRebuild() &&
4185 SubStmt.get() == E->getSubStmt())
4186 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004187
4188 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004189 move(SubStmt),
4190 E->getRParenLoc());
4191}
Mike Stump1eb44332009-09-09 15:08:12 +00004192
Douglas Gregorb98b1992009-08-11 05:31:07 +00004193template<typename Derived>
4194Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004195TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004196 QualType T1, T2;
4197 {
4198 // FIXME: Source location isn't quite accurate.
4199 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004200
Douglas Gregorb98b1992009-08-11 05:31:07 +00004201 T1 = getDerived().TransformType(E->getArgType1());
4202 if (T1.isNull())
4203 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004204
Douglas Gregorb98b1992009-08-11 05:31:07 +00004205 T2 = getDerived().TransformType(E->getArgType2());
4206 if (T2.isNull())
4207 return SemaRef.ExprError();
4208 }
4209
4210 if (!getDerived().AlwaysRebuild() &&
4211 T1 == E->getArgType1() &&
4212 T2 == E->getArgType2())
Mike Stump1eb44332009-09-09 15:08:12 +00004213 return SemaRef.Owned(E->Retain());
4214
Douglas Gregorb98b1992009-08-11 05:31:07 +00004215 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4216 T1, T2, E->getRParenLoc());
4217}
Mike Stump1eb44332009-09-09 15:08:12 +00004218
Douglas Gregorb98b1992009-08-11 05:31:07 +00004219template<typename Derived>
4220Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004221TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004222 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4223 if (Cond.isInvalid())
4224 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004225
Douglas Gregorb98b1992009-08-11 05:31:07 +00004226 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4227 if (LHS.isInvalid())
4228 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004229
Douglas Gregorb98b1992009-08-11 05:31:07 +00004230 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4231 if (RHS.isInvalid())
4232 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004233
Douglas Gregorb98b1992009-08-11 05:31:07 +00004234 if (!getDerived().AlwaysRebuild() &&
4235 Cond.get() == E->getCond() &&
4236 LHS.get() == E->getLHS() &&
4237 RHS.get() == E->getRHS())
Mike Stump1eb44332009-09-09 15:08:12 +00004238 return SemaRef.Owned(E->Retain());
4239
Douglas Gregorb98b1992009-08-11 05:31:07 +00004240 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4241 move(Cond), move(LHS), move(RHS),
4242 E->getRParenLoc());
4243}
Mike Stump1eb44332009-09-09 15:08:12 +00004244
Douglas Gregorb98b1992009-08-11 05:31:07 +00004245template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004246Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004247TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004248 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004249}
4250
4251template<typename Derived>
4252Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004253TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00004254 switch (E->getOperator()) {
4255 case OO_New:
4256 case OO_Delete:
4257 case OO_Array_New:
4258 case OO_Array_Delete:
4259 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4260 return SemaRef.ExprError();
4261
4262 case OO_Call: {
4263 // This is a call to an object's operator().
4264 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4265
4266 // Transform the object itself.
4267 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4268 if (Object.isInvalid())
4269 return SemaRef.ExprError();
4270
4271 // FIXME: Poor location information
4272 SourceLocation FakeLParenLoc
4273 = SemaRef.PP.getLocForEndOfToken(
4274 static_cast<Expr *>(Object.get())->getLocEnd());
4275
4276 // Transform the call arguments.
4277 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4278 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4279 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004280 if (getDerived().DropCallArgument(E->getArg(I)))
4281 break;
4282
Douglas Gregor668d6d92009-12-13 20:44:55 +00004283 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4284 if (Arg.isInvalid())
4285 return SemaRef.ExprError();
4286
4287 // FIXME: Poor source location information.
4288 SourceLocation FakeCommaLoc
4289 = SemaRef.PP.getLocForEndOfToken(
4290 static_cast<Expr *>(Arg.get())->getLocEnd());
4291 FakeCommaLocs.push_back(FakeCommaLoc);
4292 Args.push_back(Arg.release());
4293 }
4294
4295 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4296 move_arg(Args),
4297 FakeCommaLocs.data(),
4298 E->getLocEnd());
4299 }
4300
4301#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4302 case OO_##Name:
4303#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4304#include "clang/Basic/OperatorKinds.def"
4305 case OO_Subscript:
4306 // Handled below.
4307 break;
4308
4309 case OO_Conditional:
4310 llvm_unreachable("conditional operator is not actually overloadable");
4311 return SemaRef.ExprError();
4312
4313 case OO_None:
4314 case NUM_OVERLOADED_OPERATORS:
4315 llvm_unreachable("not an overloaded operator?");
4316 return SemaRef.ExprError();
4317 }
4318
Douglas Gregorb98b1992009-08-11 05:31:07 +00004319 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4320 if (Callee.isInvalid())
4321 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004322
John McCall454feb92009-12-08 09:21:05 +00004323 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004324 if (First.isInvalid())
4325 return SemaRef.ExprError();
4326
4327 OwningExprResult Second(SemaRef);
4328 if (E->getNumArgs() == 2) {
4329 Second = getDerived().TransformExpr(E->getArg(1));
4330 if (Second.isInvalid())
4331 return SemaRef.ExprError();
4332 }
Mike Stump1eb44332009-09-09 15:08:12 +00004333
Douglas Gregorb98b1992009-08-11 05:31:07 +00004334 if (!getDerived().AlwaysRebuild() &&
4335 Callee.get() == E->getCallee() &&
4336 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00004337 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4338 return SemaRef.Owned(E->Retain());
4339
Douglas Gregorb98b1992009-08-11 05:31:07 +00004340 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4341 E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004342 move(Callee),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004343 move(First),
4344 move(Second));
4345}
Mike Stump1eb44332009-09-09 15:08:12 +00004346
Douglas Gregorb98b1992009-08-11 05:31:07 +00004347template<typename Derived>
4348Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004349TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4350 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004351}
Mike Stump1eb44332009-09-09 15:08:12 +00004352
Douglas Gregorb98b1992009-08-11 05:31:07 +00004353template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004354Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004355TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004356 TypeSourceInfo *OldT;
4357 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004358 {
4359 // FIXME: Source location isn't quite accurate.
Mike Stump1eb44332009-09-09 15:08:12 +00004360 SourceLocation TypeStartLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004361 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4362 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004363
John McCall9d125032010-01-15 18:39:57 +00004364 OldT = E->getTypeInfoAsWritten();
4365 NewT = getDerived().TransformType(OldT);
4366 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004367 return SemaRef.ExprError();
4368 }
Mike Stump1eb44332009-09-09 15:08:12 +00004369
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004370 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004371 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004372 if (SubExpr.isInvalid())
4373 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004374
Douglas Gregorb98b1992009-08-11 05:31:07 +00004375 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004376 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004377 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004378 return SemaRef.Owned(E->Retain());
4379
Douglas Gregorb98b1992009-08-11 05:31:07 +00004380 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00004381 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00004382 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4383 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4384 SourceLocation FakeRParenLoc
4385 = SemaRef.PP.getLocForEndOfToken(
4386 E->getSubExpr()->getSourceRange().getEnd());
4387 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00004388 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004389 FakeLAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00004390 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004391 FakeRAngleLoc,
4392 FakeRAngleLoc,
4393 move(SubExpr),
4394 FakeRParenLoc);
4395}
Mike Stump1eb44332009-09-09 15:08:12 +00004396
Douglas Gregorb98b1992009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4400 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004401}
Mike Stump1eb44332009-09-09 15:08:12 +00004402
4403template<typename Derived>
4404Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004405TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4406 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00004407}
4408
Douglas Gregorb98b1992009-08-11 05:31:07 +00004409template<typename Derived>
4410Sema::OwningExprResult
4411TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004412 CXXReinterpretCastExpr *E) {
4413 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004414}
Mike Stump1eb44332009-09-09 15:08:12 +00004415
Douglas Gregorb98b1992009-08-11 05:31:07 +00004416template<typename Derived>
4417Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004418TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4419 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004420}
Mike Stump1eb44332009-09-09 15:08:12 +00004421
Douglas Gregorb98b1992009-08-11 05:31:07 +00004422template<typename Derived>
4423Sema::OwningExprResult
4424TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00004425 CXXFunctionalCastExpr *E) {
John McCall9d125032010-01-15 18:39:57 +00004426 TypeSourceInfo *OldT;
4427 TypeSourceInfo *NewT;
Douglas Gregorb98b1992009-08-11 05:31:07 +00004428 {
4429 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004430
John McCall9d125032010-01-15 18:39:57 +00004431 OldT = E->getTypeInfoAsWritten();
4432 NewT = getDerived().TransformType(OldT);
4433 if (!NewT)
Douglas Gregorb98b1992009-08-11 05:31:07 +00004434 return SemaRef.ExprError();
4435 }
Mike Stump1eb44332009-09-09 15:08:12 +00004436
Douglas Gregora88cfbf2009-12-12 18:16:41 +00004437 OwningExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00004438 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004439 if (SubExpr.isInvalid())
4440 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004441
Douglas Gregorb98b1992009-08-11 05:31:07 +00004442 if (!getDerived().AlwaysRebuild() &&
John McCall9d125032010-01-15 18:39:57 +00004443 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004444 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004445 return SemaRef.Owned(E->Retain());
4446
Douglas Gregorb98b1992009-08-11 05:31:07 +00004447 // FIXME: The end of the type's source range is wrong
4448 return getDerived().RebuildCXXFunctionalCastExpr(
4449 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall9d125032010-01-15 18:39:57 +00004450 NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004451 /*FIXME:*/E->getSubExpr()->getLocStart(),
4452 move(SubExpr),
4453 E->getRParenLoc());
4454}
Mike Stump1eb44332009-09-09 15:08:12 +00004455
Douglas Gregorb98b1992009-08-11 05:31:07 +00004456template<typename Derived>
4457Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004458TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004459 if (E->isTypeOperand()) {
4460 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregorb98b1992009-08-11 05:31:07 +00004462 QualType T = getDerived().TransformType(E->getTypeOperand());
4463 if (T.isNull())
4464 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004465
Douglas Gregorb98b1992009-08-11 05:31:07 +00004466 if (!getDerived().AlwaysRebuild() &&
4467 T == E->getTypeOperand())
4468 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004469
Douglas Gregorb98b1992009-08-11 05:31:07 +00004470 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4471 /*FIXME:*/E->getLocStart(),
4472 T,
4473 E->getLocEnd());
4474 }
Mike Stump1eb44332009-09-09 15:08:12 +00004475
Douglas Gregorb98b1992009-08-11 05:31:07 +00004476 // We don't know whether the expression is potentially evaluated until
4477 // after we perform semantic analysis, so the expression is potentially
4478 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00004479 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregorb98b1992009-08-11 05:31:07 +00004480 Action::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004481
Douglas Gregorb98b1992009-08-11 05:31:07 +00004482 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4483 if (SubExpr.isInvalid())
4484 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004485
Douglas Gregorb98b1992009-08-11 05:31:07 +00004486 if (!getDerived().AlwaysRebuild() &&
4487 SubExpr.get() == E->getExprOperand())
Mike Stump1eb44332009-09-09 15:08:12 +00004488 return SemaRef.Owned(E->Retain());
4489
Douglas Gregorb98b1992009-08-11 05:31:07 +00004490 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4491 /*FIXME:*/E->getLocStart(),
4492 move(SubExpr),
4493 E->getLocEnd());
4494}
4495
4496template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004497Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004498TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *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
4504TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00004505 CXXNullPtrLiteralExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004506 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004507}
Mike Stump1eb44332009-09-09 15:08:12 +00004508
Douglas Gregorb98b1992009-08-11 05:31:07 +00004509template<typename Derived>
4510Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004511TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004512 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004513
Douglas Gregorb98b1992009-08-11 05:31:07 +00004514 QualType T = getDerived().TransformType(E->getType());
4515 if (T.isNull())
4516 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregorb98b1992009-08-11 05:31:07 +00004518 if (!getDerived().AlwaysRebuild() &&
4519 T == E->getType())
4520 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004521
Douglas Gregor828a1972010-01-07 23:12:05 +00004522 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004523}
Mike Stump1eb44332009-09-09 15:08:12 +00004524
Douglas Gregorb98b1992009-08-11 05:31:07 +00004525template<typename Derived>
4526Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004527TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004528 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4529 if (SubExpr.isInvalid())
4530 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004531
Douglas Gregorb98b1992009-08-11 05:31:07 +00004532 if (!getDerived().AlwaysRebuild() &&
4533 SubExpr.get() == E->getSubExpr())
Mike Stump1eb44332009-09-09 15:08:12 +00004534 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004535
4536 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4537}
Mike Stump1eb44332009-09-09 15:08:12 +00004538
Douglas Gregorb98b1992009-08-11 05:31:07 +00004539template<typename Derived>
4540Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004541TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00004542 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004543 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4544 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004545 if (!Param)
4546 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004547
Chandler Carruth53cb6f82010-02-08 06:42:49 +00004548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00004549 Param == E->getParam())
4550 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004551
Douglas Gregor036aed12009-12-23 23:03:06 +00004552 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004553}
Mike Stump1eb44332009-09-09 15:08:12 +00004554
Douglas Gregorb98b1992009-08-11 05:31:07 +00004555template<typename Derived>
4556Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004557TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004558 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4559
4560 QualType T = getDerived().TransformType(E->getType());
4561 if (T.isNull())
4562 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004563
Douglas Gregorb98b1992009-08-11 05:31:07 +00004564 if (!getDerived().AlwaysRebuild() &&
4565 T == E->getType())
Mike Stump1eb44332009-09-09 15:08:12 +00004566 return SemaRef.Owned(E->Retain());
4567
4568 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004569 /*FIXME:*/E->getTypeBeginLoc(),
4570 T,
4571 E->getRParenLoc());
4572}
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregorb98b1992009-08-11 05:31:07 +00004574template<typename Derived>
4575Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004576TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004577 // Transform the type that we're allocating
4578 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4579 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4580 if (AllocType.isNull())
4581 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004582
Douglas Gregorb98b1992009-08-11 05:31:07 +00004583 // Transform the size of the array we're allocating (if any).
4584 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4585 if (ArraySize.isInvalid())
4586 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004587
Douglas Gregorb98b1992009-08-11 05:31:07 +00004588 // Transform the placement arguments (if any).
4589 bool ArgumentChanged = false;
4590 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4591 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4592 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4593 if (Arg.isInvalid())
4594 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004595
Douglas Gregorb98b1992009-08-11 05:31:07 +00004596 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4597 PlacementArgs.push_back(Arg.take());
4598 }
Mike Stump1eb44332009-09-09 15:08:12 +00004599
Douglas Gregor43959a92009-08-20 07:17:43 +00004600 // transform the constructor arguments (if any).
Douglas Gregorb98b1992009-08-11 05:31:07 +00004601 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4602 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4603 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4604 if (Arg.isInvalid())
4605 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004606
Douglas Gregorb98b1992009-08-11 05:31:07 +00004607 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4608 ConstructorArgs.push_back(Arg.take());
4609 }
Mike Stump1eb44332009-09-09 15:08:12 +00004610
Douglas Gregor1af74512010-02-26 00:38:10 +00004611 // Transform constructor, new operator, and delete operator.
4612 CXXConstructorDecl *Constructor = 0;
4613 if (E->getConstructor()) {
4614 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004615 getDerived().TransformDecl(E->getLocStart(),
4616 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004617 if (!Constructor)
4618 return SemaRef.ExprError();
4619 }
4620
4621 FunctionDecl *OperatorNew = 0;
4622 if (E->getOperatorNew()) {
4623 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004624 getDerived().TransformDecl(E->getLocStart(),
4625 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004626 if (!OperatorNew)
4627 return SemaRef.ExprError();
4628 }
4629
4630 FunctionDecl *OperatorDelete = 0;
4631 if (E->getOperatorDelete()) {
4632 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004633 getDerived().TransformDecl(E->getLocStart(),
4634 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004635 if (!OperatorDelete)
4636 return SemaRef.ExprError();
4637 }
4638
Douglas Gregorb98b1992009-08-11 05:31:07 +00004639 if (!getDerived().AlwaysRebuild() &&
4640 AllocType == E->getAllocatedType() &&
4641 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004642 Constructor == E->getConstructor() &&
4643 OperatorNew == E->getOperatorNew() &&
4644 OperatorDelete == E->getOperatorDelete() &&
4645 !ArgumentChanged) {
4646 // Mark any declarations we need as referenced.
4647 // FIXME: instantiation-specific.
4648 if (Constructor)
4649 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4650 if (OperatorNew)
4651 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4652 if (OperatorDelete)
4653 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004654 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004655 }
Mike Stump1eb44332009-09-09 15:08:12 +00004656
Douglas Gregor5b5ad842009-12-22 17:13:37 +00004657 if (!ArraySize.get()) {
4658 // If no array size was specified, but the new expression was
4659 // instantiated with an array type (e.g., "new T" where T is
4660 // instantiated with "int[4]"), extract the outer bound from the
4661 // array type as our array size. We do this with constant and
4662 // dependently-sized array types.
4663 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4664 if (!ArrayT) {
4665 // Do nothing
4666 } else if (const ConstantArrayType *ConsArrayT
4667 = dyn_cast<ConstantArrayType>(ArrayT)) {
4668 ArraySize
4669 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4670 ConsArrayT->getSize(),
4671 SemaRef.Context.getSizeType(),
4672 /*FIXME:*/E->getLocStart()));
4673 AllocType = ConsArrayT->getElementType();
4674 } else if (const DependentSizedArrayType *DepArrayT
4675 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4676 if (DepArrayT->getSizeExpr()) {
4677 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4678 AllocType = DepArrayT->getElementType();
4679 }
4680 }
4681 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00004682 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4683 E->isGlobalNew(),
4684 /*FIXME:*/E->getLocStart(),
4685 move_arg(PlacementArgs),
4686 /*FIXME:*/E->getLocStart(),
4687 E->isParenTypeId(),
4688 AllocType,
4689 /*FIXME:*/E->getLocStart(),
4690 /*FIXME:*/SourceRange(),
4691 move(ArraySize),
4692 /*FIXME:*/E->getLocStart(),
4693 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00004694 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004695}
Mike Stump1eb44332009-09-09 15:08:12 +00004696
Douglas Gregorb98b1992009-08-11 05:31:07 +00004697template<typename Derived>
4698Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004699TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004700 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4701 if (Operand.isInvalid())
4702 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004703
Douglas Gregor1af74512010-02-26 00:38:10 +00004704 // Transform the delete operator, if known.
4705 FunctionDecl *OperatorDelete = 0;
4706 if (E->getOperatorDelete()) {
4707 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004708 getDerived().TransformDecl(E->getLocStart(),
4709 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00004710 if (!OperatorDelete)
4711 return SemaRef.ExprError();
4712 }
4713
Douglas Gregorb98b1992009-08-11 05:31:07 +00004714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00004715 Operand.get() == E->getArgument() &&
4716 OperatorDelete == E->getOperatorDelete()) {
4717 // Mark any declarations we need as referenced.
4718 // FIXME: instantiation-specific.
4719 if (OperatorDelete)
4720 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump1eb44332009-09-09 15:08:12 +00004721 return SemaRef.Owned(E->Retain());
Douglas Gregor1af74512010-02-26 00:38:10 +00004722 }
Mike Stump1eb44332009-09-09 15:08:12 +00004723
Douglas Gregorb98b1992009-08-11 05:31:07 +00004724 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4725 E->isGlobalDelete(),
4726 E->isArrayForm(),
4727 move(Operand));
4728}
Mike Stump1eb44332009-09-09 15:08:12 +00004729
Douglas Gregorb98b1992009-08-11 05:31:07 +00004730template<typename Derived>
4731Sema::OwningExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00004732TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00004733 CXXPseudoDestructorExpr *E) {
Douglas Gregora71d8192009-09-04 17:36:40 +00004734 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4735 if (Base.isInvalid())
4736 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004737
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004738 Sema::TypeTy *ObjectTypePtr = 0;
4739 bool MayBePseudoDestructor = false;
4740 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4741 E->getOperatorLoc(),
4742 E->isArrow()? tok::arrow : tok::period,
4743 ObjectTypePtr,
4744 MayBePseudoDestructor);
4745 if (Base.isInvalid())
4746 return SemaRef.ExprError();
4747
4748 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregora71d8192009-09-04 17:36:40 +00004749 NestedNameSpecifier *Qualifier
4750 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorb10cd042010-02-21 18:36:56 +00004751 E->getQualifierRange(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004752 ObjectType);
Douglas Gregora71d8192009-09-04 17:36:40 +00004753 if (E->getQualifier() && !Qualifier)
4754 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004755
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004756 PseudoDestructorTypeStorage Destroyed;
4757 if (E->getDestroyedTypeInfo()) {
4758 TypeSourceInfo *DestroyedTypeInfo
4759 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4760 if (!DestroyedTypeInfo)
4761 return SemaRef.ExprError();
4762 Destroyed = DestroyedTypeInfo;
4763 } else if (ObjectType->isDependentType()) {
4764 // We aren't likely to be able to resolve the identifier down to a type
4765 // now anyway, so just retain the identifier.
4766 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4767 E->getDestroyedTypeLoc());
4768 } else {
4769 // Look for a destructor known with the given name.
4770 CXXScopeSpec SS;
4771 if (Qualifier) {
4772 SS.setScopeRep(Qualifier);
4773 SS.setRange(E->getQualifierRange());
4774 }
4775
4776 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4777 *E->getDestroyedTypeIdentifier(),
4778 E->getDestroyedTypeLoc(),
4779 /*Scope=*/0,
4780 SS, ObjectTypePtr,
4781 false);
4782 if (!T)
4783 return SemaRef.ExprError();
4784
4785 Destroyed
4786 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4787 E->getDestroyedTypeLoc());
4788 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004789
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004790 TypeSourceInfo *ScopeTypeInfo = 0;
4791 if (E->getScopeTypeInfo()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004792 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4793 ObjectType);
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004794 if (!ScopeTypeInfo)
Douglas Gregora71d8192009-09-04 17:36:40 +00004795 return SemaRef.ExprError();
4796 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004797
Douglas Gregora71d8192009-09-04 17:36:40 +00004798 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4799 E->getOperatorLoc(),
4800 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00004801 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00004802 E->getQualifierRange(),
4803 ScopeTypeInfo,
4804 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00004805 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00004806 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00004807}
Mike Stump1eb44332009-09-09 15:08:12 +00004808
Douglas Gregora71d8192009-09-04 17:36:40 +00004809template<typename Derived>
4810Sema::OwningExprResult
John McCallba135432009-11-21 08:51:07 +00004811TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00004812 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00004813 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4814
4815 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4816 Sema::LookupOrdinaryName);
4817
4818 // Transform all the decls.
4819 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4820 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004821 NamedDecl *InstD = static_cast<NamedDecl*>(
4822 getDerived().TransformDecl(Old->getNameLoc(),
4823 *I));
John McCall9f54ad42009-12-10 09:41:52 +00004824 if (!InstD) {
4825 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4826 // This can happen because of dependent hiding.
4827 if (isa<UsingShadowDecl>(*I))
4828 continue;
4829 else
4830 return SemaRef.ExprError();
4831 }
John McCallf7a1a742009-11-24 19:00:30 +00004832
4833 // Expand using declarations.
4834 if (isa<UsingDecl>(InstD)) {
4835 UsingDecl *UD = cast<UsingDecl>(InstD);
4836 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4837 E = UD->shadow_end(); I != E; ++I)
4838 R.addDecl(*I);
4839 continue;
4840 }
4841
4842 R.addDecl(InstD);
4843 }
4844
4845 // Resolve a kind, but don't do any further analysis. If it's
4846 // ambiguous, the callee needs to deal with it.
4847 R.resolveKind();
4848
4849 // Rebuild the nested-name qualifier, if present.
4850 CXXScopeSpec SS;
4851 NestedNameSpecifier *Qualifier = 0;
4852 if (Old->getQualifier()) {
4853 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004854 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00004855 if (!Qualifier)
4856 return SemaRef.ExprError();
4857
4858 SS.setScopeRep(Qualifier);
4859 SS.setRange(Old->getQualifierRange());
4860 }
4861
4862 // If we have no template arguments, it's a normal declaration name.
4863 if (!Old->hasExplicitTemplateArgs())
4864 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4865
4866 // If we have template arguments, rebuild them, then rebuild the
4867 // templateid expression.
4868 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4869 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4870 TemplateArgumentLoc Loc;
4871 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4872 return SemaRef.ExprError();
4873 TransArgs.addArgument(Loc);
4874 }
4875
4876 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4877 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004878}
Mike Stump1eb44332009-09-09 15:08:12 +00004879
Douglas Gregorb98b1992009-08-11 05:31:07 +00004880template<typename Derived>
4881Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004882TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004883 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump1eb44332009-09-09 15:08:12 +00004884
Douglas Gregorb98b1992009-08-11 05:31:07 +00004885 QualType T = getDerived().TransformType(E->getQueriedType());
4886 if (T.isNull())
4887 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004888
Douglas Gregorb98b1992009-08-11 05:31:07 +00004889 if (!getDerived().AlwaysRebuild() &&
4890 T == E->getQueriedType())
4891 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004892
Douglas Gregorb98b1992009-08-11 05:31:07 +00004893 // FIXME: Bad location information
4894 SourceLocation FakeLParenLoc
4895 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump1eb44332009-09-09 15:08:12 +00004896
4897 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004898 E->getLocStart(),
4899 /*FIXME:*/FakeLParenLoc,
4900 T,
4901 E->getLocEnd());
4902}
Mike Stump1eb44332009-09-09 15:08:12 +00004903
Douglas Gregorb98b1992009-08-11 05:31:07 +00004904template<typename Derived>
4905Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00004906TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall454feb92009-12-08 09:21:05 +00004907 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00004908 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00004909 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00004910 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004911 if (!NNS)
4912 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004913
4914 DeclarationName Name
Douglas Gregor81499bb2009-09-03 22:13:48 +00004915 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4916 if (!Name)
4917 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004918
John McCallf7a1a742009-11-24 19:00:30 +00004919 if (!E->hasExplicitTemplateArgs()) {
4920 if (!getDerived().AlwaysRebuild() &&
4921 NNS == E->getQualifier() &&
4922 Name == E->getDeclName())
4923 return SemaRef.Owned(E->Retain());
Mike Stump1eb44332009-09-09 15:08:12 +00004924
John McCallf7a1a742009-11-24 19:00:30 +00004925 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4926 E->getQualifierRange(),
4927 Name, E->getLocation(),
4928 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00004929 }
John McCalld5532b62009-11-23 01:53:49 +00004930
4931 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00004932 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00004933 TemplateArgumentLoc Loc;
4934 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb98b1992009-08-11 05:31:07 +00004935 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00004936 TransArgs.addArgument(Loc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004937 }
4938
John McCallf7a1a742009-11-24 19:00:30 +00004939 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4940 E->getQualifierRange(),
4941 Name, E->getLocation(),
4942 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004943}
4944
4945template<typename Derived>
4946Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00004947TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00004948 // CXXConstructExprs are always implicit, so when we have a
4949 // 1-argument construction we just transform that argument.
4950 if (E->getNumArgs() == 1 ||
4951 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4952 return getDerived().TransformExpr(E->getArg(0));
4953
Douglas Gregorb98b1992009-08-11 05:31:07 +00004954 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4955
4956 QualType T = getDerived().TransformType(E->getType());
4957 if (T.isNull())
4958 return SemaRef.ExprError();
4959
4960 CXXConstructorDecl *Constructor
4961 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004962 getDerived().TransformDecl(E->getLocStart(),
4963 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00004964 if (!Constructor)
4965 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregorb98b1992009-08-11 05:31:07 +00004967 bool ArgumentChanged = false;
4968 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump1eb44332009-09-09 15:08:12 +00004969 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004970 ArgEnd = E->arg_end();
4971 Arg != ArgEnd; ++Arg) {
Douglas Gregor6eef5192009-12-14 19:27:10 +00004972 if (getDerived().DropCallArgument(*Arg)) {
4973 ArgumentChanged = true;
4974 break;
4975 }
4976
Douglas Gregorb98b1992009-08-11 05:31:07 +00004977 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4978 if (TransArg.isInvalid())
4979 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregorb98b1992009-08-11 05:31:07 +00004981 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4982 Args.push_back(TransArg.takeAs<Expr>());
4983 }
4984
4985 if (!getDerived().AlwaysRebuild() &&
4986 T == E->getType() &&
4987 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00004988 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00004989 // Mark the constructor as referenced.
4990 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00004991 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00004992 return SemaRef.Owned(E->Retain());
Douglas Gregorc845aad2010-02-26 00:01:57 +00004993 }
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregor4411d2e2009-12-14 16:27:04 +00004995 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4996 Constructor, E->isElidable(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00004997 move_arg(Args));
4998}
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregorb98b1992009-08-11 05:31:07 +00005000/// \brief Transform a C++ temporary-binding expression.
5001///
Douglas Gregor51326552009-12-24 18:51:59 +00005002/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5003/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005004template<typename Derived>
5005Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005006TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00005007 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005008}
Mike Stump1eb44332009-09-09 15:08:12 +00005009
Anders Carlssoneb60edf2010-01-29 02:39:32 +00005010/// \brief Transform a C++ reference-binding expression.
5011///
5012/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5013/// transform the subexpression and return that.
5014template<typename Derived>
5015Sema::OwningExprResult
5016TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5017 return getDerived().TransformExpr(E->getSubExpr());
5018}
5019
Mike Stump1eb44332009-09-09 15:08:12 +00005020/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregorb98b1992009-08-11 05:31:07 +00005021/// be destroyed after the expression is evaluated.
5022///
Douglas Gregor51326552009-12-24 18:51:59 +00005023/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5024/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00005025template<typename Derived>
5026Sema::OwningExprResult
5027TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor51326552009-12-24 18:51:59 +00005028 CXXExprWithTemporaries *E) {
5029 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030}
Mike Stump1eb44332009-09-09 15:08:12 +00005031
Douglas Gregorb98b1992009-08-11 05:31:07 +00005032template<typename Derived>
5033Sema::OwningExprResult
5034TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall454feb92009-12-08 09:21:05 +00005035 CXXTemporaryObjectExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005036 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5037 QualType T = getDerived().TransformType(E->getType());
5038 if (T.isNull())
5039 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005040
Douglas Gregorb98b1992009-08-11 05:31:07 +00005041 CXXConstructorDecl *Constructor
5042 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005043 getDerived().TransformDecl(E->getLocStart(),
5044 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005045 if (!Constructor)
5046 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Douglas Gregorb98b1992009-08-11 05:31:07 +00005048 bool ArgumentChanged = false;
5049 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5050 Args.reserve(E->getNumArgs());
Mike Stump1eb44332009-09-09 15:08:12 +00005051 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005052 ArgEnd = E->arg_end();
5053 Arg != ArgEnd; ++Arg) {
Douglas Gregor91be6f52010-03-02 17:18:33 +00005054 if (getDerived().DropCallArgument(*Arg)) {
5055 ArgumentChanged = true;
5056 break;
5057 }
5058
Douglas Gregorb98b1992009-08-11 05:31:07 +00005059 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5060 if (TransArg.isInvalid())
5061 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005062
Douglas Gregorb98b1992009-08-11 05:31:07 +00005063 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5064 Args.push_back((Expr *)TransArg.release());
5065 }
Mike Stump1eb44332009-09-09 15:08:12 +00005066
Douglas Gregorb98b1992009-08-11 05:31:07 +00005067 if (!getDerived().AlwaysRebuild() &&
5068 T == E->getType() &&
5069 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00005070 !ArgumentChanged) {
5071 // FIXME: Instantiation-specific
5072 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005073 return SemaRef.Owned(E->Retain());
Douglas Gregor91be6f52010-03-02 17:18:33 +00005074 }
Mike Stump1eb44332009-09-09 15:08:12 +00005075
Douglas Gregorb98b1992009-08-11 05:31:07 +00005076 // FIXME: Bogus location information
5077 SourceLocation CommaLoc;
5078 if (Args.size() > 1) {
5079 Expr *First = (Expr *)Args[0];
Mike Stump1eb44332009-09-09 15:08:12 +00005080 CommaLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005081 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5082 }
5083 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5084 T,
5085 /*FIXME:*/E->getTypeBeginLoc(),
5086 move_arg(Args),
5087 &CommaLoc,
5088 E->getLocEnd());
5089}
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregorb98b1992009-08-11 05:31:07 +00005091template<typename Derived>
5092Sema::OwningExprResult
5093TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00005094 CXXUnresolvedConstructExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005095 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5096 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5097 if (T.isNull())
5098 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005099
Douglas Gregorb98b1992009-08-11 05:31:07 +00005100 bool ArgumentChanged = false;
5101 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5102 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5103 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5104 ArgEnd = E->arg_end();
5105 Arg != ArgEnd; ++Arg) {
5106 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5107 if (TransArg.isInvalid())
5108 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005109
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5111 FakeCommaLocs.push_back(
5112 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5113 Args.push_back(TransArg.takeAs<Expr>());
5114 }
Mike Stump1eb44332009-09-09 15:08:12 +00005115
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 if (!getDerived().AlwaysRebuild() &&
5117 T == E->getTypeAsWritten() &&
5118 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005119 return SemaRef.Owned(E->Retain());
5120
Douglas Gregorb98b1992009-08-11 05:31:07 +00005121 // FIXME: we're faking the locations of the commas
5122 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5123 T,
5124 E->getLParenLoc(),
5125 move_arg(Args),
5126 FakeCommaLocs.data(),
5127 E->getRParenLoc());
5128}
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregorb98b1992009-08-11 05:31:07 +00005130template<typename Derived>
5131Sema::OwningExprResult
John McCall865d4472009-11-19 22:55:06 +00005132TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall454feb92009-12-08 09:21:05 +00005133 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005134 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005135 OwningExprResult Base(SemaRef, (Expr*) 0);
5136 Expr *OldBase;
5137 QualType BaseType;
5138 QualType ObjectType;
5139 if (!E->isImplicitAccess()) {
5140 OldBase = E->getBase();
5141 Base = getDerived().TransformExpr(OldBase);
5142 if (Base.isInvalid())
5143 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005144
John McCallaa81e162009-12-01 22:10:20 +00005145 // Start the member reference and compute the object's type.
5146 Sema::TypeTy *ObjectTy = 0;
Douglas Gregord4dca082010-02-24 18:44:31 +00005147 bool MayBePseudoDestructor = false;
John McCallaa81e162009-12-01 22:10:20 +00005148 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5149 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005150 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00005151 ObjectTy,
5152 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00005153 if (Base.isInvalid())
5154 return SemaRef.ExprError();
5155
5156 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5157 BaseType = ((Expr*) Base.get())->getType();
5158 } else {
5159 OldBase = 0;
5160 BaseType = getDerived().TransformType(E->getBaseType());
5161 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5162 }
Mike Stump1eb44332009-09-09 15:08:12 +00005163
Douglas Gregor6cd21982009-10-20 05:58:46 +00005164 // Transform the first part of the nested-name-specifier that qualifies
5165 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00005166 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00005167 = getDerived().TransformFirstQualifierInScope(
5168 E->getFirstQualifierFoundInScope(),
5169 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005170
Douglas Gregora38c6872009-09-03 16:14:30 +00005171 NestedNameSpecifier *Qualifier = 0;
5172 if (E->getQualifier()) {
5173 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5174 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00005175 ObjectType,
5176 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00005177 if (!Qualifier)
5178 return SemaRef.ExprError();
5179 }
Mike Stump1eb44332009-09-09 15:08:12 +00005180
5181 DeclarationName Name
Douglas Gregordd62b152009-10-19 22:04:39 +00005182 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCallaa81e162009-12-01 22:10:20 +00005183 ObjectType);
Douglas Gregor81499bb2009-09-03 22:13:48 +00005184 if (!Name)
5185 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005186
John McCallaa81e162009-12-01 22:10:20 +00005187 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005188 // This is a reference to a member without an explicitly-specified
5189 // template argument list. Optimize for this common case.
5190 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00005191 Base.get() == OldBase &&
5192 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005193 Qualifier == E->getQualifier() &&
5194 Name == E->getMember() &&
5195 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump1eb44332009-09-09 15:08:12 +00005196 return SemaRef.Owned(E->Retain());
5197
John McCall865d4472009-11-19 22:55:06 +00005198 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005199 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005200 E->isArrow(),
5201 E->getOperatorLoc(),
5202 Qualifier,
5203 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00005204 FirstQualifierInScope,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005205 Name,
5206 E->getMemberLoc(),
John McCall129e2df2009-11-30 22:42:35 +00005207 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005208 }
5209
John McCalld5532b62009-11-23 01:53:49 +00005210 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005211 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCalld5532b62009-11-23 01:53:49 +00005212 TemplateArgumentLoc Loc;
5213 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005214 return SemaRef.ExprError();
John McCalld5532b62009-11-23 01:53:49 +00005215 TransArgs.addArgument(Loc);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005216 }
Mike Stump1eb44332009-09-09 15:08:12 +00005217
John McCall865d4472009-11-19 22:55:06 +00005218 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005219 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220 E->isArrow(),
5221 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00005222 Qualifier,
5223 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005224 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005225 Name,
5226 E->getMemberLoc(),
5227 &TransArgs);
5228}
5229
5230template<typename Derived>
5231Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005232TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00005233 // Transform the base of the expression.
John McCallaa81e162009-12-01 22:10:20 +00005234 OwningExprResult Base(SemaRef, (Expr*) 0);
5235 QualType BaseType;
5236 if (!Old->isImplicitAccess()) {
5237 Base = getDerived().TransformExpr(Old->getBase());
5238 if (Base.isInvalid())
5239 return SemaRef.ExprError();
5240 BaseType = ((Expr*) Base.get())->getType();
5241 } else {
5242 BaseType = getDerived().TransformType(Old->getBaseType());
5243 }
John McCall129e2df2009-11-30 22:42:35 +00005244
5245 NestedNameSpecifier *Qualifier = 0;
5246 if (Old->getQualifier()) {
5247 Qualifier
5248 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005249 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00005250 if (Qualifier == 0)
5251 return SemaRef.ExprError();
5252 }
5253
5254 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5255 Sema::LookupOrdinaryName);
5256
5257 // Transform all the decls.
5258 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5259 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005260 NamedDecl *InstD = static_cast<NamedDecl*>(
5261 getDerived().TransformDecl(Old->getMemberLoc(),
5262 *I));
John McCall9f54ad42009-12-10 09:41:52 +00005263 if (!InstD) {
5264 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5265 // This can happen because of dependent hiding.
5266 if (isa<UsingShadowDecl>(*I))
5267 continue;
5268 else
5269 return SemaRef.ExprError();
5270 }
John McCall129e2df2009-11-30 22:42:35 +00005271
5272 // Expand using declarations.
5273 if (isa<UsingDecl>(InstD)) {
5274 UsingDecl *UD = cast<UsingDecl>(InstD);
5275 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5276 E = UD->shadow_end(); I != E; ++I)
5277 R.addDecl(*I);
5278 continue;
5279 }
5280
5281 R.addDecl(InstD);
5282 }
5283
5284 R.resolveKind();
5285
5286 TemplateArgumentListInfo TransArgs;
5287 if (Old->hasExplicitTemplateArgs()) {
5288 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5289 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5290 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5291 TemplateArgumentLoc Loc;
5292 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5293 Loc))
5294 return SemaRef.ExprError();
5295 TransArgs.addArgument(Loc);
5296 }
5297 }
John McCallc2233c52010-01-15 08:34:02 +00005298
5299 // FIXME: to do this check properly, we will need to preserve the
5300 // first-qualifier-in-scope here, just in case we had a dependent
5301 // base (and therefore couldn't do the check) and a
5302 // nested-name-qualifier (and therefore could do the lookup).
5303 NamedDecl *FirstQualifierInScope = 0;
John McCall129e2df2009-11-30 22:42:35 +00005304
5305 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCallaa81e162009-12-01 22:10:20 +00005306 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00005307 Old->getOperatorLoc(),
5308 Old->isArrow(),
5309 Qualifier,
5310 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00005311 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00005312 R,
5313 (Old->hasExplicitTemplateArgs()
5314 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005315}
5316
5317template<typename Derived>
5318Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005319TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005320 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005321}
5322
Mike Stump1eb44332009-09-09 15:08:12 +00005323template<typename Derived>
5324Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005325TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005326 // FIXME: poor source location
5327 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5328 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5329 if (EncodedType.isNull())
5330 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregorb98b1992009-08-11 05:31:07 +00005332 if (!getDerived().AlwaysRebuild() &&
5333 EncodedType == E->getEncodedType())
Mike Stump1eb44332009-09-09 15:08:12 +00005334 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005335
5336 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5337 EncodedType,
5338 E->getRParenLoc());
5339}
Mike Stump1eb44332009-09-09 15:08:12 +00005340
Douglas Gregorb98b1992009-08-11 05:31:07 +00005341template<typename Derived>
5342Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005343TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005344 // FIXME: Implement this!
5345 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005346 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005347}
5348
Mike Stump1eb44332009-09-09 15:08:12 +00005349template<typename Derived>
5350Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005351TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005352 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005353}
5354
Mike Stump1eb44332009-09-09 15:08:12 +00005355template<typename Derived>
5356Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005358 ObjCProtocolDecl *Protocol
Douglas Gregorb98b1992009-08-11 05:31:07 +00005359 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005360 getDerived().TransformDecl(E->getLocStart(),
5361 E->getProtocol()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005362 if (!Protocol)
5363 return SemaRef.ExprError();
5364
5365 if (!getDerived().AlwaysRebuild() &&
5366 Protocol == E->getProtocol())
Mike Stump1eb44332009-09-09 15:08:12 +00005367 return SemaRef.Owned(E->Retain());
5368
Douglas Gregorb98b1992009-08-11 05:31:07 +00005369 return getDerived().RebuildObjCProtocolExpr(Protocol,
5370 E->getAtLoc(),
5371 /*FIXME:*/E->getAtLoc(),
5372 /*FIXME:*/E->getAtLoc(),
5373 E->getRParenLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00005374
Douglas Gregorb98b1992009-08-11 05:31:07 +00005375}
5376
Mike Stump1eb44332009-09-09 15:08:12 +00005377template<typename Derived>
5378Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005379TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005380 // FIXME: Implement this!
5381 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005382 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005383}
5384
Mike Stump1eb44332009-09-09 15:08:12 +00005385template<typename Derived>
5386Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005387TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005388 // FIXME: Implement this!
5389 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005390 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005391}
5392
Mike Stump1eb44332009-09-09 15:08:12 +00005393template<typename Derived>
5394Sema::OwningExprResult
Fariborz Jahanian09105f52009-08-20 17:02:02 +00005395TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall454feb92009-12-08 09:21:05 +00005396 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005397 // FIXME: Implement this!
5398 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005399 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005400}
5401
Mike Stump1eb44332009-09-09 15:08:12 +00005402template<typename Derived>
5403Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005404TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005405 // FIXME: Implement this!
5406 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005407 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408}
5409
Mike Stump1eb44332009-09-09 15:08:12 +00005410template<typename Derived>
5411Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005413 // FIXME: Implement this!
5414 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005415 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005416}
5417
Mike Stump1eb44332009-09-09 15:08:12 +00005418template<typename Derived>
5419Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005420TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005421 bool ArgumentChanged = false;
5422 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5423 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5424 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5425 if (SubExpr.isInvalid())
5426 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005427
Douglas Gregorb98b1992009-08-11 05:31:07 +00005428 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5429 SubExprs.push_back(SubExpr.takeAs<Expr>());
5430 }
Mike Stump1eb44332009-09-09 15:08:12 +00005431
Douglas Gregorb98b1992009-08-11 05:31:07 +00005432 if (!getDerived().AlwaysRebuild() &&
5433 !ArgumentChanged)
Mike Stump1eb44332009-09-09 15:08:12 +00005434 return SemaRef.Owned(E->Retain());
5435
Douglas Gregorb98b1992009-08-11 05:31:07 +00005436 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5437 move_arg(SubExprs),
5438 E->getRParenLoc());
5439}
5440
Mike Stump1eb44332009-09-09 15:08:12 +00005441template<typename Derived>
5442Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005443TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005444 // FIXME: Implement this!
5445 assert(false && "Cannot transform block expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005446 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005447}
5448
Mike Stump1eb44332009-09-09 15:08:12 +00005449template<typename Derived>
5450Sema::OwningExprResult
John McCall454feb92009-12-08 09:21:05 +00005451TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005452 // FIXME: Implement this!
5453 assert(false && "Cannot transform block-related expressions yet");
Mike Stump1eb44332009-09-09 15:08:12 +00005454 return SemaRef.Owned(E->Retain());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005455}
Mike Stump1eb44332009-09-09 15:08:12 +00005456
Douglas Gregorb98b1992009-08-11 05:31:07 +00005457//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00005458// Type reconstruction
5459//===----------------------------------------------------------------------===//
5460
Mike Stump1eb44332009-09-09 15:08:12 +00005461template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005462QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5463 SourceLocation Star) {
5464 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005465 getDerived().getBaseEntity());
5466}
5467
Mike Stump1eb44332009-09-09 15:08:12 +00005468template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00005469QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5470 SourceLocation Star) {
5471 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005472 getDerived().getBaseEntity());
5473}
5474
Mike Stump1eb44332009-09-09 15:08:12 +00005475template<typename Derived>
5476QualType
John McCall85737a72009-10-30 00:06:24 +00005477TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5478 bool WrittenAsLValue,
5479 SourceLocation Sigil) {
5480 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5481 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005482}
5483
5484template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005485QualType
John McCall85737a72009-10-30 00:06:24 +00005486TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5487 QualType ClassType,
5488 SourceLocation Sigil) {
John McCall0953e762009-09-24 19:53:00 +00005489 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall85737a72009-10-30 00:06:24 +00005490 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005491}
5492
5493template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005494QualType
John McCall85737a72009-10-30 00:06:24 +00005495TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5496 SourceLocation Sigil) {
5497 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCalla2becad2009-10-21 00:40:46 +00005498 getDerived().getBaseEntity());
5499}
5500
5501template<typename Derived>
5502QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00005503TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5504 ArrayType::ArraySizeModifier SizeMod,
5505 const llvm::APInt *Size,
5506 Expr *SizeExpr,
5507 unsigned IndexTypeQuals,
5508 SourceRange BracketsRange) {
5509 if (SizeExpr || !Size)
5510 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5511 IndexTypeQuals, BracketsRange,
5512 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00005513
5514 QualType Types[] = {
5515 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5516 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5517 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00005518 };
5519 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5520 QualType SizeType;
5521 for (unsigned I = 0; I != NumTypes; ++I)
5522 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5523 SizeType = Types[I];
5524 break;
5525 }
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor577f75a2009-08-04 16:50:30 +00005527 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00005528 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005529 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00005530 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00005531}
Mike Stump1eb44332009-09-09 15:08:12 +00005532
Douglas Gregor577f75a2009-08-04 16:50:30 +00005533template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005534QualType
5535TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005536 ArrayType::ArraySizeModifier SizeMod,
5537 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00005538 unsigned IndexTypeQuals,
5539 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005540 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00005541 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005542}
5543
5544template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005545QualType
Mike Stump1eb44332009-09-09 15:08:12 +00005546TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005547 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00005548 unsigned IndexTypeQuals,
5549 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005550 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00005551 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005552}
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor577f75a2009-08-04 16:50:30 +00005554template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005555QualType
5556TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005557 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005558 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005559 unsigned IndexTypeQuals,
5560 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005561 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005562 SizeExpr.takeAs<Expr>(),
5563 IndexTypeQuals, BracketsRange);
5564}
5565
5566template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005567QualType
5568TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005569 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005570 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005571 unsigned IndexTypeQuals,
5572 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00005573 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005574 SizeExpr.takeAs<Expr>(),
5575 IndexTypeQuals, BracketsRange);
5576}
5577
5578template<typename Derived>
5579QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson82287d12010-02-05 00:12:22 +00005580 unsigned NumElements,
5581 bool IsAltiVec, bool IsPixel) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005582 // FIXME: semantic checking!
John Thompson82287d12010-02-05 00:12:22 +00005583 return SemaRef.Context.getVectorType(ElementType, NumElements,
5584 IsAltiVec, IsPixel);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005585}
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregor577f75a2009-08-04 16:50:30 +00005587template<typename Derived>
5588QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5589 unsigned NumElements,
5590 SourceLocation AttributeLoc) {
5591 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5592 NumElements, true);
5593 IntegerLiteral *VectorSize
Mike Stump1eb44332009-09-09 15:08:12 +00005594 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005595 AttributeLoc);
5596 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5597 AttributeLoc);
5598}
Mike Stump1eb44332009-09-09 15:08:12 +00005599
Douglas Gregor577f75a2009-08-04 16:50:30 +00005600template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005601QualType
5602TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005603 ExprArg SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005604 SourceLocation AttributeLoc) {
5605 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5606}
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Douglas Gregor577f75a2009-08-04 16:50:30 +00005608template<typename Derived>
5609QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00005610 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005611 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00005612 bool Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005613 unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +00005614 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00005615 Quals,
5616 getDerived().getBaseLocation(),
5617 getDerived().getBaseEntity());
5618}
Mike Stump1eb44332009-09-09 15:08:12 +00005619
Douglas Gregor577f75a2009-08-04 16:50:30 +00005620template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00005621QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5622 return SemaRef.Context.getFunctionNoProtoType(T);
5623}
5624
5625template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00005626QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5627 assert(D && "no decl found");
5628 if (D->isInvalidDecl()) return QualType();
5629
5630 TypeDecl *Ty;
5631 if (isa<UsingDecl>(D)) {
5632 UsingDecl *Using = cast<UsingDecl>(D);
5633 assert(Using->isTypeName() &&
5634 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5635
5636 // A valid resolved using typename decl points to exactly one type decl.
5637 assert(++Using->shadow_begin() == Using->shadow_end());
5638 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5639
5640 } else {
5641 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5642 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5643 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5644 }
5645
5646 return SemaRef.Context.getTypeDeclType(Ty);
5647}
5648
5649template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005651 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5652}
5653
5654template<typename Derived>
5655QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5656 return SemaRef.Context.getTypeOfType(Underlying);
5657}
5658
5659template<typename Derived>
Douglas Gregorb98b1992009-08-11 05:31:07 +00005660QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00005661 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5662}
5663
5664template<typename Derived>
5665QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00005666 TemplateName Template,
5667 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00005668 const TemplateArgumentListInfo &TemplateArgs) {
5669 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00005670}
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregordcee1a12009-08-06 05:28:30 +00005672template<typename Derived>
5673NestedNameSpecifier *
5674TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5675 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00005676 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005677 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00005678 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00005679 CXXScopeSpec SS;
5680 // FIXME: The source location information is all wrong.
5681 SS.setRange(Range);
5682 SS.setScopeRep(Prefix);
5683 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00005684 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00005685 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00005686 ObjectType,
5687 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00005688 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00005689}
5690
5691template<typename Derived>
5692NestedNameSpecifier *
5693TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5694 SourceRange Range,
5695 NamespaceDecl *NS) {
5696 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5697}
5698
5699template<typename Derived>
5700NestedNameSpecifier *
5701TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5702 SourceRange Range,
5703 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00005704 QualType T) {
5705 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00005706 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00005707 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00005708 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5709 T.getTypePtr());
5710 }
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Douglas Gregordcee1a12009-08-06 05:28:30 +00005712 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5713 return 0;
5714}
Mike Stump1eb44332009-09-09 15:08:12 +00005715
Douglas Gregord1067e52009-08-06 06:41:21 +00005716template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005717TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005718TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5719 bool TemplateKW,
5720 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00005721 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00005722 Template);
5723}
5724
5725template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005726TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00005727TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005728 const IdentifierInfo &II,
5729 QualType ObjectType) {
Douglas Gregord1067e52009-08-06 06:41:21 +00005730 CXXScopeSpec SS;
5731 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump1eb44332009-09-09 15:08:12 +00005732 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00005733 UnqualifiedId Name;
5734 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005735 return getSema().ActOnDependentTemplateName(
5736 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005737 SS,
Douglas Gregor014e88d2009-11-03 23:16:33 +00005738 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005739 ObjectType.getAsOpaquePtr(),
5740 /*EnteringContext=*/false)
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00005741 .template getAsVal<TemplateName>();
Douglas Gregord1067e52009-08-06 06:41:21 +00005742}
Mike Stump1eb44332009-09-09 15:08:12 +00005743
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005745TemplateName
5746TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5747 OverloadedOperatorKind Operator,
5748 QualType ObjectType) {
5749 CXXScopeSpec SS;
5750 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5751 SS.setScopeRep(Qualifier);
5752 UnqualifiedId Name;
5753 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5754 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5755 Operator, SymbolLocations);
5756 return getSema().ActOnDependentTemplateName(
5757 /*FIXME:*/getDerived().getBaseLocation(),
5758 SS,
5759 Name,
Douglas Gregora481edb2009-11-20 23:39:24 +00005760 ObjectType.getAsOpaquePtr(),
5761 /*EnteringContext=*/false)
Douglas Gregorca1bdd72009-11-04 00:56:37 +00005762 .template getAsVal<TemplateName>();
5763}
5764
5765template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00005766Sema::OwningExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005767TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5768 SourceLocation OpLoc,
5769 ExprArg Callee,
5770 ExprArg First,
5771 ExprArg Second) {
5772 Expr *FirstExpr = (Expr *)First.get();
5773 Expr *SecondExpr = (Expr *)Second.get();
John McCallba135432009-11-21 08:51:07 +00005774 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00005776
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00005778 if (Op == OO_Subscript) {
5779 if (!FirstExpr->getType()->isOverloadableType() &&
5780 !SecondExpr->getType()->isOverloadableType())
5781 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCallba135432009-11-21 08:51:07 +00005782 CalleeExpr->getLocStart(),
Sebastian Redlf322ed62009-10-29 20:17:01 +00005783 move(Second), OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00005784 } else if (Op == OO_Arrow) {
5785 // -> is never a builtin operation.
5786 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redlf322ed62009-10-29 20:17:01 +00005787 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005788 if (!FirstExpr->getType()->isOverloadableType()) {
5789 // The argument is not of overloadable type, so try to create a
5790 // built-in unary operation.
Mike Stump1eb44332009-09-09 15:08:12 +00005791 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00005793
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5795 }
5796 } else {
Mike Stump1eb44332009-09-09 15:08:12 +00005797 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798 !SecondExpr->getType()->isOverloadableType()) {
5799 // Neither of the arguments is an overloadable type, so try to
5800 // create a built-in binary operation.
5801 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005802 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005803 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5804 if (Result.isInvalid())
5805 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807 First.release();
5808 Second.release();
5809 return move(Result);
5810 }
5811 }
Mike Stump1eb44332009-09-09 15:08:12 +00005812
5813 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00005815 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00005816
John McCallba135432009-11-21 08:51:07 +00005817 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5818 assert(ULE->requiresADL());
5819
5820 // FIXME: Do we have to check
5821 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00005822 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00005823 } else {
John McCall6e266892010-01-26 03:27:55 +00005824 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCallba135432009-11-21 08:51:07 +00005825 }
Mike Stump1eb44332009-09-09 15:08:12 +00005826
Douglas Gregorb98b1992009-08-11 05:31:07 +00005827 // Add any functions found via argument-dependent lookup.
5828 Expr *Args[2] = { FirstExpr, SecondExpr };
5829 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00005830
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831 // Create the overloaded operator invocation for unary operators.
5832 if (NumArgs == 1 || isPostIncDec) {
Mike Stump1eb44332009-09-09 15:08:12 +00005833 UnaryOperator::Opcode Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5835 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5836 }
Mike Stump1eb44332009-09-09 15:08:12 +00005837
Sebastian Redlf322ed62009-10-29 20:17:01 +00005838 if (Op == OO_Subscript)
John McCallba135432009-11-21 08:51:07 +00005839 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5840 OpLoc,
5841 move(First),
5842 move(Second));
Sebastian Redlf322ed62009-10-29 20:17:01 +00005843
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844 // Create the overloaded operator invocation for binary operators.
Mike Stump1eb44332009-09-09 15:08:12 +00005845 BinaryOperator::Opcode Opc =
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump1eb44332009-09-09 15:08:12 +00005847 OwningExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00005848 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5849 if (Result.isInvalid())
5850 return SemaRef.ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852 First.release();
5853 Second.release();
Mike Stump1eb44332009-09-09 15:08:12 +00005854 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005855}
Mike Stump1eb44332009-09-09 15:08:12 +00005856
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005857template<typename Derived>
5858Sema::OwningExprResult
5859TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5860 SourceLocation OperatorLoc,
5861 bool isArrow,
5862 NestedNameSpecifier *Qualifier,
5863 SourceRange QualifierRange,
5864 TypeSourceInfo *ScopeType,
5865 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005866 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005867 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005868 CXXScopeSpec SS;
5869 if (Qualifier) {
5870 SS.setRange(QualifierRange);
5871 SS.setScopeRep(Qualifier);
5872 }
5873
5874 Expr *BaseE = (Expr *)Base.get();
5875 QualType BaseType = BaseE->getType();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005876 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005877 (!isArrow && !BaseType->getAs<RecordType>()) ||
5878 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00005879 !BaseType->getAs<PointerType>()->getPointeeType()
5880 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005881 // This pseudo-destructor expression is still a pseudo-destructor.
5882 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5883 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00005884 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005885 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005886 /*FIXME?*/true);
5887 }
5888
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005889 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005890 DeclarationName Name
5891 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5892 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5893
5894 // FIXME: the ScopeType should be tacked onto SS.
5895
5896 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5897 OperatorLoc, isArrow,
5898 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00005899 Name, Destroyed.getLocation(),
Douglas Gregor26d4ac92010-02-24 23:40:28 +00005900 /*TemplateArgs*/ 0);
5901}
5902
Douglas Gregor577f75a2009-08-04 16:50:30 +00005903} // end namespace clang
5904
5905#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H