blob: 17f94193fed4bc0ddb4c876575d24241255b91ce [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-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 Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-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 McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-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 Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-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 Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-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 Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-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 Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-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 McCallbcd03502009-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 McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
Douglas Gregorfe17d252010-02-16 19:09:40 +0000318 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
319 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000320
Douglas Gregorc59e5612009-10-19 22:04:39 +0000321 QualType
322 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
323 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000324
Douglas Gregorebe10102009-08-20 07:17:43 +0000325 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000326
Douglas Gregorebe10102009-08-20 07:17:43 +0000327#define STMT(Node, Parent) \
328 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000329#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000330 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000331#define ABSTRACT_EXPR(Node, Parent)
332#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000333
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000338 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000339
340 /// \brief Build a new block pointer type given its pointee type.
341 ///
Mike Stump11289f42009-09-09 15:08:12 +0000342 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000343 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000344 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000345
John McCall70dd5f62009-10-30 00:06:24 +0000346 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 ///
John McCall70dd5f62009-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 Gregord6ff3322009-08-04 16:50:30 +0000351 ///
John McCall70dd5f62009-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 Stump11289f42009-09-09 15:08:12 +0000357
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000363 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
364 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000365
John McCall550e0c22009-10-21 00:40:46 +0000366 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000367 QualType RebuildObjCObjectPointerType(QualType PointeeType,
368 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000369
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000376 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000383
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000389 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000392 unsigned IndexTypeQuals,
393 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000400 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000401 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404
Mike Stump11289f42009-09-09 15:08:12 +0000405 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000410 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000412 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 unsigned IndexTypeQuals,
414 SourceRange BracketsRange);
415
Mike Stump11289f42009-09-09 15:08:12 +0000416 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000421 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000423 ExprArg SizeExpr,
Douglas Gregord6ff3322009-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 Thompson22334602010-02-05 00:12:22 +0000432 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
433 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000434
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000442
443 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000448 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000449 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000451
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000457 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000458 unsigned NumParamTypes,
459 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000460
John McCall550e0c22009-10-21 00:40:46 +0000461 /// \brief Build a new unprototyped function type.
462 QualType RebuildFunctionNoProtoType(QualType ResultType);
463
John McCallb96ec562009-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 Gregord6ff3322009-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 McCallfcc33b02009-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 Stump11289f42009-09-09 15:08:12 +0000487
488 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-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 Gregora16548e2009-08-11 05:31:07 +0000492 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000499 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-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 Gregora16548e2009-08-11 05:31:07 +0000503 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000504
Douglas Gregord6ff3322009-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 McCall0ad16662009-10-29 08:12:44 +0000511 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000512 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000513
Douglas Gregord6ff3322009-08-04 16:50:30 +0000514 /// \brief Build a new qualified name type.
515 ///
Mike Stump11289f42009-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 Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000521 }
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000526 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000527 /// different behavior.
528 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-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 Gregord6ff3322009-08-04 16:50:30 +0000534 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000535 }
Mike Stump11289f42009-09-09 15:08:12 +0000536
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000538 }
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000543 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000544 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000545 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000546 const IdentifierInfo *Id,
547 SourceRange SR) {
548 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000549 }
Mike Stump11289f42009-09-09 15:08:12 +0000550
Douglas Gregor1135c352009-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 Gregorc26e0f62009-09-03 16:14:30 +0000559 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000560 QualType ObjectType,
561 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-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 Gregorcd3f49f2010-02-25 04:46:04 +0000582 QualType T);
Douglas Gregor71dc5092009-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 Gregor71dc5092009-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 Gregor308047d2009-09-09 00:23:06 +0000602 const IdentifierInfo &II,
603 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000604
Douglas Gregor71395fa2009-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 Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000637 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000638 ColonLoc);
639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000649
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000654 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 SourceLocation ColonLoc,
656 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000657 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000658 /*CurScope=*/0);
659 }
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000665 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000671
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000676 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-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 Gregorebe10102009-08-20 07:17:43 +0000681 }
Mike Stump11289f42009-09-09 15:08:12 +0000682
Douglas Gregorebe10102009-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 Gregor7bab5ff2009-11-25 00:27:52 +0000687 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
688 VarDecl *CondVar) {
689 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 }
Mike Stump11289f42009-09-09 15:08:12 +0000691
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000696 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-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 Gregor7bab5ff2009-11-25 00:27:52 +0000708 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000710 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
711 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 }
Mike Stump11289f42009-09-09 15:08:12 +0000713
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000723 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000731 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000733 StmtArg Init, Sema::FullExprArg Cond,
734 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000736 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
737 DeclPtrTy::make(CondVar),
738 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 }
Mike Stump11289f42009-09-09 15:08:12 +0000740
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000760
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000767
Douglas Gregorebe10102009-08-20 07:17:43 +0000768 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
769 }
Mike Stump11289f42009-09-09 15:08:12 +0000770
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000776 SourceLocation StartLoc,
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000784
Anders Carlssonaaeef072010-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 Carlsson9a020f92010-01-30 22:25:16 +0000794 IdentifierInfo **Names,
Anders Carlssonaaeef072010-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 Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000811 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000812 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000813 IdentifierInfo *Name,
814 SourceLocation Loc,
815 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000816 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000828 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000829 Handler.takeAs<Stmt>()));
830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +0000841
Douglas Gregora16548e2009-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 McCalle66edc12009-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 Gregor4bd90e52009-10-23 18:54:35 +0000857 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
858 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000859 ValueDecl *VD, SourceLocation Loc,
860 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000861 CXXScopeSpec SS;
862 SS.setScopeRep(Qualifier);
863 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000864
865 // FIXME: loses template args.
866
867 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000868 }
Mike Stump11289f42009-09-09 15:08:12 +0000869
Douglas Gregora16548e2009-08-11 05:31:07 +0000870 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000871 ///
Douglas Gregora16548e2009-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 Gregorad8a3362009-09-04 17:36:40 +0000879 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000880 ///
Douglas Gregorad8a3362009-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 Gregor678f90d2010-02-25 01:56:36 +0000886 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000887 SourceRange QualifierRange,
888 TypeSourceInfo *ScopeType,
889 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000890 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000891 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000892
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000894 ///
Douglas Gregora16548e2009-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 Gregor5287f092009-11-05 00:51:44 +0000900 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000901 }
Mike Stump11289f42009-09-09 15:08:12 +0000902
Douglas Gregora16548e2009-08-11 05:31:07 +0000903 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000904 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000905 /// By default, performs semantic analysis to build the new expression.
906 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000907 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000908 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000910 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 }
912
Mike Stump11289f42009-09-09 15:08:12 +0000913 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000915 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000920 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000921 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
922 OpLoc, isSizeOf, R);
923 if (Result.isInvalid())
924 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000925
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 SubExpr.release();
927 return move(Result);
928 }
Mike Stump11289f42009-09-09 15:08:12 +0000929
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000931 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000934 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 SourceLocation LBracketLoc,
936 ExprArg RHS,
937 SourceLocation RBracketLoc) {
938 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000939 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000940 RBracketLoc);
941 }
942
943 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000944 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000956 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000960 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000961 NestedNameSpecifier *Qualifier,
962 SourceRange QualifierRange,
963 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000964 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000965 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000966 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-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 Stump11289f42009-09-09 15:08:12 +0000970
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000971 Expr *BaseExpr = Base.takeAs<Expr>();
Douglas Gregorcc3f3252010-03-03 23:55:11 +0000972 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000973 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000974
Mike Stump11289f42009-09-09 15:08:12 +0000975 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000976 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000977 Member, MemberLoc,
978 cast<FieldDecl>(Member)->getType());
979 return getSema().Owned(ME);
980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000982 CXXScopeSpec SS;
983 if (Qualifier) {
984 SS.setRange(QualifierRange);
985 SS.setScopeRep(Qualifier);
986 }
987
John McCall2d74de92009-12-01 22:10:20 +0000988 QualType BaseType = ((Expr*) Base.get())->getType();
989
John McCall38836f02010-01-15 08:34:02 +0000990 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
991 Sema::LookupMemberName);
992 R.addDecl(Member);
993 R.resolveKind();
994
John McCall2d74de92009-12-01 22:10:20 +0000995 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
996 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000997 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +0000998 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 }
Mike Stump11289f42009-09-09 15:08:12 +00001000
Douglas Gregora16548e2009-08-11 05:31:07 +00001001 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001002 ///
Douglas Gregora16548e2009-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 Gregor5287f092009-11-05 00:51:44 +00001008 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1009 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 }
1011
1012 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001013 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001021 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001022 move(LHS), move(RHS));
1023 }
1024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001029 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1030 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 SourceLocation RParenLoc,
1032 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001033 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1034 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-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 McCalle15bbff2010-01-18 19:35:47 +00001042 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001043 SourceLocation RParenLoc,
1044 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001045 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1046 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001050 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001053 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 SourceLocation OpLoc,
1055 SourceLocation AccessorLoc,
1056 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001057
John McCall10eae182009-11-30 22:42:35 +00001058 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001059 QualType BaseType = ((Expr*) Base.get())->getType();
1060 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001061 OpLoc, /*IsArrow*/ false,
1062 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001063 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001064 AccessorLoc,
1065 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 }
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001069 ///
Douglas Gregora16548e2009-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 Gregord3d93062009-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 Gregora16548e2009-08-11 05:31:07 +00001086 }
Mike Stump11289f42009-09-09 15:08:12 +00001087
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001089 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 ArrayExprs.release();
1104 return move(Result);
1105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001108 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001115
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001117 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001122 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 RParenLoc);
1124 }
1125
1126 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001127 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// By default, performs semantic analysis to build the new expression.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1131 MultiExprArg SubExprs,
1132 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001133 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1134 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 }
Mike Stump11289f42009-09-09 15:08:12 +00001136
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001138 ///
1139 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001147
Douglas Gregora16548e2009-08-11 05:31:07 +00001148 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001149 ///
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001182
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001188 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001196
1197 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001198 /// reinterpret_cast.
1199 ///
1200 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001201 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001206 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001213 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001214 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 move(SubExpr), RParenLoc);
1216
1217 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001218 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001219 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001221
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001223 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001224 RAngleLoc, LParenLoc,
1225 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001227
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001229 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001230 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001232
Douglas Gregora16548e2009-08-11 05:31:07 +00001233 default:
1234 assert(false && "Invalid C++ named cast");
1235 break;
1236 }
Mike Stump11289f42009-09-09 15:08:12 +00001237
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 return getSema().ExprError();
1239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Douglas Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001247 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 SourceLocation RAngleLoc,
1249 SourceLocation LParenLoc,
1250 ExprArg SubExpr,
1251 SourceLocation RParenLoc) {
John McCalld377e042010-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 Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001264 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 SourceLocation RAngleLoc,
1266 SourceLocation LParenLoc,
1267 ExprArg SubExpr,
1268 SourceLocation RParenLoc) {
John McCalld377e042010-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 Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001281 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 SourceLocation RAngleLoc,
1283 SourceLocation LParenLoc,
1284 ExprArg SubExpr,
1285 SourceLocation RParenLoc) {
John McCalld377e042010-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 Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001298 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 SourceLocation RAngleLoc,
1300 SourceLocation LParenLoc,
1301 ExprArg SubExpr,
1302 SourceLocation RParenLoc) {
John McCalld377e042010-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 Gregora16548e2009-08-11 05:31:07 +00001307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-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 McCall97513962010-01-15 18:39:57 +00001314 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 SourceLocation LParenLoc,
1316 ExprArg SubExpr,
1317 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001318 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001320 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001322 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001323 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 RParenLoc);
1325 }
Mike Stump11289f42009-09-09 15:08:12 +00001326
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001335 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 T.getAsOpaquePtr(), RParenLoc);
1337 }
Mike Stump11289f42009-09-09 15:08:12 +00001338
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001347 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1349 RParenLoc);
1350 if (Result.isInvalid())
1351 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1354 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001355 }
1356
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001360 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001362 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001363 QualType ThisType,
1364 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001366 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1367 isImplicit));
Douglas Gregora16548e2009-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 Gregor033f6752009-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 Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001393 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 SourceLocation LParenLoc,
1395 QualType T,
1396 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001397 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1398 T.getAsOpaquePtr(), LParenLoc,
1399 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 0, RParenLoc);
1401 }
Mike Stump11289f42009-09-09 15:08:12 +00001402
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001407 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 bool UseGlobal,
1409 SourceLocation PlacementLParen,
1410 MultiExprArg PlacementArgs,
1411 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001412 bool ParenTypeId,
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001420 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001445
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001455 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 T.getAsOpaquePtr(), RParenLoc);
1457 }
1458
Mike Stump11289f42009-09-09 15:08:12 +00001459 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-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 McCall8cd78132009-11-19 22:55:06 +00001464 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001465 SourceRange QualifierRange,
1466 DeclarationName Name,
1467 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001468 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 CXXScopeSpec SS;
1470 SS.setRange(QualifierRange);
1471 SS.setScopeRep(NNS);
John McCalle66edc12009-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 Gregora16548e2009-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 McCalle66edc12009-11-24 19:00:30 +00001484 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1485 LookupResult &R,
1486 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001487 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001488 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-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 Gregordb121ba2009-12-14 16:27:04 +00001496 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001497 CXXConstructorDecl *Constructor,
1498 bool IsElidable,
1499 MultiExprArg Args) {
Douglas Gregordb121ba2009-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 Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001545
Douglas Gregora16548e2009-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 McCall8cd78132009-11-19 22:55:06 +00001550 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001551 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 bool IsArrow,
1553 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001554 NestedNameSpecifier *Qualifier,
1555 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001556 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001558 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001559 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001561 SS.setRange(QualifierRange);
1562 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001563
John McCall2d74de92009-12-01 22:10:20 +00001564 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1565 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001566 SS, FirstQualifierInScope,
1567 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001568 }
1569
John McCall10eae182009-11-30 22:42:35 +00001570 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-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 McCall10eae182009-11-30 22:42:35 +00001574 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001575 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001576 SourceLocation OperatorLoc,
1577 bool IsArrow,
1578 NestedNameSpecifier *Qualifier,
1579 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001580 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001581 LookupResult &R,
1582 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001583 CXXScopeSpec SS;
1584 SS.setRange(QualifierRange);
1585 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001586
John McCall2d74de92009-12-01 22:10:20 +00001587 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1588 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001589 SS, FirstQualifierInScope,
1590 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001602 }
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001618 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001629 const IdentifierInfo &Name
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 // Build a reference to the __builtin_shufflevector builtin
1636 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001637 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001639 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001641
1642 // Build the CallExpr
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +00001655
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001657 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001659};
Douglas Gregora16548e2009-08-11 05:31:07 +00001660
Douglas Gregorebe10102009-08-20 07:17:43 +00001661template<typename Derived>
1662Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1663 if (!S)
1664 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001665
Douglas Gregorebe10102009-08-20 07:17:43 +00001666 switch (S->getStmtClass()) {
1667 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001668
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +00001674
Douglas Gregorebe10102009-08-20 07:17:43 +00001675 // Transform expressions by calling TransformExpr.
1676#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001677#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-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 Stump11289f42009-09-09 15:08:12 +00001684
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001685 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001686 }
Mike Stump11289f42009-09-09 15:08:12 +00001687 }
1688
Douglas Gregorebe10102009-08-20 07:17:43 +00001689 return SemaRef.Owned(S->Retain());
1690}
Mike Stump11289f42009-09-09 15:08:12 +00001691
1692
Douglas Gregore922c772009-08-04 22:27:00 +00001693template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001694Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-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 McCall2adddca2010-02-03 00:55:45 +00001701#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001702#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001703 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001704#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001705 }
1706
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001708}
1709
1710template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001711NestedNameSpecifier *
1712TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001713 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001714 QualType ObjectType,
1715 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001716 if (!NNS)
1717 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregorebe10102009-08-20 07:17:43 +00001719 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001720 NestedNameSpecifier *Prefix = NNS->getPrefix();
1721 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001722 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001723 ObjectType,
1724 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001725 if (!Prefix)
1726 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001727
1728 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001730 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001731 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 }
Mike Stump11289f42009-09-09 15:08:12 +00001733
Douglas Gregor1135c352009-08-06 05:28:30 +00001734 switch (NNS->getKind()) {
1735 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001736 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-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 Gregor1135c352009-08-06 05:28:30 +00001740 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001741
1742 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001743 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001744 ObjectType,
1745 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001746
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001748 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001750 getDerived().TransformDecl(Range.getBegin(),
1751 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001752 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 Prefix == NNS->getPrefix() &&
1754 NS == NNS->getAsNamespace())
1755 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1758 }
Mike Stump11289f42009-09-09 15:08:12 +00001759
Douglas Gregor1135c352009-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 Stump11289f42009-09-09 15:08:12 +00001764
Douglas Gregor1135c352009-08-06 05:28:30 +00001765 case NestedNameSpecifier::TypeSpecWithTemplate:
1766 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001767 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001768 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1769 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001770 if (T.isNull())
1771 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregor1135c352009-08-06 05:28:30 +00001773 if (!getDerived().AlwaysRebuild() &&
1774 Prefix == NNS->getPrefix() &&
1775 T == QualType(NNS->getAsType(), 0))
1776 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001777
1778 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1779 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001780 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001781 }
1782 }
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor1135c352009-08-06 05:28:30 +00001784 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001785 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001786}
1787
1788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001789DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001791 SourceLocation Loc,
1792 QualType ObjectType) {
Douglas Gregorf816bd72009-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:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001802 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001803 case DeclarationName::CXXUsingDirective:
1804 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001805
Douglas Gregorf816bd72009-09-03 22:13:48 +00001806 case DeclarationName::CXXConstructorName:
1807 case DeclarationName::CXXDestructorName:
1808 case DeclarationName::CXXConversionFunctionName: {
1809 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001810 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1811 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001812 if (T.isNull())
1813 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001814
Douglas Gregorf816bd72009-09-03 22:13:48 +00001815 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001816 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001817 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001818 }
Mike Stump11289f42009-09-09 15:08:12 +00001819 }
1820
Douglas Gregorf816bd72009-09-03 22:13:48 +00001821 return DeclarationName();
1822}
1823
1824template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001825TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001826TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1827 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001828 SourceLocation Loc = getDerived().getBaseLocation();
1829
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001831 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001832 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001833 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1834 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 if (!NNS)
1836 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregor71dc5092009-08-06 06:41:21 +00001838 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001839 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001840 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001841 if (!TransTemplate)
1842 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregor71dc5092009-08-06 06:41:21 +00001844 if (!getDerived().AlwaysRebuild() &&
1845 NNS == QTN->getQualifier() &&
1846 TransTemplate == Template)
1847 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1850 TransTemplate);
1851 }
Mike Stump11289f42009-09-09 15:08:12 +00001852
John McCalle66edc12009-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 Gregor71dc5092009-08-06 06:41:21 +00001855 }
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregor71dc5092009-08-06 06:41:21 +00001857 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001858 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001860 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1861 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001862 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001864
Douglas Gregor71dc5092009-08-06 06:41:21 +00001865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001866 NNS == DTN->getQualifier() &&
1867 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001869
Douglas Gregor71395fa2009-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 Gregor71dc5092009-08-06 06:41:21 +00001876 }
Mike Stump11289f42009-09-09 15:08:12 +00001877
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001879 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001880 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001881 if (!TransTemplate)
1882 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884 if (!getDerived().AlwaysRebuild() &&
1885 TransTemplate == Template)
1886 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregor71dc5092009-08-06 06:41:21 +00001888 return TemplateName(TransTemplate);
1889 }
Mike Stump11289f42009-09-09 15:08:12 +00001890
John McCalle66edc12009-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 Gregor71dc5092009-08-06 06:41:21 +00001894}
1895
1896template<typename Derived>
John McCall0ad16662009-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 Yasskin1615d452009-12-12 05:05:38 +00001903 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001904 break;
1905
1906 case TemplateArgument::Type:
1907 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001908 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001909
1910 break;
1911
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001912 case TemplateArgument::Template:
1913 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1914 break;
1915
John McCall0ad16662009-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 McCall0d07eb32009-10-29 18:45:58 +00001923 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-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 Gregore922c772009-08-04 22:27:00 +00001933 switch (Arg.getKind()) {
1934 case TemplateArgument::Null:
1935 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001936 Output = Input;
1937 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001938
Douglas Gregore922c772009-08-04 22:27:00 +00001939 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001940 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001941 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001942 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-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 Gregore922c772009-08-04 22:27:00 +00001949 }
Mike Stump11289f42009-09-09 15:08:12 +00001950
Douglas Gregore922c772009-08-04 22:27:00 +00001951 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001952 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001953 DeclarationName Name;
1954 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1955 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001956 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001957 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001958 if (!D) return true;
1959
John McCall0d07eb32009-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 McCall0ad16662009-10-29 08:12:44 +00001974 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001975 }
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregor9167f8b2009-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 Gregore922c772009-08-04 22:27:00 +00001990 case TemplateArgument::Expression: {
1991 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001992 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001993 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001994
John McCall0ad16662009-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 McCall0d07eb32009-10-29 18:45:58 +00002003 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002004 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2005 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002006 }
Mike Stump11289f42009-09-09 15:08:12 +00002007
Douglas Gregore922c772009-08-04 22:27:00 +00002008 case TemplateArgument::Pack: {
2009 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2010 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002011 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002012 AEnd = Arg.pack_end();
2013 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002014
John McCall0ad16662009-10-29 08:12:44 +00002015 // FIXME: preserve source information here when we start
2016 // caring about parameter packs.
2017
John McCall0d07eb32009-10-29 18:45:58 +00002018 TemplateArgumentLoc InputArg;
2019 TemplateArgumentLoc OutputArg;
2020 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2021 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002022 return true;
2023
John McCall0d07eb32009-10-29 18:45:58 +00002024 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002025 }
2026 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002027 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002028 true);
John McCall0d07eb32009-10-29 18:45:58 +00002029 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002030 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002031 }
2032 }
Mike Stump11289f42009-09-09 15:08:12 +00002033
Douglas Gregore922c772009-08-04 22:27:00 +00002034 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002035 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002036}
2037
Douglas Gregord6ff3322009-08-04 16:50:30 +00002038//===----------------------------------------------------------------------===//
2039// Type transformation
2040//===----------------------------------------------------------------------===//
2041
2042template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002043QualType TreeTransform<Derived>::TransformType(QualType T,
2044 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002045 if (getDerived().AlreadyTransformed(T))
2046 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002047
John McCall550e0c22009-10-21 00:40:46 +00002048 // Temporary workaround. All of these transformations should
2049 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002050 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002051 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002052
Douglas Gregorfe17d252010-02-16 19:09:40 +00002053 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002054
John McCall550e0c22009-10-21 00:40:46 +00002055 if (!NewDI)
2056 return QualType();
2057
2058 return NewDI->getType();
2059}
2060
2061template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002062TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2063 QualType ObjectType) {
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +00002072 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002073 if (Result.isNull())
2074 return 0;
2075
John McCallbcd03502009-12-07 02:54:59 +00002076 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002077}
2078
2079template<typename Derived>
2080QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002081TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2082 QualType ObjectType) {
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +00002087 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2088 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002089#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002090 }
Mike Stump11289f42009-09-09 15:08:12 +00002091
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002092 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +00002104 QualifiedTypeLoc T,
2105 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002106 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002107
Douglas Gregorfe17d252010-02-16 19:09:40 +00002108 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2109 ObjectType);
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002117 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002118
John McCall550e0c22009-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 McCall70dd5f62009-10-30 00:06:24 +00002146 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2147 TL.getSigilLoc()); \
John McCall550e0c22009-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 McCall550e0c22009-10-21 00:40:46 +00002158template<typename Derived>
2159QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002160 BuiltinTypeLoc T,
2161 QualType ObjectType) {
Douglas Gregorc9b7a592010-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 Gregord6ff3322009-08-04 16:50:30 +00002167}
Mike Stump11289f42009-09-09 15:08:12 +00002168
Douglas Gregord6ff3322009-08-04 16:50:30 +00002169template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002170QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002171 ComplexTypeLoc T,
2172 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002173 // FIXME: recurse?
2174 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002175}
Mike Stump11289f42009-09-09 15:08:12 +00002176
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002178QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002179 PointerTypeLoc TL,
2180 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002181 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002182}
Mike Stump11289f42009-09-09 15:08:12 +00002183
2184template<typename Derived>
2185QualType
John McCall550e0c22009-10-21 00:40:46 +00002186TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002187 BlockPointerTypeLoc TL,
2188 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002189 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002190}
2191
John McCall70dd5f62009-10-30 00:06:24 +00002192/// Transforms a reference type. Note that somewhat paradoxically we
2193/// don't care whether the type itself is an l-value type or an r-value
2194/// type; we only care if the type was *written* as an l-value type
2195/// or an r-value type.
2196template<typename Derived>
2197QualType
2198TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002199 ReferenceTypeLoc TL,
2200 QualType ObjectType) {
John McCall70dd5f62009-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 Stump11289f42009-09-09 15:08:12 +00002229template<typename Derived>
2230QualType
John McCall550e0c22009-10-21 00:40:46 +00002231TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002232 LValueReferenceTypeLoc TL,
2233 QualType ObjectType) {
2234 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002235}
2236
Mike Stump11289f42009-09-09 15:08:12 +00002237template<typename Derived>
2238QualType
John McCall550e0c22009-10-21 00:40:46 +00002239TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002240 RValueReferenceTypeLoc TL,
2241 QualType ObjectType) {
2242 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002243}
Mike Stump11289f42009-09-09 15:08:12 +00002244
Douglas Gregord6ff3322009-08-04 16:50:30 +00002245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002246QualType
John McCall550e0c22009-10-21 00:40:46 +00002247TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002248 MemberPointerTypeLoc TL,
2249 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002250 MemberPointerType *T = TL.getTypePtr();
2251
2252 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002253 if (PointeeType.isNull())
2254 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002255
John McCall550e0c22009-10-21 00:40:46 +00002256 // TODO: preserve source information for this.
2257 QualType ClassType
2258 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002259 if (ClassType.isNull())
2260 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002261
John McCall550e0c22009-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 McCall70dd5f62009-10-30 00:06:24 +00002266 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2267 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002268 if (Result.isNull())
2269 return QualType();
2270 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002271
John McCall550e0c22009-10-21 00:40:46 +00002272 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2273 NewTL.setSigilLoc(TL.getSigilLoc());
2274
2275 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002276}
2277
Mike Stump11289f42009-09-09 15:08:12 +00002278template<typename Derived>
2279QualType
John McCall550e0c22009-10-21 00:40:46 +00002280TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002281 ConstantArrayTypeLoc TL,
2282 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002283 ConstantArrayType *T = TL.getTypePtr();
2284 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002285 if (ElementType.isNull())
2286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002287
John McCall550e0c22009-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 McCall70dd5f62009-10-30 00:06:24 +00002294 T->getIndexTypeCVRQualifiers(),
2295 TL.getBracketsRange());
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002303
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002312}
Mike Stump11289f42009-09-09 15:08:12 +00002313
Douglas Gregord6ff3322009-08-04 16:50:30 +00002314template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002315QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002316 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002317 IncompleteArrayTypeLoc TL,
2318 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002319 IncompleteArrayType *T = TL.getTypePtr();
2320 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002321 if (ElementType.isNull())
2322 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002323
John McCall550e0c22009-10-21 00:40:46 +00002324 QualType Result = TL.getType();
2325 if (getDerived().AlwaysRebuild() ||
2326 ElementType != T->getElementType()) {
2327 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002328 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002329 T->getIndexTypeCVRQualifiers(),
2330 TL.getBracketsRange());
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +00002346 VariableArrayTypeLoc TL,
2347 QualType ObjectType) {
John McCall550e0c22009-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 McCall70dd5f62009-10-30 00:06:24 +00002371 TL.getBracketsRange());
John McCall550e0c22009-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 Gregorfe17d252010-02-16 19:09:40 +00002388 DependentSizedArrayTypeLoc TL,
2389 QualType ObjectType) {
John McCall550e0c22009-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 McCall70dd5f62009-10-30 00:06:24 +00002413 TL.getBracketsRange());
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002427}
Mike Stump11289f42009-09-09 15:08:12 +00002428
2429template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002431 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002432 DependentSizedExtVectorTypeLoc TL,
2433 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002434 DependentSizedExtVectorType *T = TL.getTypePtr();
2435
2436 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002437 QualType ElementType = getDerived().TransformType(T->getElementType());
2438 if (ElementType.isNull())
2439 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002440
Douglas Gregore922c772009-08-04 22:27:00 +00002441 // Vector sizes are not potentially evaluated contexts
2442 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2443
Douglas Gregord6ff3322009-08-04 16:50:30 +00002444 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2445 if (Size.isInvalid())
2446 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002447
John McCall550e0c22009-10-21 00:40:46 +00002448 QualType Result = TL.getType();
2449 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002450 ElementType != T->getElementType() ||
2451 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002452 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002453 move(Size),
2454 T->getAttributeLoc());
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002471}
Mike Stump11289f42009-09-09 15:08:12 +00002472
2473template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002474QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002475 VectorTypeLoc TL,
2476 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002477 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002478 QualType ElementType = getDerived().TransformType(T->getElementType());
2479 if (ElementType.isNull())
2480 return QualType();
2481
John McCall550e0c22009-10-21 00:40:46 +00002482 QualType Result = TL.getType();
2483 if (getDerived().AlwaysRebuild() ||
2484 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002485 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2486 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002493
John McCall550e0c22009-10-21 00:40:46 +00002494 return Result;
2495}
2496
2497template<typename Derived>
2498QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002499 ExtVectorTypeLoc TL,
2500 QualType ObjectType) {
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002520}
Mike Stump11289f42009-09-09 15:08:12 +00002521
2522template<typename Derived>
2523QualType
John McCall550e0c22009-10-21 00:40:46 +00002524TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002525 FunctionProtoTypeLoc TL,
2526 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002527 FunctionProtoType *T = TL.getTypePtr();
2528 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002529 if (ResultType.isNull())
2530 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002531
John McCall550e0c22009-10-21 00:40:46 +00002532 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002533 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002537
John McCall550e0c22009-10-21 00:40:46 +00002538 QualType NewType;
2539 ParmVarDecl *NewParm;
2540
2541 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002542 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002543 assert(OldDI->getType() == T->getArgType(i));
2544
John McCallbcd03502009-12-07 02:54:59 +00002545 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002575 }
Mike Stump11289f42009-09-09 15:08:12 +00002576
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002589
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002597}
Mike Stump11289f42009-09-09 15:08:12 +00002598
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599template<typename Derived>
2600QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002601 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002602 FunctionNoProtoTypeLoc TL,
2603 QualType ObjectType) {
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002619}
Mike Stump11289f42009-09-09 15:08:12 +00002620
John McCallb96ec562009-12-04 22:46:56 +00002621template<typename Derived> QualType
2622TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002623 UnresolvedUsingTypeLoc TL,
2624 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002625 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002626 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-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 Gregord6ff3322009-08-04 16:50:30 +00002645template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002646QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002647 TypedefTypeLoc TL,
2648 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002649 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002651 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2652 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002653 if (!Typedef)
2654 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002655
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002663
John McCall550e0c22009-10-21 00:40:46 +00002664 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2665 NewTL.setNameLoc(TL.getNameLoc());
2666
2667 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668}
Mike Stump11289f42009-09-09 15:08:12 +00002669
Douglas Gregord6ff3322009-08-04 16:50:30 +00002670template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002671QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002672 TypeOfExprTypeLoc TL,
2673 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002674 // typeof expressions are not potentially evaluated contexts
2675 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002676
John McCalle8595032010-01-13 20:03:27 +00002677 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678 if (E.isInvalid())
2679 return QualType();
2680
John McCall550e0c22009-10-21 00:40:46 +00002681 QualType Result = TL.getType();
2682 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002683 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002684 Result = getDerived().RebuildTypeOfExprType(move(E));
2685 if (Result.isNull())
2686 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687 }
John McCall550e0c22009-10-21 00:40:46 +00002688 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002689
John McCall550e0c22009-10-21 00:40:46 +00002690 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002691 NewTL.setTypeofLoc(TL.getTypeofLoc());
2692 NewTL.setLParenLoc(TL.getLParenLoc());
2693 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002694
2695 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002696}
Mike Stump11289f42009-09-09 15:08:12 +00002697
2698template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002699QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002700 TypeOfTypeLoc TL,
2701 QualType ObjectType) {
John McCalle8595032010-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 Gregord6ff3322009-08-04 16:50:30 +00002705 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002706
John McCall550e0c22009-10-21 00:40:46 +00002707 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002708 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2709 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002710 if (Result.isNull())
2711 return QualType();
2712 }
Mike Stump11289f42009-09-09 15:08:12 +00002713
John McCall550e0c22009-10-21 00:40:46 +00002714 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-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 McCall550e0c22009-10-21 00:40:46 +00002719
2720 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002721}
Mike Stump11289f42009-09-09 15:08:12 +00002722
2723template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002724QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002725 DecltypeTypeLoc TL,
2726 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002727 DecltypeType *T = TL.getTypePtr();
2728
Douglas Gregore922c772009-08-04 22:27:00 +00002729 // decltype expressions are not potentially evaluated contexts
2730 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002731
Douglas Gregord6ff3322009-08-04 16:50:30 +00002732 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2733 if (E.isInvalid())
2734 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002735
John McCall550e0c22009-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 Gregord6ff3322009-08-04 16:50:30 +00002742 }
John McCall550e0c22009-10-21 00:40:46 +00002743 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002744
John McCall550e0c22009-10-21 00:40:46 +00002745 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2746 NewTL.setNameLoc(TL.getNameLoc());
2747
2748 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749}
2750
2751template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002752QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002753 RecordTypeLoc TL,
2754 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002755 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002757 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2758 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759 if (!Record)
2760 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002761
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002769
John McCall550e0c22009-10-21 00:40:46 +00002770 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2771 NewTL.setNameLoc(TL.getNameLoc());
2772
2773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774}
Mike Stump11289f42009-09-09 15:08:12 +00002775
2776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002777QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002778 EnumTypeLoc TL,
2779 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002780 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002781 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002782 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2783 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784 if (!Enum)
2785 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 QualType Result = TL.getType();
2788 if (getDerived().AlwaysRebuild() ||
2789 Enum != T->getDecl()) {
2790 Result = getDerived().RebuildEnumType(Enum);
2791 if (Result.isNull())
2792 return QualType();
2793 }
Mike Stump11289f42009-09-09 15:08:12 +00002794
John McCall550e0c22009-10-21 00:40:46 +00002795 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2796 NewTL.setNameLoc(TL.getNameLoc());
2797
2798 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799}
John McCallfcc33b02009-09-05 00:15:47 +00002800
2801template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002803 ElaboratedTypeLoc TL,
2804 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002805 ElaboratedType *T = TL.getTypePtr();
2806
2807 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002808 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2809 if (Underlying.isNull())
2810 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-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 Stump11289f42009-09-09 15:08:12 +00002819
John McCall550e0c22009-10-21 00:40:46 +00002820 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2821 NewTL.setNameLoc(TL.getNameLoc());
2822
2823 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002824}
Mike Stump11289f42009-09-09 15:08:12 +00002825
John McCalle78aac42010-03-10 03:28:59 +00002826template<typename Derived>
2827QualType TreeTransform<Derived>::TransformInjectedClassNameType(
2828 TypeLocBuilder &TLB,
2829 InjectedClassNameTypeLoc TL,
2830 QualType ObjectType) {
2831 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
2832 TL.getTypePtr()->getDecl());
2833 if (!D) return QualType();
2834
2835 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
2836 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
2837 return T;
2838}
2839
Mike Stump11289f42009-09-09 15:08:12 +00002840
Douglas Gregord6ff3322009-08-04 16:50:30 +00002841template<typename Derived>
2842QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002843 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002844 TemplateTypeParmTypeLoc TL,
2845 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002846 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002847}
2848
Mike Stump11289f42009-09-09 15:08:12 +00002849template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002850QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002851 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002852 SubstTemplateTypeParmTypeLoc TL,
2853 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002854 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002855}
2856
2857template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002858QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2859 const TemplateSpecializationType *TST,
2860 QualType ObjectType) {
2861 // FIXME: this entire method is a temporary workaround; callers
2862 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002863
John McCall0ad16662009-10-29 08:12:44 +00002864 // Fake up a TemplateSpecializationTypeLoc.
2865 TypeLocBuilder TLB;
2866 TemplateSpecializationTypeLoc TL
2867 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2868
John McCall0d07eb32009-10-29 18:45:58 +00002869 SourceLocation BaseLoc = getDerived().getBaseLocation();
2870
2871 TL.setTemplateNameLoc(BaseLoc);
2872 TL.setLAngleLoc(BaseLoc);
2873 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002874 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2875 const TemplateArgument &TA = TST->getArg(i);
2876 TemplateArgumentLoc TAL;
2877 getDerived().InventTemplateArgumentLoc(TA, TAL);
2878 TL.setArgLocInfo(i, TAL.getLocInfo());
2879 }
2880
2881 TypeLocBuilder IgnoredTLB;
2882 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002883}
2884
2885template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002886QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002887 TypeLocBuilder &TLB,
2888 TemplateSpecializationTypeLoc TL,
2889 QualType ObjectType) {
2890 const TemplateSpecializationType *T = TL.getTypePtr();
2891
Mike Stump11289f42009-09-09 15:08:12 +00002892 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002893 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002894 if (Template.isNull())
2895 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002896
John McCall6b51f282009-11-23 01:53:49 +00002897 TemplateArgumentListInfo NewTemplateArgs;
2898 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2899 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2900
2901 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2902 TemplateArgumentLoc Loc;
2903 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002905 NewTemplateArgs.addArgument(Loc);
2906 }
Mike Stump11289f42009-09-09 15:08:12 +00002907
John McCall0ad16662009-10-29 08:12:44 +00002908 // FIXME: maybe don't rebuild if all the template arguments are the same.
2909
2910 QualType Result =
2911 getDerived().RebuildTemplateSpecializationType(Template,
2912 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002913 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002914
2915 if (!Result.isNull()) {
2916 TemplateSpecializationTypeLoc NewTL
2917 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2918 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2919 NewTL.setLAngleLoc(TL.getLAngleLoc());
2920 NewTL.setRAngleLoc(TL.getRAngleLoc());
2921 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2922 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002923 }
Mike Stump11289f42009-09-09 15:08:12 +00002924
John McCall0ad16662009-10-29 08:12:44 +00002925 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002926}
Mike Stump11289f42009-09-09 15:08:12 +00002927
2928template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002929QualType
2930TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002931 QualifiedNameTypeLoc TL,
2932 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002933 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934 NestedNameSpecifier *NNS
2935 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002936 SourceRange(),
2937 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938 if (!NNS)
2939 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002940
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941 QualType Named = getDerived().TransformType(T->getNamedType());
2942 if (Named.isNull())
2943 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002944
John McCall550e0c22009-10-21 00:40:46 +00002945 QualType Result = TL.getType();
2946 if (getDerived().AlwaysRebuild() ||
2947 NNS != T->getQualifier() ||
2948 Named != T->getNamedType()) {
2949 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2950 if (Result.isNull())
2951 return QualType();
2952 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002953
John McCall550e0c22009-10-21 00:40:46 +00002954 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2955 NewTL.setNameLoc(TL.getNameLoc());
2956
2957 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002958}
Mike Stump11289f42009-09-09 15:08:12 +00002959
2960template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002961QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002962 TypenameTypeLoc TL,
2963 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002964 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002965
2966 /* FIXME: preserve source information better than this */
2967 SourceRange SR(TL.getNameLoc());
2968
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00002970 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002971 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002972 if (!NNS)
2973 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002974
John McCall550e0c22009-10-21 00:40:46 +00002975 QualType Result;
2976
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002978 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002979 = getDerived().TransformType(QualType(TemplateId, 0));
2980 if (NewTemplateId.isNull())
2981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregord6ff3322009-08-04 16:50:30 +00002983 if (!getDerived().AlwaysRebuild() &&
2984 NNS == T->getQualifier() &&
2985 NewTemplateId == QualType(TemplateId, 0))
2986 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002987
John McCall550e0c22009-10-21 00:40:46 +00002988 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2989 } else {
John McCall0ad16662009-10-29 08:12:44 +00002990 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991 }
John McCall550e0c22009-10-21 00:40:46 +00002992 if (Result.isNull())
2993 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002994
John McCall550e0c22009-10-21 00:40:46 +00002995 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2996 NewTL.setNameLoc(TL.getNameLoc());
2997
2998 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002999}
Mike Stump11289f42009-09-09 15:08:12 +00003000
Douglas Gregord6ff3322009-08-04 16:50:30 +00003001template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003002QualType
3003TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003004 ObjCInterfaceTypeLoc TL,
3005 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003006 assert(false && "TransformObjCInterfaceType unimplemented");
3007 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003008}
Mike Stump11289f42009-09-09 15:08:12 +00003009
3010template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003011QualType
3012TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003013 ObjCObjectPointerTypeLoc TL,
3014 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003015 assert(false && "TransformObjCObjectPointerType unimplemented");
3016 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003017}
3018
Douglas Gregord6ff3322009-08-04 16:50:30 +00003019//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003020// Statement transformation
3021//===----------------------------------------------------------------------===//
3022template<typename Derived>
3023Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003024TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3025 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003026}
3027
3028template<typename Derived>
3029Sema::OwningStmtResult
3030TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3031 return getDerived().TransformCompoundStmt(S, false);
3032}
3033
3034template<typename Derived>
3035Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003036TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003037 bool IsStmtExpr) {
3038 bool SubStmtChanged = false;
3039 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3040 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3041 B != BEnd; ++B) {
3042 OwningStmtResult Result = getDerived().TransformStmt(*B);
3043 if (Result.isInvalid())
3044 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003045
Douglas Gregorebe10102009-08-20 07:17:43 +00003046 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3047 Statements.push_back(Result.takeAs<Stmt>());
3048 }
Mike Stump11289f42009-09-09 15:08:12 +00003049
Douglas Gregorebe10102009-08-20 07:17:43 +00003050 if (!getDerived().AlwaysRebuild() &&
3051 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003052 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003053
3054 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3055 move_arg(Statements),
3056 S->getRBracLoc(),
3057 IsStmtExpr);
3058}
Mike Stump11289f42009-09-09 15:08:12 +00003059
Douglas Gregorebe10102009-08-20 07:17:43 +00003060template<typename Derived>
3061Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003062TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003063 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3064 {
3065 // The case value expressions are not potentially evaluated.
3066 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003067
Eli Friedman06577382009-11-19 03:14:00 +00003068 // Transform the left-hand case value.
3069 LHS = getDerived().TransformExpr(S->getLHS());
3070 if (LHS.isInvalid())
3071 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003072
Eli Friedman06577382009-11-19 03:14:00 +00003073 // Transform the right-hand case value (for the GNU case-range extension).
3074 RHS = getDerived().TransformExpr(S->getRHS());
3075 if (RHS.isInvalid())
3076 return SemaRef.StmtError();
3077 }
Mike Stump11289f42009-09-09 15:08:12 +00003078
Douglas Gregorebe10102009-08-20 07:17:43 +00003079 // Build the case statement.
3080 // Case statements are always rebuilt so that they will attached to their
3081 // transformed switch statement.
3082 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3083 move(LHS),
3084 S->getEllipsisLoc(),
3085 move(RHS),
3086 S->getColonLoc());
3087 if (Case.isInvalid())
3088 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003089
Douglas Gregorebe10102009-08-20 07:17:43 +00003090 // Transform the statement following the case
3091 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3092 if (SubStmt.isInvalid())
3093 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003094
Douglas Gregorebe10102009-08-20 07:17:43 +00003095 // Attach the body to the case statement
3096 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3097}
3098
3099template<typename Derived>
3100Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003101TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003102 // Transform the statement following the default case
3103 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3104 if (SubStmt.isInvalid())
3105 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003106
Douglas Gregorebe10102009-08-20 07:17:43 +00003107 // Default statements are always rebuilt
3108 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3109 move(SubStmt));
3110}
Mike Stump11289f42009-09-09 15:08:12 +00003111
Douglas Gregorebe10102009-08-20 07:17:43 +00003112template<typename Derived>
3113Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003114TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003115 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3116 if (SubStmt.isInvalid())
3117 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003118
Douglas Gregorebe10102009-08-20 07:17:43 +00003119 // FIXME: Pass the real colon location in.
3120 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3121 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3122 move(SubStmt));
3123}
Mike Stump11289f42009-09-09 15:08:12 +00003124
Douglas Gregorebe10102009-08-20 07:17:43 +00003125template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003126Sema::OwningStmtResult
3127TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003129 OwningExprResult Cond(SemaRef);
3130 VarDecl *ConditionVar = 0;
3131 if (S->getConditionVariable()) {
3132 ConditionVar
3133 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003134 getDerived().TransformDefinition(
3135 S->getConditionVariable()->getLocation(),
3136 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003137 if (!ConditionVar)
3138 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003139 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003140 Cond = getDerived().TransformExpr(S->getCond());
3141
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003142 if (Cond.isInvalid())
3143 return SemaRef.StmtError();
3144 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003145
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003146 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003147
Douglas Gregorebe10102009-08-20 07:17:43 +00003148 // Transform the "then" branch.
3149 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3150 if (Then.isInvalid())
3151 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 // Transform the "else" branch.
3154 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3155 if (Else.isInvalid())
3156 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 if (!getDerived().AlwaysRebuild() &&
3159 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003160 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003161 Then.get() == S->getThen() &&
3162 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003163 return SemaRef.Owned(S->Retain());
3164
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003165 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3166 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003167 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003168}
3169
3170template<typename Derived>
3171Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003172TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003173 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003174 OwningExprResult Cond(SemaRef);
3175 VarDecl *ConditionVar = 0;
3176 if (S->getConditionVariable()) {
3177 ConditionVar
3178 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003179 getDerived().TransformDefinition(
3180 S->getConditionVariable()->getLocation(),
3181 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003182 if (!ConditionVar)
3183 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003184 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003185 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003186
3187 if (Cond.isInvalid())
3188 return SemaRef.StmtError();
3189 }
Mike Stump11289f42009-09-09 15:08:12 +00003190
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003191 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003192
Douglas Gregorebe10102009-08-20 07:17:43 +00003193 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003194 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3195 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003196 if (Switch.isInvalid())
3197 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregorebe10102009-08-20 07:17:43 +00003199 // Transform the body of the switch statement.
3200 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3201 if (Body.isInvalid())
3202 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregorebe10102009-08-20 07:17:43 +00003204 // Complete the switch statement.
3205 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3206 move(Body));
3207}
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregorebe10102009-08-20 07:17:43 +00003209template<typename Derived>
3210Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003211TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003212 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003213 OwningExprResult Cond(SemaRef);
3214 VarDecl *ConditionVar = 0;
3215 if (S->getConditionVariable()) {
3216 ConditionVar
3217 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003218 getDerived().TransformDefinition(
3219 S->getConditionVariable()->getLocation(),
3220 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003221 if (!ConditionVar)
3222 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003223 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003224 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003225
3226 if (Cond.isInvalid())
3227 return SemaRef.StmtError();
3228 }
Mike Stump11289f42009-09-09 15:08:12 +00003229
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003230 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 // Transform the body
3233 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3234 if (Body.isInvalid())
3235 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 if (!getDerived().AlwaysRebuild() &&
3238 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003239 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003241 return SemaRef.Owned(S->Retain());
3242
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003243 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3244 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003245}
Mike Stump11289f42009-09-09 15:08:12 +00003246
Douglas Gregorebe10102009-08-20 07:17:43 +00003247template<typename Derived>
3248Sema::OwningStmtResult
3249TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3250 // Transform the condition
3251 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3252 if (Cond.isInvalid())
3253 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003254
Douglas Gregorebe10102009-08-20 07:17:43 +00003255 // Transform the body
3256 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3257 if (Body.isInvalid())
3258 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003259
Douglas Gregorebe10102009-08-20 07:17:43 +00003260 if (!getDerived().AlwaysRebuild() &&
3261 Cond.get() == S->getCond() &&
3262 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003263 return SemaRef.Owned(S->Retain());
3264
Douglas Gregorebe10102009-08-20 07:17:43 +00003265 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3266 /*FIXME:*/S->getWhileLoc(), move(Cond),
3267 S->getRParenLoc());
3268}
Mike Stump11289f42009-09-09 15:08:12 +00003269
Douglas Gregorebe10102009-08-20 07:17:43 +00003270template<typename Derived>
3271Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003272TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003273 // Transform the initialization statement
3274 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3275 if (Init.isInvalid())
3276 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003277
Douglas Gregorebe10102009-08-20 07:17:43 +00003278 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003279 OwningExprResult Cond(SemaRef);
3280 VarDecl *ConditionVar = 0;
3281 if (S->getConditionVariable()) {
3282 ConditionVar
3283 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003284 getDerived().TransformDefinition(
3285 S->getConditionVariable()->getLocation(),
3286 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003287 if (!ConditionVar)
3288 return SemaRef.StmtError();
3289 } else {
3290 Cond = getDerived().TransformExpr(S->getCond());
3291
3292 if (Cond.isInvalid())
3293 return SemaRef.StmtError();
3294 }
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 // Transform the increment
3297 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3298 if (Inc.isInvalid())
3299 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 // Transform the body
3302 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3303 if (Body.isInvalid())
3304 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003305
Douglas Gregorebe10102009-08-20 07:17:43 +00003306 if (!getDerived().AlwaysRebuild() &&
3307 Init.get() == S->getInit() &&
3308 Cond.get() == S->getCond() &&
3309 Inc.get() == S->getInc() &&
3310 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003311 return SemaRef.Owned(S->Retain());
3312
Douglas Gregorebe10102009-08-20 07:17:43 +00003313 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003314 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003315 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003316 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 S->getRParenLoc(), move(Body));
3318}
3319
3320template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003321Sema::OwningStmtResult
3322TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003323 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003324 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003325 S->getLabel());
3326}
3327
3328template<typename Derived>
3329Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003330TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003331 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3332 if (Target.isInvalid())
3333 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregorebe10102009-08-20 07:17:43 +00003335 if (!getDerived().AlwaysRebuild() &&
3336 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003337 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003338
3339 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3340 move(Target));
3341}
3342
3343template<typename Derived>
3344Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003345TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3346 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003347}
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349template<typename Derived>
3350Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003351TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3352 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003353}
Mike Stump11289f42009-09-09 15:08:12 +00003354
Douglas Gregorebe10102009-08-20 07:17:43 +00003355template<typename Derived>
3356Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003357TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003358 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3359 if (Result.isInvalid())
3360 return SemaRef.StmtError();
3361
Mike Stump11289f42009-09-09 15:08:12 +00003362 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003363 // to tell whether the return type of the function has changed.
3364 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
Douglas Gregorebe10102009-08-20 07:17:43 +00003367template<typename Derived>
3368Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003369TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003370 bool DeclChanged = false;
3371 llvm::SmallVector<Decl *, 4> Decls;
3372 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3373 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003374 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3375 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003376 if (!Transformed)
3377 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003378
Douglas Gregorebe10102009-08-20 07:17:43 +00003379 if (Transformed != *D)
3380 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003381
Douglas Gregorebe10102009-08-20 07:17:43 +00003382 Decls.push_back(Transformed);
3383 }
Mike Stump11289f42009-09-09 15:08:12 +00003384
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003386 return SemaRef.Owned(S->Retain());
3387
3388 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003389 S->getStartLoc(), S->getEndLoc());
3390}
Mike Stump11289f42009-09-09 15:08:12 +00003391
Douglas Gregorebe10102009-08-20 07:17:43 +00003392template<typename Derived>
3393Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003394TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003395 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003396 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003397}
3398
3399template<typename Derived>
3400Sema::OwningStmtResult
3401TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003402
3403 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3404 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003405 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003406
Anders Carlssonaaeef072010-01-24 05:50:09 +00003407 OwningExprResult AsmString(SemaRef);
3408 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3409
3410 bool ExprsChanged = false;
3411
3412 // Go through the outputs.
3413 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003414 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003415
Anders Carlssonaaeef072010-01-24 05:50:09 +00003416 // No need to transform the constraint literal.
3417 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3418
3419 // Transform the output expr.
3420 Expr *OutputExpr = S->getOutputExpr(I);
3421 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3422 if (Result.isInvalid())
3423 return SemaRef.StmtError();
3424
3425 ExprsChanged |= Result.get() != OutputExpr;
3426
3427 Exprs.push_back(Result.takeAs<Expr>());
3428 }
3429
3430 // Go through the inputs.
3431 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003432 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003433
Anders Carlssonaaeef072010-01-24 05:50:09 +00003434 // No need to transform the constraint literal.
3435 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3436
3437 // Transform the input expr.
3438 Expr *InputExpr = S->getInputExpr(I);
3439 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3440 if (Result.isInvalid())
3441 return SemaRef.StmtError();
3442
3443 ExprsChanged |= Result.get() != InputExpr;
3444
3445 Exprs.push_back(Result.takeAs<Expr>());
3446 }
3447
3448 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3449 return SemaRef.Owned(S->Retain());
3450
3451 // Go through the clobbers.
3452 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3453 Clobbers.push_back(S->getClobber(I)->Retain());
3454
3455 // No need to transform the asm string literal.
3456 AsmString = SemaRef.Owned(S->getAsmString());
3457
3458 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3459 S->isSimple(),
3460 S->isVolatile(),
3461 S->getNumOutputs(),
3462 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003463 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003464 move_arg(Constraints),
3465 move_arg(Exprs),
3466 move(AsmString),
3467 move_arg(Clobbers),
3468 S->getRParenLoc(),
3469 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003470}
3471
3472
3473template<typename Derived>
3474Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003475TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 // FIXME: Implement this
3477 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003478 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003479}
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregorebe10102009-08-20 07:17:43 +00003481template<typename Derived>
3482Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003483TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003484 // FIXME: Implement this
3485 assert(false && "Cannot transform an Objective-C @catch statement");
3486 return SemaRef.Owned(S->Retain());
3487}
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregorebe10102009-08-20 07:17:43 +00003489template<typename Derived>
3490Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003491TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003492 // FIXME: Implement this
3493 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003494 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003495}
Mike Stump11289f42009-09-09 15:08:12 +00003496
Douglas Gregorebe10102009-08-20 07:17:43 +00003497template<typename Derived>
3498Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003499TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003500 // FIXME: Implement this
3501 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003502 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003503}
Mike Stump11289f42009-09-09 15:08:12 +00003504
Douglas Gregorebe10102009-08-20 07:17:43 +00003505template<typename Derived>
3506Sema::OwningStmtResult
3507TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003508 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 // FIXME: Implement this
3510 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003512}
3513
3514template<typename Derived>
3515Sema::OwningStmtResult
3516TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003517 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003518 // FIXME: Implement this
3519 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003520 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003521}
3522
3523
3524template<typename Derived>
3525Sema::OwningStmtResult
3526TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3527 // Transform the exception declaration, if any.
3528 VarDecl *Var = 0;
3529 if (S->getExceptionDecl()) {
3530 VarDecl *ExceptionDecl = S->getExceptionDecl();
3531 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3532 ExceptionDecl->getDeclName());
3533
3534 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3535 if (T.isNull())
3536 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3539 T,
John McCallbcd03502009-12-07 02:54:59 +00003540 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003541 ExceptionDecl->getIdentifier(),
3542 ExceptionDecl->getLocation(),
3543 /*FIXME: Inaccurate*/
3544 SourceRange(ExceptionDecl->getLocation()));
3545 if (!Var || Var->isInvalidDecl()) {
3546 if (Var)
3547 Var->Destroy(SemaRef.Context);
3548 return SemaRef.StmtError();
3549 }
3550 }
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 // Transform the actual exception handler.
3553 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3554 if (Handler.isInvalid()) {
3555 if (Var)
3556 Var->Destroy(SemaRef.Context);
3557 return SemaRef.StmtError();
3558 }
Mike Stump11289f42009-09-09 15:08:12 +00003559
Douglas Gregorebe10102009-08-20 07:17:43 +00003560 if (!getDerived().AlwaysRebuild() &&
3561 !Var &&
3562 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003563 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003564
3565 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3566 Var,
3567 move(Handler));
3568}
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregorebe10102009-08-20 07:17:43 +00003570template<typename Derived>
3571Sema::OwningStmtResult
3572TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3573 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003574 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003575 = getDerived().TransformCompoundStmt(S->getTryBlock());
3576 if (TryBlock.isInvalid())
3577 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 // Transform the handlers.
3580 bool HandlerChanged = false;
3581 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3582 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003583 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003584 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3585 if (Handler.isInvalid())
3586 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregorebe10102009-08-20 07:17:43 +00003588 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3589 Handlers.push_back(Handler.takeAs<Stmt>());
3590 }
Mike Stump11289f42009-09-09 15:08:12 +00003591
Douglas Gregorebe10102009-08-20 07:17:43 +00003592 if (!getDerived().AlwaysRebuild() &&
3593 TryBlock.get() == S->getTryBlock() &&
3594 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003595 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003596
3597 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003598 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003599}
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003602// Expression transformation
3603//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003604template<typename Derived>
3605Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003606TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003607 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003608}
Mike Stump11289f42009-09-09 15:08:12 +00003609
3610template<typename Derived>
3611Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003612TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003613 NestedNameSpecifier *Qualifier = 0;
3614 if (E->getQualifier()) {
3615 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003616 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003617 if (!Qualifier)
3618 return SemaRef.ExprError();
3619 }
John McCallce546572009-12-08 09:08:17 +00003620
3621 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003622 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3623 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003624 if (!ND)
3625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003626
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003627 if (!getDerived().AlwaysRebuild() &&
3628 Qualifier == E->getQualifier() &&
3629 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003630 !E->hasExplicitTemplateArgumentList()) {
3631
3632 // Mark it referenced in the new context regardless.
3633 // FIXME: this is a bit instantiation-specific.
3634 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3635
Mike Stump11289f42009-09-09 15:08:12 +00003636 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003637 }
John McCallce546572009-12-08 09:08:17 +00003638
3639 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3640 if (E->hasExplicitTemplateArgumentList()) {
3641 TemplateArgs = &TransArgs;
3642 TransArgs.setLAngleLoc(E->getLAngleLoc());
3643 TransArgs.setRAngleLoc(E->getRAngleLoc());
3644 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3645 TemplateArgumentLoc Loc;
3646 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3647 return SemaRef.ExprError();
3648 TransArgs.addArgument(Loc);
3649 }
3650 }
3651
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003652 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003653 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003654}
Mike Stump11289f42009-09-09 15:08:12 +00003655
Douglas Gregora16548e2009-08-11 05:31:07 +00003656template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003657Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003658TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003659 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003660}
Mike Stump11289f42009-09-09 15:08:12 +00003661
Douglas Gregora16548e2009-08-11 05:31:07 +00003662template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003663Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003664TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003665 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003666}
Mike Stump11289f42009-09-09 15:08:12 +00003667
Douglas Gregora16548e2009-08-11 05:31:07 +00003668template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003669Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003670TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003671 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003672}
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregora16548e2009-08-11 05:31:07 +00003674template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003675Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003676TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003677 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003678}
Mike Stump11289f42009-09-09 15:08:12 +00003679
Douglas Gregora16548e2009-08-11 05:31:07 +00003680template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003681Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003682TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003683 return SemaRef.Owned(E->Retain());
3684}
3685
3686template<typename Derived>
3687Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003688TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003689 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3690 if (SubExpr.isInvalid())
3691 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003692
Douglas Gregora16548e2009-08-11 05:31:07 +00003693 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003694 return SemaRef.Owned(E->Retain());
3695
3696 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003697 E->getRParen());
3698}
3699
Mike Stump11289f42009-09-09 15:08:12 +00003700template<typename Derived>
3701Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003702TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3703 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003704 if (SubExpr.isInvalid())
3705 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003708 return SemaRef.Owned(E->Retain());
3709
Douglas Gregora16548e2009-08-11 05:31:07 +00003710 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3711 E->getOpcode(),
3712 move(SubExpr));
3713}
Mike Stump11289f42009-09-09 15:08:12 +00003714
Douglas Gregora16548e2009-08-11 05:31:07 +00003715template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003716Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003717TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003719 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003720
John McCallbcd03502009-12-07 02:54:59 +00003721 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003722 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003723 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003724
John McCall4c98fd82009-11-04 07:28:41 +00003725 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003726 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003727
John McCall4c98fd82009-11-04 07:28:41 +00003728 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003729 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 E->getSourceRange());
3731 }
Mike Stump11289f42009-09-09 15:08:12 +00003732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003734 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003735 // C++0x [expr.sizeof]p1:
3736 // The operand is either an expression, which is an unevaluated operand
3737 // [...]
3738 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003739
Douglas Gregora16548e2009-08-11 05:31:07 +00003740 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3741 if (SubExpr.isInvalid())
3742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3745 return SemaRef.Owned(E->Retain());
3746 }
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregora16548e2009-08-11 05:31:07 +00003748 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3749 E->isSizeOf(),
3750 E->getSourceRange());
3751}
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregora16548e2009-08-11 05:31:07 +00003753template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003754Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003755TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003756 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3757 if (LHS.isInvalid())
3758 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003759
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3761 if (RHS.isInvalid())
3762 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003763
3764
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 if (!getDerived().AlwaysRebuild() &&
3766 LHS.get() == E->getLHS() &&
3767 RHS.get() == E->getRHS())
3768 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003769
Douglas Gregora16548e2009-08-11 05:31:07 +00003770 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3771 /*FIXME:*/E->getLHS()->getLocStart(),
3772 move(RHS),
3773 E->getRBracketLoc());
3774}
Mike Stump11289f42009-09-09 15:08:12 +00003775
3776template<typename Derived>
3777Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003778TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003779 // Transform the callee.
3780 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3781 if (Callee.isInvalid())
3782 return SemaRef.ExprError();
3783
3784 // Transform arguments.
3785 bool ArgChanged = false;
3786 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3787 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3788 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3789 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3790 if (Arg.isInvalid())
3791 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 // FIXME: Wrong source location information for the ','.
3794 FakeCommaLocs.push_back(
3795 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003796
3797 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003798 Args.push_back(Arg.takeAs<Expr>());
3799 }
Mike Stump11289f42009-09-09 15:08:12 +00003800
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 if (!getDerived().AlwaysRebuild() &&
3802 Callee.get() == E->getCallee() &&
3803 !ArgChanged)
3804 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregora16548e2009-08-11 05:31:07 +00003806 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003807 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003808 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3809 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3810 move_arg(Args),
3811 FakeCommaLocs.data(),
3812 E->getRParenLoc());
3813}
Mike Stump11289f42009-09-09 15:08:12 +00003814
3815template<typename Derived>
3816Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003817TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003818 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3819 if (Base.isInvalid())
3820 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003821
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003822 NestedNameSpecifier *Qualifier = 0;
3823 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003824 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003825 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003826 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003827 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003828 return SemaRef.ExprError();
3829 }
Mike Stump11289f42009-09-09 15:08:12 +00003830
Eli Friedman2cfcef62009-12-04 06:40:45 +00003831 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003832 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
3833 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003834 if (!Member)
3835 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003836
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 if (!getDerived().AlwaysRebuild() &&
3838 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003839 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003840 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003841 !E->hasExplicitTemplateArgumentList()) {
3842
3843 // Mark it referenced in the new context regardless.
3844 // FIXME: this is a bit instantiation-specific.
3845 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003846 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003847 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003848
John McCall6b51f282009-11-23 01:53:49 +00003849 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003850 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003851 TransArgs.setLAngleLoc(E->getLAngleLoc());
3852 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003853 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003854 TemplateArgumentLoc Loc;
3855 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003856 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003857 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003858 }
3859 }
3860
Douglas Gregora16548e2009-08-11 05:31:07 +00003861 // FIXME: Bogus source location for the operator
3862 SourceLocation FakeOperatorLoc
3863 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3864
John McCall38836f02010-01-15 08:34:02 +00003865 // FIXME: to do this check properly, we will need to preserve the
3866 // first-qualifier-in-scope here, just in case we had a dependent
3867 // base (and therefore couldn't do the check) and a
3868 // nested-name-qualifier (and therefore could do the lookup).
3869 NamedDecl *FirstQualifierInScope = 0;
3870
Douglas Gregora16548e2009-08-11 05:31:07 +00003871 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3872 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003873 Qualifier,
3874 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003876 Member,
John McCall6b51f282009-11-23 01:53:49 +00003877 (E->hasExplicitTemplateArgumentList()
3878 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003879 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregora16548e2009-08-11 05:31:07 +00003882template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003883Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003884TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3886 if (LHS.isInvalid())
3887 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003888
Douglas Gregora16548e2009-08-11 05:31:07 +00003889 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3890 if (RHS.isInvalid())
3891 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 if (!getDerived().AlwaysRebuild() &&
3894 LHS.get() == E->getLHS() &&
3895 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003896 return SemaRef.Owned(E->Retain());
3897
Douglas Gregora16548e2009-08-11 05:31:07 +00003898 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3899 move(LHS), move(RHS));
3900}
3901
Mike Stump11289f42009-09-09 15:08:12 +00003902template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003903Sema::OwningExprResult
3904TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003905 CompoundAssignOperator *E) {
3906 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003907}
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003910Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003911TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003912 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3913 if (Cond.isInvalid())
3914 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003915
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3917 if (LHS.isInvalid())
3918 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3921 if (RHS.isInvalid())
3922 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003923
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 if (!getDerived().AlwaysRebuild() &&
3925 Cond.get() == E->getCond() &&
3926 LHS.get() == E->getLHS() &&
3927 RHS.get() == E->getRHS())
3928 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003929
3930 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003931 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003932 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003933 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 move(RHS));
3935}
Mike Stump11289f42009-09-09 15:08:12 +00003936
3937template<typename Derived>
3938Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003939TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003940 // Implicit casts are eliminated during transformation, since they
3941 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003942 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003943}
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945template<typename Derived>
3946Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003947TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003948 TypeSourceInfo *OldT;
3949 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 {
3951 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003952 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003953 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3954 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003955
John McCall97513962010-01-15 18:39:57 +00003956 OldT = E->getTypeInfoAsWritten();
3957 NewT = getDerived().TransformType(OldT);
3958 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 return SemaRef.ExprError();
3960 }
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregor6131b442009-12-12 18:16:41 +00003962 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003963 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 if (SubExpr.isInvalid())
3965 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003968 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003970 return SemaRef.Owned(E->Retain());
3971
John McCall97513962010-01-15 18:39:57 +00003972 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3973 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 E->getRParenLoc(),
3975 move(SubExpr));
3976}
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregora16548e2009-08-11 05:31:07 +00003978template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003979Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003980TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003981 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3982 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3983 if (!NewT)
3984 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3987 if (Init.isInvalid())
3988 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003991 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003992 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003993 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003994
John McCall5d7aa7f2010-01-19 22:33:45 +00003995 // Note: the expression type doesn't necessarily match the
3996 // type-as-written, but that's okay, because it should always be
3997 // derivable from the initializer.
3998
John McCalle15bbff2010-01-18 19:35:47 +00003999 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 /*FIXME:*/E->getInitializer()->getLocEnd(),
4001 move(Init));
4002}
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregora16548e2009-08-11 05:31:07 +00004004template<typename Derived>
4005Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004006TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4008 if (Base.isInvalid())
4009 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004010
Douglas Gregora16548e2009-08-11 05:31:07 +00004011 if (!getDerived().AlwaysRebuild() &&
4012 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004013 return SemaRef.Owned(E->Retain());
4014
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004016 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4018 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4019 E->getAccessorLoc(),
4020 E->getAccessor());
4021}
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregora16548e2009-08-11 05:31:07 +00004023template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004024Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004025TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4029 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4030 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4031 if (Init.isInvalid())
4032 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004033
Douglas Gregora16548e2009-08-11 05:31:07 +00004034 InitChanged = InitChanged || Init.get() != E->getInit(I);
4035 Inits.push_back(Init.takeAs<Expr>());
4036 }
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregora16548e2009-08-11 05:31:07 +00004038 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004039 return SemaRef.Owned(E->Retain());
4040
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004042 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregora16548e2009-08-11 05:31:07 +00004045template<typename Derived>
4046Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004047TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004048 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregorebe10102009-08-20 07:17:43 +00004050 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4052 if (Init.isInvalid())
4053 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004056 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4057 bool ExprChanged = false;
4058 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4059 DEnd = E->designators_end();
4060 D != DEnd; ++D) {
4061 if (D->isFieldDesignator()) {
4062 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4063 D->getDotLoc(),
4064 D->getFieldLoc()));
4065 continue;
4066 }
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 if (D->isArrayDesignator()) {
4069 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4070 if (Index.isInvalid())
4071 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004072
4073 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004075
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4077 ArrayExprs.push_back(Index.release());
4078 continue;
4079 }
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004082 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4084 if (Start.isInvalid())
4085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4088 if (End.isInvalid())
4089 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004090
4091 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004092 End.get(),
4093 D->getLBracketLoc(),
4094 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4097 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregora16548e2009-08-11 05:31:07 +00004099 ArrayExprs.push_back(Start.release());
4100 ArrayExprs.push_back(End.release());
4101 }
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 if (!getDerived().AlwaysRebuild() &&
4104 Init.get() == E->getInit() &&
4105 !ExprChanged)
4106 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4109 E->getEqualOrColonLoc(),
4110 E->usesGNUSyntax(), move(Init));
4111}
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004114Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004115TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004116 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004117 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4118
4119 // FIXME: Will we ever have proper type location here? Will we actually
4120 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004121 QualType T = getDerived().TransformType(E->getType());
4122 if (T.isNull())
4123 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregora16548e2009-08-11 05:31:07 +00004125 if (!getDerived().AlwaysRebuild() &&
4126 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004127 return SemaRef.Owned(E->Retain());
4128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 return getDerived().RebuildImplicitValueInitExpr(T);
4130}
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregora16548e2009-08-11 05:31:07 +00004132template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004133Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004134TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004135 // FIXME: Do we want the type as written?
4136 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregora16548e2009-08-11 05:31:07 +00004138 {
4139 // FIXME: Source location isn't quite accurate.
4140 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4141 T = getDerived().TransformType(E->getType());
4142 if (T.isNull())
4143 return SemaRef.ExprError();
4144 }
Mike Stump11289f42009-09-09 15:08:12 +00004145
Douglas Gregora16548e2009-08-11 05:31:07 +00004146 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4147 if (SubExpr.isInvalid())
4148 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 if (!getDerived().AlwaysRebuild() &&
4151 T == E->getType() &&
4152 SubExpr.get() == E->getSubExpr())
4153 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004154
Douglas Gregora16548e2009-08-11 05:31:07 +00004155 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4156 T, E->getRParenLoc());
4157}
4158
4159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004160Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004161TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004162 bool ArgumentChanged = false;
4163 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4164 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4165 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4166 if (Init.isInvalid())
4167 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4170 Inits.push_back(Init.takeAs<Expr>());
4171 }
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4174 move_arg(Inits),
4175 E->getRParenLoc());
4176}
Mike Stump11289f42009-09-09 15:08:12 +00004177
Douglas Gregora16548e2009-08-11 05:31:07 +00004178/// \brief Transform an address-of-label expression.
4179///
4180/// By default, the transformation of an address-of-label expression always
4181/// rebuilds the expression, so that the label identifier can be resolved to
4182/// the corresponding label statement by semantic analysis.
4183template<typename Derived>
4184Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004185TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4187 E->getLabel());
4188}
Mike Stump11289f42009-09-09 15:08:12 +00004189
4190template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004191Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004192TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004193 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004194 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4195 if (SubStmt.isInvalid())
4196 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 if (!getDerived().AlwaysRebuild() &&
4199 SubStmt.get() == E->getSubStmt())
4200 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004201
4202 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004203 move(SubStmt),
4204 E->getRParenLoc());
4205}
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207template<typename Derived>
4208Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004209TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 QualType T1, T2;
4211 {
4212 // FIXME: Source location isn't quite accurate.
4213 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004214
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 T1 = getDerived().TransformType(E->getArgType1());
4216 if (T1.isNull())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 T2 = getDerived().TransformType(E->getArgType2());
4220 if (T2.isNull())
4221 return SemaRef.ExprError();
4222 }
4223
4224 if (!getDerived().AlwaysRebuild() &&
4225 T1 == E->getArgType1() &&
4226 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004227 return SemaRef.Owned(E->Retain());
4228
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4230 T1, T2, E->getRParenLoc());
4231}
Mike Stump11289f42009-09-09 15:08:12 +00004232
Douglas Gregora16548e2009-08-11 05:31:07 +00004233template<typename Derived>
4234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004235TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004236 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4237 if (Cond.isInvalid())
4238 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004239
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4241 if (LHS.isInvalid())
4242 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4245 if (RHS.isInvalid())
4246 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248 if (!getDerived().AlwaysRebuild() &&
4249 Cond.get() == E->getCond() &&
4250 LHS.get() == E->getLHS() &&
4251 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004252 return SemaRef.Owned(E->Retain());
4253
Douglas Gregora16548e2009-08-11 05:31:07 +00004254 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4255 move(Cond), move(LHS), move(RHS),
4256 E->getRParenLoc());
4257}
Mike Stump11289f42009-09-09 15:08:12 +00004258
Douglas Gregora16548e2009-08-11 05:31:07 +00004259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004260Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004261TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004262 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004263}
4264
4265template<typename Derived>
4266Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004267TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004268 switch (E->getOperator()) {
4269 case OO_New:
4270 case OO_Delete:
4271 case OO_Array_New:
4272 case OO_Array_Delete:
4273 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4274 return SemaRef.ExprError();
4275
4276 case OO_Call: {
4277 // This is a call to an object's operator().
4278 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4279
4280 // Transform the object itself.
4281 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4282 if (Object.isInvalid())
4283 return SemaRef.ExprError();
4284
4285 // FIXME: Poor location information
4286 SourceLocation FakeLParenLoc
4287 = SemaRef.PP.getLocForEndOfToken(
4288 static_cast<Expr *>(Object.get())->getLocEnd());
4289
4290 // Transform the call arguments.
4291 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4292 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4293 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004294 if (getDerived().DropCallArgument(E->getArg(I)))
4295 break;
4296
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004297 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4298 if (Arg.isInvalid())
4299 return SemaRef.ExprError();
4300
4301 // FIXME: Poor source location information.
4302 SourceLocation FakeCommaLoc
4303 = SemaRef.PP.getLocForEndOfToken(
4304 static_cast<Expr *>(Arg.get())->getLocEnd());
4305 FakeCommaLocs.push_back(FakeCommaLoc);
4306 Args.push_back(Arg.release());
4307 }
4308
4309 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4310 move_arg(Args),
4311 FakeCommaLocs.data(),
4312 E->getLocEnd());
4313 }
4314
4315#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4316 case OO_##Name:
4317#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4318#include "clang/Basic/OperatorKinds.def"
4319 case OO_Subscript:
4320 // Handled below.
4321 break;
4322
4323 case OO_Conditional:
4324 llvm_unreachable("conditional operator is not actually overloadable");
4325 return SemaRef.ExprError();
4326
4327 case OO_None:
4328 case NUM_OVERLOADED_OPERATORS:
4329 llvm_unreachable("not an overloaded operator?");
4330 return SemaRef.ExprError();
4331 }
4332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4334 if (Callee.isInvalid())
4335 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004336
John McCall47f29ea2009-12-08 09:21:05 +00004337 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004338 if (First.isInvalid())
4339 return SemaRef.ExprError();
4340
4341 OwningExprResult Second(SemaRef);
4342 if (E->getNumArgs() == 2) {
4343 Second = getDerived().TransformExpr(E->getArg(1));
4344 if (Second.isInvalid())
4345 return SemaRef.ExprError();
4346 }
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 if (!getDerived().AlwaysRebuild() &&
4349 Callee.get() == E->getCallee() &&
4350 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004351 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4352 return SemaRef.Owned(E->Retain());
4353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4355 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004356 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 move(First),
4358 move(Second));
4359}
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361template<typename Derived>
4362Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004363TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4364 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004365}
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregora16548e2009-08-11 05:31:07 +00004367template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004368Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004369TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004370 TypeSourceInfo *OldT;
4371 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 {
4373 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004374 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004375 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4376 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004377
John McCall97513962010-01-15 18:39:57 +00004378 OldT = E->getTypeInfoAsWritten();
4379 NewT = getDerived().TransformType(OldT);
4380 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 return SemaRef.ExprError();
4382 }
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregor6131b442009-12-12 18:16:41 +00004384 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004385 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 if (SubExpr.isInvalid())
4387 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004390 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004392 return SemaRef.Owned(E->Retain());
4393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004395 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4397 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4398 SourceLocation FakeRParenLoc
4399 = SemaRef.PP.getLocForEndOfToken(
4400 E->getSubExpr()->getSourceRange().getEnd());
4401 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004402 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004404 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004405 FakeRAngleLoc,
4406 FakeRAngleLoc,
4407 move(SubExpr),
4408 FakeRParenLoc);
4409}
Mike Stump11289f42009-09-09 15:08:12 +00004410
Douglas Gregora16548e2009-08-11 05:31:07 +00004411template<typename Derived>
4412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004413TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4414 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004415}
Mike Stump11289f42009-09-09 15:08:12 +00004416
4417template<typename Derived>
4418Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004419TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4420 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004421}
4422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423template<typename Derived>
4424Sema::OwningExprResult
4425TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004426 CXXReinterpretCastExpr *E) {
4427 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004428}
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430template<typename Derived>
4431Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004432TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4433 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004434}
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436template<typename Derived>
4437Sema::OwningExprResult
4438TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004439 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004440 TypeSourceInfo *OldT;
4441 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 {
4443 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004444
John McCall97513962010-01-15 18:39:57 +00004445 OldT = E->getTypeInfoAsWritten();
4446 NewT = getDerived().TransformType(OldT);
4447 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 return SemaRef.ExprError();
4449 }
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregor6131b442009-12-12 18:16:41 +00004451 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004452 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 if (SubExpr.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004457 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004458 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004459 return SemaRef.Owned(E->Retain());
4460
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 // FIXME: The end of the type's source range is wrong
4462 return getDerived().RebuildCXXFunctionalCastExpr(
4463 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004464 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 /*FIXME:*/E->getSubExpr()->getLocStart(),
4466 move(SubExpr),
4467 E->getRParenLoc());
4468}
Mike Stump11289f42009-09-09 15:08:12 +00004469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470template<typename Derived>
4471Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004472TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 if (E->isTypeOperand()) {
4474 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregora16548e2009-08-11 05:31:07 +00004476 QualType T = getDerived().TransformType(E->getTypeOperand());
4477 if (T.isNull())
4478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004479
Douglas Gregora16548e2009-08-11 05:31:07 +00004480 if (!getDerived().AlwaysRebuild() &&
4481 T == E->getTypeOperand())
4482 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004483
Douglas Gregora16548e2009-08-11 05:31:07 +00004484 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4485 /*FIXME:*/E->getLocStart(),
4486 T,
4487 E->getLocEnd());
4488 }
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregora16548e2009-08-11 05:31:07 +00004490 // We don't know whether the expression is potentially evaluated until
4491 // after we perform semantic analysis, so the expression is potentially
4492 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004493 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004494 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregora16548e2009-08-11 05:31:07 +00004496 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4497 if (SubExpr.isInvalid())
4498 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 if (!getDerived().AlwaysRebuild() &&
4501 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004502 return SemaRef.Owned(E->Retain());
4503
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4505 /*FIXME:*/E->getLocStart(),
4506 move(SubExpr),
4507 E->getLocEnd());
4508}
4509
4510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004511Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004512TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004513 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004514}
Mike Stump11289f42009-09-09 15:08:12 +00004515
Douglas Gregora16548e2009-08-11 05:31:07 +00004516template<typename Derived>
4517Sema::OwningExprResult
4518TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004519 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004520 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004521}
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregora16548e2009-08-11 05:31:07 +00004523template<typename Derived>
4524Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004525TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004527
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 QualType T = getDerived().TransformType(E->getType());
4529 if (T.isNull())
4530 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 if (!getDerived().AlwaysRebuild() &&
4533 T == E->getType())
4534 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregorb15af892010-01-07 23:12:05 +00004536 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004537}
Mike Stump11289f42009-09-09 15:08:12 +00004538
Douglas Gregora16548e2009-08-11 05:31:07 +00004539template<typename Derived>
4540Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004541TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004542 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4543 if (SubExpr.isInvalid())
4544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004545
Douglas Gregora16548e2009-08-11 05:31:07 +00004546 if (!getDerived().AlwaysRebuild() &&
4547 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004548 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004549
4550 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4551}
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553template<typename Derived>
4554Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004555TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004556 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004557 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4558 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 if (!Param)
4560 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004561
Chandler Carruth794da4c2010-02-08 06:42:49 +00004562 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 Param == E->getParam())
4564 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregor033f6752009-12-23 23:03:06 +00004566 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004567}
Mike Stump11289f42009-09-09 15:08:12 +00004568
Douglas Gregora16548e2009-08-11 05:31:07 +00004569template<typename Derived>
4570Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004571TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4573
4574 QualType T = getDerived().TransformType(E->getType());
4575 if (T.isNull())
4576 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 if (!getDerived().AlwaysRebuild() &&
4579 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004580 return SemaRef.Owned(E->Retain());
4581
4582 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004583 /*FIXME:*/E->getTypeBeginLoc(),
4584 T,
4585 E->getRParenLoc());
4586}
Mike Stump11289f42009-09-09 15:08:12 +00004587
Douglas Gregora16548e2009-08-11 05:31:07 +00004588template<typename Derived>
4589Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004590TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 // Transform the type that we're allocating
4592 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4593 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4594 if (AllocType.isNull())
4595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 // Transform the size of the array we're allocating (if any).
4598 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4599 if (ArraySize.isInvalid())
4600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004601
Douglas Gregora16548e2009-08-11 05:31:07 +00004602 // Transform the placement arguments (if any).
4603 bool ArgumentChanged = false;
4604 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4605 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4606 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4607 if (Arg.isInvalid())
4608 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004609
Douglas Gregora16548e2009-08-11 05:31:07 +00004610 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4611 PlacementArgs.push_back(Arg.take());
4612 }
Mike Stump11289f42009-09-09 15:08:12 +00004613
Douglas Gregorebe10102009-08-20 07:17:43 +00004614 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4616 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4617 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4618 if (Arg.isInvalid())
4619 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004620
Douglas Gregora16548e2009-08-11 05:31:07 +00004621 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4622 ConstructorArgs.push_back(Arg.take());
4623 }
Mike Stump11289f42009-09-09 15:08:12 +00004624
Douglas Gregord2d9da02010-02-26 00:38:10 +00004625 // Transform constructor, new operator, and delete operator.
4626 CXXConstructorDecl *Constructor = 0;
4627 if (E->getConstructor()) {
4628 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004629 getDerived().TransformDecl(E->getLocStart(),
4630 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004631 if (!Constructor)
4632 return SemaRef.ExprError();
4633 }
4634
4635 FunctionDecl *OperatorNew = 0;
4636 if (E->getOperatorNew()) {
4637 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004638 getDerived().TransformDecl(E->getLocStart(),
4639 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004640 if (!OperatorNew)
4641 return SemaRef.ExprError();
4642 }
4643
4644 FunctionDecl *OperatorDelete = 0;
4645 if (E->getOperatorDelete()) {
4646 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004647 getDerived().TransformDecl(E->getLocStart(),
4648 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004649 if (!OperatorDelete)
4650 return SemaRef.ExprError();
4651 }
4652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 if (!getDerived().AlwaysRebuild() &&
4654 AllocType == E->getAllocatedType() &&
4655 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004656 Constructor == E->getConstructor() &&
4657 OperatorNew == E->getOperatorNew() &&
4658 OperatorDelete == E->getOperatorDelete() &&
4659 !ArgumentChanged) {
4660 // Mark any declarations we need as referenced.
4661 // FIXME: instantiation-specific.
4662 if (Constructor)
4663 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4664 if (OperatorNew)
4665 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4666 if (OperatorDelete)
4667 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004668 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004669 }
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004671 if (!ArraySize.get()) {
4672 // If no array size was specified, but the new expression was
4673 // instantiated with an array type (e.g., "new T" where T is
4674 // instantiated with "int[4]"), extract the outer bound from the
4675 // array type as our array size. We do this with constant and
4676 // dependently-sized array types.
4677 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4678 if (!ArrayT) {
4679 // Do nothing
4680 } else if (const ConstantArrayType *ConsArrayT
4681 = dyn_cast<ConstantArrayType>(ArrayT)) {
4682 ArraySize
4683 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4684 ConsArrayT->getSize(),
4685 SemaRef.Context.getSizeType(),
4686 /*FIXME:*/E->getLocStart()));
4687 AllocType = ConsArrayT->getElementType();
4688 } else if (const DependentSizedArrayType *DepArrayT
4689 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4690 if (DepArrayT->getSizeExpr()) {
4691 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4692 AllocType = DepArrayT->getElementType();
4693 }
4694 }
4695 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4697 E->isGlobalNew(),
4698 /*FIXME:*/E->getLocStart(),
4699 move_arg(PlacementArgs),
4700 /*FIXME:*/E->getLocStart(),
4701 E->isParenTypeId(),
4702 AllocType,
4703 /*FIXME:*/E->getLocStart(),
4704 /*FIXME:*/SourceRange(),
4705 move(ArraySize),
4706 /*FIXME:*/E->getLocStart(),
4707 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004708 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004709}
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711template<typename Derived>
4712Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004713TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004714 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4715 if (Operand.isInvalid())
4716 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregord2d9da02010-02-26 00:38:10 +00004718 // Transform the delete operator, if known.
4719 FunctionDecl *OperatorDelete = 0;
4720 if (E->getOperatorDelete()) {
4721 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004722 getDerived().TransformDecl(E->getLocStart(),
4723 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004724 if (!OperatorDelete)
4725 return SemaRef.ExprError();
4726 }
4727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004729 Operand.get() == E->getArgument() &&
4730 OperatorDelete == E->getOperatorDelete()) {
4731 // Mark any declarations we need as referenced.
4732 // FIXME: instantiation-specific.
4733 if (OperatorDelete)
4734 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004735 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004736 }
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4739 E->isGlobalDelete(),
4740 E->isArrayForm(),
4741 move(Operand));
4742}
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744template<typename Derived>
4745Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004746TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004747 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004748 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4749 if (Base.isInvalid())
4750 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregor678f90d2010-02-25 01:56:36 +00004752 Sema::TypeTy *ObjectTypePtr = 0;
4753 bool MayBePseudoDestructor = false;
4754 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4755 E->getOperatorLoc(),
4756 E->isArrow()? tok::arrow : tok::period,
4757 ObjectTypePtr,
4758 MayBePseudoDestructor);
4759 if (Base.isInvalid())
4760 return SemaRef.ExprError();
4761
4762 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004763 NestedNameSpecifier *Qualifier
4764 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004765 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004766 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004767 if (E->getQualifier() && !Qualifier)
4768 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregor678f90d2010-02-25 01:56:36 +00004770 PseudoDestructorTypeStorage Destroyed;
4771 if (E->getDestroyedTypeInfo()) {
4772 TypeSourceInfo *DestroyedTypeInfo
4773 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4774 if (!DestroyedTypeInfo)
4775 return SemaRef.ExprError();
4776 Destroyed = DestroyedTypeInfo;
4777 } else if (ObjectType->isDependentType()) {
4778 // We aren't likely to be able to resolve the identifier down to a type
4779 // now anyway, so just retain the identifier.
4780 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4781 E->getDestroyedTypeLoc());
4782 } else {
4783 // Look for a destructor known with the given name.
4784 CXXScopeSpec SS;
4785 if (Qualifier) {
4786 SS.setScopeRep(Qualifier);
4787 SS.setRange(E->getQualifierRange());
4788 }
4789
4790 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4791 *E->getDestroyedTypeIdentifier(),
4792 E->getDestroyedTypeLoc(),
4793 /*Scope=*/0,
4794 SS, ObjectTypePtr,
4795 false);
4796 if (!T)
4797 return SemaRef.ExprError();
4798
4799 Destroyed
4800 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4801 E->getDestroyedTypeLoc());
4802 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004803
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004804 TypeSourceInfo *ScopeTypeInfo = 0;
4805 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004806 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4807 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004808 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004809 return SemaRef.ExprError();
4810 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004811
Douglas Gregorad8a3362009-09-04 17:36:40 +00004812 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4813 E->getOperatorLoc(),
4814 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004815 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004816 E->getQualifierRange(),
4817 ScopeTypeInfo,
4818 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004819 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004820 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004821}
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorad8a3362009-09-04 17:36:40 +00004823template<typename Derived>
4824Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004825TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004826 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004827 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4828
4829 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4830 Sema::LookupOrdinaryName);
4831
4832 // Transform all the decls.
4833 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4834 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004835 NamedDecl *InstD = static_cast<NamedDecl*>(
4836 getDerived().TransformDecl(Old->getNameLoc(),
4837 *I));
John McCall84d87672009-12-10 09:41:52 +00004838 if (!InstD) {
4839 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4840 // This can happen because of dependent hiding.
4841 if (isa<UsingShadowDecl>(*I))
4842 continue;
4843 else
4844 return SemaRef.ExprError();
4845 }
John McCalle66edc12009-11-24 19:00:30 +00004846
4847 // Expand using declarations.
4848 if (isa<UsingDecl>(InstD)) {
4849 UsingDecl *UD = cast<UsingDecl>(InstD);
4850 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4851 E = UD->shadow_end(); I != E; ++I)
4852 R.addDecl(*I);
4853 continue;
4854 }
4855
4856 R.addDecl(InstD);
4857 }
4858
4859 // Resolve a kind, but don't do any further analysis. If it's
4860 // ambiguous, the callee needs to deal with it.
4861 R.resolveKind();
4862
4863 // Rebuild the nested-name qualifier, if present.
4864 CXXScopeSpec SS;
4865 NestedNameSpecifier *Qualifier = 0;
4866 if (Old->getQualifier()) {
4867 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004868 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00004869 if (!Qualifier)
4870 return SemaRef.ExprError();
4871
4872 SS.setScopeRep(Qualifier);
4873 SS.setRange(Old->getQualifierRange());
4874 }
4875
4876 // If we have no template arguments, it's a normal declaration name.
4877 if (!Old->hasExplicitTemplateArgs())
4878 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4879
4880 // If we have template arguments, rebuild them, then rebuild the
4881 // templateid expression.
4882 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4883 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4884 TemplateArgumentLoc Loc;
4885 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4886 return SemaRef.ExprError();
4887 TransArgs.addArgument(Loc);
4888 }
4889
4890 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4891 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004892}
Mike Stump11289f42009-09-09 15:08:12 +00004893
Douglas Gregora16548e2009-08-11 05:31:07 +00004894template<typename Derived>
4895Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004896TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004897 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004898
Douglas Gregora16548e2009-08-11 05:31:07 +00004899 QualType T = getDerived().TransformType(E->getQueriedType());
4900 if (T.isNull())
4901 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 if (!getDerived().AlwaysRebuild() &&
4904 T == E->getQueriedType())
4905 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregora16548e2009-08-11 05:31:07 +00004907 // FIXME: Bad location information
4908 SourceLocation FakeLParenLoc
4909 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004910
4911 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 E->getLocStart(),
4913 /*FIXME:*/FakeLParenLoc,
4914 T,
4915 E->getLocEnd());
4916}
Mike Stump11289f42009-09-09 15:08:12 +00004917
Douglas Gregora16548e2009-08-11 05:31:07 +00004918template<typename Derived>
4919Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004920TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004921 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004922 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004923 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004924 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004925 if (!NNS)
4926 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004927
4928 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004929 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4930 if (!Name)
4931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004932
John McCalle66edc12009-11-24 19:00:30 +00004933 if (!E->hasExplicitTemplateArgs()) {
4934 if (!getDerived().AlwaysRebuild() &&
4935 NNS == E->getQualifier() &&
4936 Name == E->getDeclName())
4937 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004938
John McCalle66edc12009-11-24 19:00:30 +00004939 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4940 E->getQualifierRange(),
4941 Name, E->getLocation(),
4942 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004943 }
John McCall6b51f282009-11-23 01:53:49 +00004944
4945 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004946 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004947 TemplateArgumentLoc Loc;
4948 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004950 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 }
4952
John McCalle66edc12009-11-24 19:00:30 +00004953 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4954 E->getQualifierRange(),
4955 Name, E->getLocation(),
4956 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004957}
4958
4959template<typename Derived>
4960Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004961TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004962 // CXXConstructExprs are always implicit, so when we have a
4963 // 1-argument construction we just transform that argument.
4964 if (E->getNumArgs() == 1 ||
4965 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4966 return getDerived().TransformExpr(E->getArg(0));
4967
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4969
4970 QualType T = getDerived().TransformType(E->getType());
4971 if (T.isNull())
4972 return SemaRef.ExprError();
4973
4974 CXXConstructorDecl *Constructor
4975 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004976 getDerived().TransformDecl(E->getLocStart(),
4977 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 if (!Constructor)
4979 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregora16548e2009-08-11 05:31:07 +00004981 bool ArgumentChanged = false;
4982 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004983 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 ArgEnd = E->arg_end();
4985 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004986 if (getDerived().DropCallArgument(*Arg)) {
4987 ArgumentChanged = true;
4988 break;
4989 }
4990
Douglas Gregora16548e2009-08-11 05:31:07 +00004991 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4992 if (TransArg.isInvalid())
4993 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004994
Douglas Gregora16548e2009-08-11 05:31:07 +00004995 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4996 Args.push_back(TransArg.takeAs<Expr>());
4997 }
4998
4999 if (!getDerived().AlwaysRebuild() &&
5000 T == E->getType() &&
5001 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005002 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005003 // Mark the constructor as referenced.
5004 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005005 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005006 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005007 }
Mike Stump11289f42009-09-09 15:08:12 +00005008
Douglas Gregordb121ba2009-12-14 16:27:04 +00005009 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5010 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 move_arg(Args));
5012}
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014/// \brief Transform a C++ temporary-binding expression.
5015///
Douglas Gregor363b1512009-12-24 18:51:59 +00005016/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5017/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005018template<typename Derived>
5019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005020TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005021 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005022}
Mike Stump11289f42009-09-09 15:08:12 +00005023
Anders Carlssonba6c4372010-01-29 02:39:32 +00005024/// \brief Transform a C++ reference-binding expression.
5025///
5026/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5027/// transform the subexpression and return that.
5028template<typename Derived>
5029Sema::OwningExprResult
5030TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5031 return getDerived().TransformExpr(E->getSubExpr());
5032}
5033
Mike Stump11289f42009-09-09 15:08:12 +00005034/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005035/// be destroyed after the expression is evaluated.
5036///
Douglas Gregor363b1512009-12-24 18:51:59 +00005037/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5038/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005039template<typename Derived>
5040Sema::OwningExprResult
5041TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005042 CXXExprWithTemporaries *E) {
5043 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005044}
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046template<typename Derived>
5047Sema::OwningExprResult
5048TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005049 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5051 QualType T = getDerived().TransformType(E->getType());
5052 if (T.isNull())
5053 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005054
Douglas Gregora16548e2009-08-11 05:31:07 +00005055 CXXConstructorDecl *Constructor
5056 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005057 getDerived().TransformDecl(E->getLocStart(),
5058 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 if (!Constructor)
5060 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 bool ArgumentChanged = false;
5063 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5064 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005065 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005066 ArgEnd = E->arg_end();
5067 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005068 if (getDerived().DropCallArgument(*Arg)) {
5069 ArgumentChanged = true;
5070 break;
5071 }
5072
Douglas Gregora16548e2009-08-11 05:31:07 +00005073 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5074 if (TransArg.isInvalid())
5075 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005076
Douglas Gregora16548e2009-08-11 05:31:07 +00005077 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5078 Args.push_back((Expr *)TransArg.release());
5079 }
Mike Stump11289f42009-09-09 15:08:12 +00005080
Douglas Gregora16548e2009-08-11 05:31:07 +00005081 if (!getDerived().AlwaysRebuild() &&
5082 T == E->getType() &&
5083 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005084 !ArgumentChanged) {
5085 // FIXME: Instantiation-specific
5086 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005087 return SemaRef.Owned(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 // FIXME: Bogus location information
5091 SourceLocation CommaLoc;
5092 if (Args.size() > 1) {
5093 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005094 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5096 }
5097 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5098 T,
5099 /*FIXME:*/E->getTypeBeginLoc(),
5100 move_arg(Args),
5101 &CommaLoc,
5102 E->getLocEnd());
5103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105template<typename Derived>
5106Sema::OwningExprResult
5107TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005108 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5110 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5111 if (T.isNull())
5112 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 bool ArgumentChanged = false;
5115 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5116 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5117 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5118 ArgEnd = E->arg_end();
5119 Arg != ArgEnd; ++Arg) {
5120 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5121 if (TransArg.isInvalid())
5122 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregora16548e2009-08-11 05:31:07 +00005124 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5125 FakeCommaLocs.push_back(
5126 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5127 Args.push_back(TransArg.takeAs<Expr>());
5128 }
Mike Stump11289f42009-09-09 15:08:12 +00005129
Douglas Gregora16548e2009-08-11 05:31:07 +00005130 if (!getDerived().AlwaysRebuild() &&
5131 T == E->getTypeAsWritten() &&
5132 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005133 return SemaRef.Owned(E->Retain());
5134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 // FIXME: we're faking the locations of the commas
5136 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5137 T,
5138 E->getLParenLoc(),
5139 move_arg(Args),
5140 FakeCommaLocs.data(),
5141 E->getRParenLoc());
5142}
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregora16548e2009-08-11 05:31:07 +00005144template<typename Derived>
5145Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005146TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005147 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005149 OwningExprResult Base(SemaRef, (Expr*) 0);
5150 Expr *OldBase;
5151 QualType BaseType;
5152 QualType ObjectType;
5153 if (!E->isImplicitAccess()) {
5154 OldBase = E->getBase();
5155 Base = getDerived().TransformExpr(OldBase);
5156 if (Base.isInvalid())
5157 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005158
John McCall2d74de92009-12-01 22:10:20 +00005159 // Start the member reference and compute the object's type.
5160 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005161 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005162 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5163 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005164 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005165 ObjectTy,
5166 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005167 if (Base.isInvalid())
5168 return SemaRef.ExprError();
5169
5170 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5171 BaseType = ((Expr*) Base.get())->getType();
5172 } else {
5173 OldBase = 0;
5174 BaseType = getDerived().TransformType(E->getBaseType());
5175 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5176 }
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005178 // Transform the first part of the nested-name-specifier that qualifies
5179 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005180 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005181 = getDerived().TransformFirstQualifierInScope(
5182 E->getFirstQualifierFoundInScope(),
5183 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005184
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005185 NestedNameSpecifier *Qualifier = 0;
5186 if (E->getQualifier()) {
5187 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5188 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005189 ObjectType,
5190 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005191 if (!Qualifier)
5192 return SemaRef.ExprError();
5193 }
Mike Stump11289f42009-09-09 15:08:12 +00005194
5195 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005196 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005197 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005198 if (!Name)
5199 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005200
John McCall2d74de92009-12-01 22:10:20 +00005201 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005202 // This is a reference to a member without an explicitly-specified
5203 // template argument list. Optimize for this common case.
5204 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005205 Base.get() == OldBase &&
5206 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005207 Qualifier == E->getQualifier() &&
5208 Name == E->getMember() &&
5209 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005210 return SemaRef.Owned(E->Retain());
5211
John McCall8cd78132009-11-19 22:55:06 +00005212 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005213 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005214 E->isArrow(),
5215 E->getOperatorLoc(),
5216 Qualifier,
5217 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005218 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005219 Name,
5220 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005221 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005222 }
5223
John McCall6b51f282009-11-23 01:53:49 +00005224 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005225 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005226 TemplateArgumentLoc Loc;
5227 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005228 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005229 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005230 }
Mike Stump11289f42009-09-09 15:08:12 +00005231
John McCall8cd78132009-11-19 22:55:06 +00005232 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005233 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005234 E->isArrow(),
5235 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005236 Qualifier,
5237 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005238 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005239 Name,
5240 E->getMemberLoc(),
5241 &TransArgs);
5242}
5243
5244template<typename Derived>
5245Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005246TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005247 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005248 OwningExprResult Base(SemaRef, (Expr*) 0);
5249 QualType BaseType;
5250 if (!Old->isImplicitAccess()) {
5251 Base = getDerived().TransformExpr(Old->getBase());
5252 if (Base.isInvalid())
5253 return SemaRef.ExprError();
5254 BaseType = ((Expr*) Base.get())->getType();
5255 } else {
5256 BaseType = getDerived().TransformType(Old->getBaseType());
5257 }
John McCall10eae182009-11-30 22:42:35 +00005258
5259 NestedNameSpecifier *Qualifier = 0;
5260 if (Old->getQualifier()) {
5261 Qualifier
5262 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005263 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005264 if (Qualifier == 0)
5265 return SemaRef.ExprError();
5266 }
5267
5268 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5269 Sema::LookupOrdinaryName);
5270
5271 // Transform all the decls.
5272 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5273 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005274 NamedDecl *InstD = static_cast<NamedDecl*>(
5275 getDerived().TransformDecl(Old->getMemberLoc(),
5276 *I));
John McCall84d87672009-12-10 09:41:52 +00005277 if (!InstD) {
5278 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5279 // This can happen because of dependent hiding.
5280 if (isa<UsingShadowDecl>(*I))
5281 continue;
5282 else
5283 return SemaRef.ExprError();
5284 }
John McCall10eae182009-11-30 22:42:35 +00005285
5286 // Expand using declarations.
5287 if (isa<UsingDecl>(InstD)) {
5288 UsingDecl *UD = cast<UsingDecl>(InstD);
5289 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5290 E = UD->shadow_end(); I != E; ++I)
5291 R.addDecl(*I);
5292 continue;
5293 }
5294
5295 R.addDecl(InstD);
5296 }
5297
5298 R.resolveKind();
5299
5300 TemplateArgumentListInfo TransArgs;
5301 if (Old->hasExplicitTemplateArgs()) {
5302 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5303 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5304 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5305 TemplateArgumentLoc Loc;
5306 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5307 Loc))
5308 return SemaRef.ExprError();
5309 TransArgs.addArgument(Loc);
5310 }
5311 }
John McCall38836f02010-01-15 08:34:02 +00005312
5313 // FIXME: to do this check properly, we will need to preserve the
5314 // first-qualifier-in-scope here, just in case we had a dependent
5315 // base (and therefore couldn't do the check) and a
5316 // nested-name-qualifier (and therefore could do the lookup).
5317 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005318
5319 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005320 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005321 Old->getOperatorLoc(),
5322 Old->isArrow(),
5323 Qualifier,
5324 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005325 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005326 R,
5327 (Old->hasExplicitTemplateArgs()
5328 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005329}
5330
5331template<typename Derived>
5332Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005333TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005334 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005335}
5336
Mike Stump11289f42009-09-09 15:08:12 +00005337template<typename Derived>
5338Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005339TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 // FIXME: poor source location
5341 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5342 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5343 if (EncodedType.isNull())
5344 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregora16548e2009-08-11 05:31:07 +00005346 if (!getDerived().AlwaysRebuild() &&
5347 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005348 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005349
5350 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5351 EncodedType,
5352 E->getRParenLoc());
5353}
Mike Stump11289f42009-09-09 15:08:12 +00005354
Douglas Gregora16548e2009-08-11 05:31:07 +00005355template<typename Derived>
5356Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // FIXME: Implement this!
5359 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005360 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005361}
5362
Mike Stump11289f42009-09-09 15:08:12 +00005363template<typename Derived>
5364Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005365TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005366 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005367}
5368
Mike Stump11289f42009-09-09 15:08:12 +00005369template<typename Derived>
5370Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005371TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005372 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005373 = cast_or_null<ObjCProtocolDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005374 getDerived().TransformDecl(E->getLocStart(),
5375 E->getProtocol()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 if (!Protocol)
5377 return SemaRef.ExprError();
5378
5379 if (!getDerived().AlwaysRebuild() &&
5380 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005381 return SemaRef.Owned(E->Retain());
5382
Douglas Gregora16548e2009-08-11 05:31:07 +00005383 return getDerived().RebuildObjCProtocolExpr(Protocol,
5384 E->getAtLoc(),
5385 /*FIXME:*/E->getAtLoc(),
5386 /*FIXME:*/E->getAtLoc(),
5387 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregora16548e2009-08-11 05:31:07 +00005389}
5390
Mike Stump11289f42009-09-09 15:08:12 +00005391template<typename Derived>
5392Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005393TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005394 // FIXME: Implement this!
5395 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005396 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005397}
5398
Mike Stump11289f42009-09-09 15:08:12 +00005399template<typename Derived>
5400Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005401TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 // FIXME: Implement this!
5403 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005404 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005405}
5406
Mike Stump11289f42009-09-09 15:08:12 +00005407template<typename Derived>
5408Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005409TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005410 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005411 // FIXME: Implement this!
5412 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005413 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005414}
5415
Mike Stump11289f42009-09-09 15:08:12 +00005416template<typename Derived>
5417Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005418TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 // FIXME: Implement this!
5420 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005421 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005422}
5423
Mike Stump11289f42009-09-09 15:08:12 +00005424template<typename Derived>
5425Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005426TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005427 // FIXME: Implement this!
5428 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005429 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005430}
5431
Mike Stump11289f42009-09-09 15:08:12 +00005432template<typename Derived>
5433Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005434TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 bool ArgumentChanged = false;
5436 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5437 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5438 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5439 if (SubExpr.isInvalid())
5440 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005441
Douglas Gregora16548e2009-08-11 05:31:07 +00005442 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5443 SubExprs.push_back(SubExpr.takeAs<Expr>());
5444 }
Mike Stump11289f42009-09-09 15:08:12 +00005445
Douglas Gregora16548e2009-08-11 05:31:07 +00005446 if (!getDerived().AlwaysRebuild() &&
5447 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005448 return SemaRef.Owned(E->Retain());
5449
Douglas Gregora16548e2009-08-11 05:31:07 +00005450 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5451 move_arg(SubExprs),
5452 E->getRParenLoc());
5453}
5454
Mike Stump11289f42009-09-09 15:08:12 +00005455template<typename Derived>
5456Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005457TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005458 // FIXME: Implement this!
5459 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005460 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005461}
5462
Mike Stump11289f42009-09-09 15:08:12 +00005463template<typename Derived>
5464Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005465TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005466 // FIXME: Implement this!
5467 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005468 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005469}
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregora16548e2009-08-11 05:31:07 +00005471//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005472// Type reconstruction
5473//===----------------------------------------------------------------------===//
5474
Mike Stump11289f42009-09-09 15:08:12 +00005475template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005476QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5477 SourceLocation Star) {
5478 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005479 getDerived().getBaseEntity());
5480}
5481
Mike Stump11289f42009-09-09 15:08:12 +00005482template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005483QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5484 SourceLocation Star) {
5485 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005486 getDerived().getBaseEntity());
5487}
5488
Mike Stump11289f42009-09-09 15:08:12 +00005489template<typename Derived>
5490QualType
John McCall70dd5f62009-10-30 00:06:24 +00005491TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5492 bool WrittenAsLValue,
5493 SourceLocation Sigil) {
5494 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5495 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005496}
5497
5498template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005499QualType
John McCall70dd5f62009-10-30 00:06:24 +00005500TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5501 QualType ClassType,
5502 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005503 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005504 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005505}
5506
5507template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005508QualType
John McCall70dd5f62009-10-30 00:06:24 +00005509TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5510 SourceLocation Sigil) {
5511 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005512 getDerived().getBaseEntity());
5513}
5514
5515template<typename Derived>
5516QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005517TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5518 ArrayType::ArraySizeModifier SizeMod,
5519 const llvm::APInt *Size,
5520 Expr *SizeExpr,
5521 unsigned IndexTypeQuals,
5522 SourceRange BracketsRange) {
5523 if (SizeExpr || !Size)
5524 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5525 IndexTypeQuals, BracketsRange,
5526 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005527
5528 QualType Types[] = {
5529 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5530 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5531 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005532 };
5533 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5534 QualType SizeType;
5535 for (unsigned I = 0; I != NumTypes; ++I)
5536 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5537 SizeType = Types[I];
5538 break;
5539 }
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregord6ff3322009-08-04 16:50:30 +00005541 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005542 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005543 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005544 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005545}
Mike Stump11289f42009-09-09 15:08:12 +00005546
Douglas Gregord6ff3322009-08-04 16:50:30 +00005547template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005548QualType
5549TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005550 ArrayType::ArraySizeModifier SizeMod,
5551 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005552 unsigned IndexTypeQuals,
5553 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005554 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005555 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005556}
5557
5558template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005559QualType
Mike Stump11289f42009-09-09 15:08:12 +00005560TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005561 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005562 unsigned IndexTypeQuals,
5563 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005564 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005565 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005566}
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregord6ff3322009-08-04 16:50:30 +00005568template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005569QualType
5570TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005571 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005573 unsigned IndexTypeQuals,
5574 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005575 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005576 SizeExpr.takeAs<Expr>(),
5577 IndexTypeQuals, BracketsRange);
5578}
5579
5580template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005581QualType
5582TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005583 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005585 unsigned IndexTypeQuals,
5586 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005587 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005588 SizeExpr.takeAs<Expr>(),
5589 IndexTypeQuals, BracketsRange);
5590}
5591
5592template<typename Derived>
5593QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005594 unsigned NumElements,
5595 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005596 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005597 return SemaRef.Context.getVectorType(ElementType, NumElements,
5598 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005599}
Mike Stump11289f42009-09-09 15:08:12 +00005600
Douglas Gregord6ff3322009-08-04 16:50:30 +00005601template<typename Derived>
5602QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5603 unsigned NumElements,
5604 SourceLocation AttributeLoc) {
5605 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5606 NumElements, true);
5607 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005608 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005609 AttributeLoc);
5610 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5611 AttributeLoc);
5612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
Douglas Gregord6ff3322009-08-04 16:50:30 +00005614template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005615QualType
5616TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005617 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005618 SourceLocation AttributeLoc) {
5619 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5620}
Mike Stump11289f42009-09-09 15:08:12 +00005621
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622template<typename Derived>
5623QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005624 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005625 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005626 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005627 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005628 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005629 Quals,
5630 getDerived().getBaseLocation(),
5631 getDerived().getBaseEntity());
5632}
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregord6ff3322009-08-04 16:50:30 +00005634template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005635QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5636 return SemaRef.Context.getFunctionNoProtoType(T);
5637}
5638
5639template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005640QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5641 assert(D && "no decl found");
5642 if (D->isInvalidDecl()) return QualType();
5643
5644 TypeDecl *Ty;
5645 if (isa<UsingDecl>(D)) {
5646 UsingDecl *Using = cast<UsingDecl>(D);
5647 assert(Using->isTypeName() &&
5648 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5649
5650 // A valid resolved using typename decl points to exactly one type decl.
5651 assert(++Using->shadow_begin() == Using->shadow_end());
5652 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5653
5654 } else {
5655 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5656 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5657 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5658 }
5659
5660 return SemaRef.Context.getTypeDeclType(Ty);
5661}
5662
5663template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005664QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005665 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5666}
5667
5668template<typename Derived>
5669QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5670 return SemaRef.Context.getTypeOfType(Underlying);
5671}
5672
5673template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005674QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005675 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5676}
5677
5678template<typename Derived>
5679QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005680 TemplateName Template,
5681 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005682 const TemplateArgumentListInfo &TemplateArgs) {
5683 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005684}
Mike Stump11289f42009-09-09 15:08:12 +00005685
Douglas Gregor1135c352009-08-06 05:28:30 +00005686template<typename Derived>
5687NestedNameSpecifier *
5688TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5689 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005690 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005691 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005692 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005693 CXXScopeSpec SS;
5694 // FIXME: The source location information is all wrong.
5695 SS.setRange(Range);
5696 SS.setScopeRep(Prefix);
5697 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005698 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005699 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005700 ObjectType,
5701 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005702 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005703}
5704
5705template<typename Derived>
5706NestedNameSpecifier *
5707TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5708 SourceRange Range,
5709 NamespaceDecl *NS) {
5710 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5711}
5712
5713template<typename Derived>
5714NestedNameSpecifier *
5715TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5716 SourceRange Range,
5717 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005718 QualType T) {
5719 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005720 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005721 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005722 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5723 T.getTypePtr());
5724 }
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregor1135c352009-08-06 05:28:30 +00005726 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5727 return 0;
5728}
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregor71dc5092009-08-06 06:41:21 +00005730template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005731TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005732TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5733 bool TemplateKW,
5734 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005735 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005736 Template);
5737}
5738
5739template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005740TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005741TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005742 const IdentifierInfo &II,
5743 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005744 CXXScopeSpec SS;
5745 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005746 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005747 UnqualifiedId Name;
5748 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005749 return getSema().ActOnDependentTemplateName(
5750 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005751 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005752 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005753 ObjectType.getAsOpaquePtr(),
5754 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005755 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005756}
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregora16548e2009-08-11 05:31:07 +00005758template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005759TemplateName
5760TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5761 OverloadedOperatorKind Operator,
5762 QualType ObjectType) {
5763 CXXScopeSpec SS;
5764 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5765 SS.setScopeRep(Qualifier);
5766 UnqualifiedId Name;
5767 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5768 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5769 Operator, SymbolLocations);
5770 return getSema().ActOnDependentTemplateName(
5771 /*FIXME:*/getDerived().getBaseLocation(),
5772 SS,
5773 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005774 ObjectType.getAsOpaquePtr(),
5775 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005776 .template getAsVal<TemplateName>();
5777}
5778
5779template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005780Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005781TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5782 SourceLocation OpLoc,
5783 ExprArg Callee,
5784 ExprArg First,
5785 ExprArg Second) {
5786 Expr *FirstExpr = (Expr *)First.get();
5787 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005788 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005789 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005790
Douglas Gregora16548e2009-08-11 05:31:07 +00005791 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005792 if (Op == OO_Subscript) {
5793 if (!FirstExpr->getType()->isOverloadableType() &&
5794 !SecondExpr->getType()->isOverloadableType())
5795 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005796 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005797 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005798 } else if (Op == OO_Arrow) {
5799 // -> is never a builtin operation.
5800 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005801 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005802 if (!FirstExpr->getType()->isOverloadableType()) {
5803 // The argument is not of overloadable type, so try to create a
5804 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005805 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005806 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5809 }
5810 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005811 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005812 !SecondExpr->getType()->isOverloadableType()) {
5813 // Neither of the arguments is an overloadable type, so try to
5814 // create a built-in binary operation.
5815 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005816 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5818 if (Result.isInvalid())
5819 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregora16548e2009-08-11 05:31:07 +00005821 First.release();
5822 Second.release();
5823 return move(Result);
5824 }
5825 }
Mike Stump11289f42009-09-09 15:08:12 +00005826
5827 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005829 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005830
John McCalld14a8642009-11-21 08:51:07 +00005831 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5832 assert(ULE->requiresADL());
5833
5834 // FIXME: Do we have to check
5835 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005836 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005837 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005838 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005839 }
Mike Stump11289f42009-09-09 15:08:12 +00005840
Douglas Gregora16548e2009-08-11 05:31:07 +00005841 // Add any functions found via argument-dependent lookup.
5842 Expr *Args[2] = { FirstExpr, SecondExpr };
5843 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845 // Create the overloaded operator invocation for unary operators.
5846 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005847 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5849 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5850 }
Mike Stump11289f42009-09-09 15:08:12 +00005851
Sebastian Redladba46e2009-10-29 20:17:01 +00005852 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005853 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5854 OpLoc,
5855 move(First),
5856 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005857
Douglas Gregora16548e2009-08-11 05:31:07 +00005858 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005859 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005861 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005862 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5863 if (Result.isInvalid())
5864 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005865
Douglas Gregora16548e2009-08-11 05:31:07 +00005866 First.release();
5867 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005868 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005869}
Mike Stump11289f42009-09-09 15:08:12 +00005870
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005871template<typename Derived>
5872Sema::OwningExprResult
5873TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5874 SourceLocation OperatorLoc,
5875 bool isArrow,
5876 NestedNameSpecifier *Qualifier,
5877 SourceRange QualifierRange,
5878 TypeSourceInfo *ScopeType,
5879 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005880 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005881 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005882 CXXScopeSpec SS;
5883 if (Qualifier) {
5884 SS.setRange(QualifierRange);
5885 SS.setScopeRep(Qualifier);
5886 }
5887
5888 Expr *BaseE = (Expr *)Base.get();
5889 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005890 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005891 (!isArrow && !BaseType->getAs<RecordType>()) ||
5892 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00005893 !BaseType->getAs<PointerType>()->getPointeeType()
5894 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005895 // This pseudo-destructor expression is still a pseudo-destructor.
5896 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5897 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005898 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005899 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005900 /*FIXME?*/true);
5901 }
5902
Douglas Gregor678f90d2010-02-25 01:56:36 +00005903 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005904 DeclarationName Name
5905 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5906 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5907
5908 // FIXME: the ScopeType should be tacked onto SS.
5909
5910 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5911 OperatorLoc, isArrow,
5912 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005913 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005914 /*TemplateArgs*/ 0);
5915}
5916
Douglas Gregord6ff3322009-08-04 16:50:30 +00005917} // end namespace clang
5918
5919#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H