blob: a59608661c48b0196b67367f84111f821d5ddfe4 [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.
240 Decl *TransformDecl(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.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
277 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000278 SourceLocation Loc,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000315
Douglas Gregorfe17d252010-02-16 19:09:40 +0000316 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
317 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000318
Douglas Gregorc59e5612009-10-19 22:04:39 +0000319 QualType
320 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
321 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000322
Douglas Gregorebe10102009-08-20 07:17:43 +0000323 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000324
Douglas Gregorebe10102009-08-20 07:17:43 +0000325#define STMT(Node, Parent) \
326 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000327#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000328 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000329#define ABSTRACT_EXPR(Node, Parent)
330#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000331
Douglas Gregord6ff3322009-08-04 16:50:30 +0000332 /// \brief Build a new pointer type given its pointee type.
333 ///
334 /// By default, performs semantic analysis when building the pointer type.
335 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000336 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000337
338 /// \brief Build a new block pointer type given its pointee type.
339 ///
Mike Stump11289f42009-09-09 15:08:12 +0000340 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000341 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000342 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000343
John McCall70dd5f62009-10-30 00:06:24 +0000344 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000345 ///
John McCall70dd5f62009-10-30 00:06:24 +0000346 /// By default, performs semantic analysis when building the
347 /// reference type. Subclasses may override this routine to provide
348 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 ///
John McCall70dd5f62009-10-30 00:06:24 +0000350 /// \param LValue whether the type was written with an lvalue sigil
351 /// or an rvalue sigil.
352 QualType RebuildReferenceType(QualType ReferentType,
353 bool LValue,
354 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000355
Douglas Gregord6ff3322009-08-04 16:50:30 +0000356 /// \brief Build a new member pointer type given the pointee type and the
357 /// class type it refers into.
358 ///
359 /// By default, performs semantic analysis when building the member pointer
360 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000361 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
362 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000363
John McCall550e0c22009-10-21 00:40:46 +0000364 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000365 QualType RebuildObjCObjectPointerType(QualType PointeeType,
366 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000367
Douglas Gregord6ff3322009-08-04 16:50:30 +0000368 /// \brief Build a new array type given the element type, size
369 /// modifier, size of the array (if known), size expression, and index type
370 /// qualifiers.
371 ///
372 /// By default, performs semantic analysis when building the array type.
373 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000374 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000375 QualType RebuildArrayType(QualType ElementType,
376 ArrayType::ArraySizeModifier SizeMod,
377 const llvm::APInt *Size,
378 Expr *SizeExpr,
379 unsigned IndexTypeQuals,
380 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new constant array type given the element type, size
383 /// modifier, (known) size of the array, and index type qualifiers.
384 ///
385 /// By default, performs semantic analysis when building the array type.
386 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000387 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000390 unsigned IndexTypeQuals,
391 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393 /// \brief Build a new incomplete array type given the element type, size
394 /// modifier, and index type qualifiers.
395 ///
396 /// By default, performs semantic analysis when building the array type.
397 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000398 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000400 unsigned IndexTypeQuals,
401 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402
Mike Stump11289f42009-09-09 15:08:12 +0000403 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404 /// size modifier, size expression, and index type qualifiers.
405 ///
406 /// By default, performs semantic analysis when building the array type.
407 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000408 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000410 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 unsigned IndexTypeQuals,
412 SourceRange BracketsRange);
413
Mike Stump11289f42009-09-09 15:08:12 +0000414 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000415 /// size modifier, size expression, and index type qualifiers.
416 ///
417 /// By default, performs semantic analysis when building the array type.
418 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000419 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000420 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000421 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 unsigned IndexTypeQuals,
423 SourceRange BracketsRange);
424
425 /// \brief Build a new vector type given the element type and
426 /// number of elements.
427 ///
428 /// By default, performs semantic analysis when building the vector type.
429 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000430 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
431 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000432
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000458
John McCall550e0c22009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCallb96ec562009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregord6ff3322009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCallfcc33b02009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump11289f42009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000491
Mike Stump11289f42009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump11289f42009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000519 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000527 if (NNS->isDependent()) {
528 CXXScopeSpec SS;
529 SS.setScopeRep(NNS);
530 if (!SemaRef.computeDeclContext(SS))
531 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000533 }
Mike Stump11289f42009-09-09 15:08:12 +0000534
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000536 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to an identifier.
539 ///
540 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000541 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000543 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000544 const IdentifierInfo *Id,
545 SourceRange SR) {
546 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000547 }
Mike Stump11289f42009-09-09 15:08:12 +0000548
Douglas Gregor1135c352009-08-06 05:28:30 +0000549 /// \brief Build a new nested-name-specifier given the prefix and an
550 /// identifier that names the next step in the nested-name-specifier.
551 ///
552 /// By default, performs semantic analysis when building the new
553 /// nested-name-specifier. Subclasses may override this routine to provide
554 /// different behavior.
555 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
556 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000557 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000558 QualType ObjectType,
559 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000560
561 /// \brief Build a new nested-name-specifier given the prefix and the
562 /// namespace named in the next step in the nested-name-specifier.
563 ///
564 /// By default, performs semantic analysis when building the new
565 /// nested-name-specifier. Subclasses may override this routine to provide
566 /// different behavior.
567 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
568 SourceRange Range,
569 NamespaceDecl *NS);
570
571 /// \brief Build a new nested-name-specifier given the prefix and the
572 /// type named in the next step in the nested-name-specifier.
573 ///
574 /// By default, performs semantic analysis when building the new
575 /// nested-name-specifier. Subclasses may override this routine to provide
576 /// different behavior.
577 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
578 SourceRange Range,
579 bool TemplateKW,
580 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000581
582 /// \brief Build a new template name given a nested name specifier, a flag
583 /// indicating whether the "template" keyword was provided, and the template
584 /// that the template name refers to.
585 ///
586 /// By default, builds the new template name directly. Subclasses may override
587 /// this routine to provide different behavior.
588 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
589 bool TemplateKW,
590 TemplateDecl *Template);
591
Douglas Gregor71dc5092009-08-06 06:41:21 +0000592 /// \brief Build a new template name given a nested name specifier and the
593 /// name that is referred to as a template.
594 ///
595 /// By default, performs semantic analysis to determine whether the name can
596 /// be resolved to a specific template, then builds the appropriate kind of
597 /// template name. Subclasses may override this routine to provide different
598 /// behavior.
599 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000600 const IdentifierInfo &II,
601 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000602
Douglas Gregor71395fa2009-11-04 00:56:37 +0000603 /// \brief Build a new template name given a nested name specifier and the
604 /// overloaded operator name that is referred to as a template.
605 ///
606 /// By default, performs semantic analysis to determine whether the name can
607 /// be resolved to a specific template, then builds the appropriate kind of
608 /// template name. Subclasses may override this routine to provide different
609 /// behavior.
610 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
611 OverloadedOperatorKind Operator,
612 QualType ObjectType);
613
Douglas Gregorebe10102009-08-20 07:17:43 +0000614 /// \brief Build a new compound statement.
615 ///
616 /// By default, performs semantic analysis to build the new statement.
617 /// Subclasses may override this routine to provide different behavior.
618 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
619 MultiStmtArg Statements,
620 SourceLocation RBraceLoc,
621 bool IsStmtExpr) {
622 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
623 IsStmtExpr);
624 }
625
626 /// \brief Build a new case statement.
627 ///
628 /// By default, performs semantic analysis to build the new statement.
629 /// Subclasses may override this routine to provide different behavior.
630 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
631 ExprArg LHS,
632 SourceLocation EllipsisLoc,
633 ExprArg RHS,
634 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000635 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000636 ColonLoc);
637 }
Mike Stump11289f42009-09-09 15:08:12 +0000638
Douglas Gregorebe10102009-08-20 07:17:43 +0000639 /// \brief Attach the body to a new case statement.
640 ///
641 /// By default, performs semantic analysis to build the new statement.
642 /// Subclasses may override this routine to provide different behavior.
643 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
644 getSema().ActOnCaseStmtBody(S.get(), move(Body));
645 return move(S);
646 }
Mike Stump11289f42009-09-09 15:08:12 +0000647
Douglas Gregorebe10102009-08-20 07:17:43 +0000648 /// \brief Build a new default statement.
649 ///
650 /// By default, performs semantic analysis to build the new statement.
651 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000652 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 SourceLocation ColonLoc,
654 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000655 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /*CurScope=*/0);
657 }
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregorebe10102009-08-20 07:17:43 +0000659 /// \brief Build a new label statement.
660 ///
661 /// By default, performs semantic analysis to build the new statement.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000663 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000664 IdentifierInfo *Id,
665 SourceLocation ColonLoc,
666 StmtArg SubStmt) {
667 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
668 }
Mike Stump11289f42009-09-09 15:08:12 +0000669
Douglas Gregorebe10102009-08-20 07:17:43 +0000670 /// \brief Build a new "if" statement.
671 ///
672 /// By default, performs semantic analysis to build the new statement.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000674 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000675 VarDecl *CondVar, StmtArg Then,
676 SourceLocation ElseLoc, StmtArg Else) {
677 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
678 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000679 }
Mike Stump11289f42009-09-09 15:08:12 +0000680
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 /// \brief Start building a new switch statement.
682 ///
683 /// By default, performs semantic analysis to build the new statement.
684 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000685 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
686 VarDecl *CondVar) {
687 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000688 }
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 /// \brief Attach the body to the switch statement.
691 ///
692 /// By default, performs semantic analysis to build the new statement.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000695 StmtArg Switch, StmtArg Body) {
696 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
697 move(Body));
698 }
699
700 /// \brief Build a new while statement.
701 ///
702 /// By default, performs semantic analysis to build the new statement.
703 /// Subclasses may override this routine to provide different behavior.
704 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
705 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000706 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000708 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
709 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 }
Mike Stump11289f42009-09-09 15:08:12 +0000711
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 /// \brief Build a new do-while statement.
713 ///
714 /// By default, performs semantic analysis to build the new statement.
715 /// Subclasses may override this routine to provide different behavior.
716 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
717 SourceLocation WhileLoc,
718 SourceLocation LParenLoc,
719 ExprArg Cond,
720 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000721 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000722 move(Cond), RParenLoc);
723 }
724
725 /// \brief Build a new for statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000731 StmtArg Init, Sema::FullExprArg Cond,
732 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000734 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
735 DeclPtrTy::make(CondVar),
736 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 }
Mike Stump11289f42009-09-09 15:08:12 +0000738
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 /// \brief Build a new goto statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
743 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
744 SourceLocation LabelLoc,
745 LabelStmt *Label) {
746 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
747 }
748
749 /// \brief Build a new indirect goto statement.
750 ///
751 /// By default, performs semantic analysis to build the new statement.
752 /// Subclasses may override this routine to provide different behavior.
753 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
754 SourceLocation StarLoc,
755 ExprArg Target) {
756 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
757 }
Mike Stump11289f42009-09-09 15:08:12 +0000758
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 /// \brief Build a new return statement.
760 ///
761 /// By default, performs semantic analysis to build the new statement.
762 /// Subclasses may override this routine to provide different behavior.
763 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
764 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000765
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Build a new declaration statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
773 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000774 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 SourceLocation EndLoc) {
776 return getSema().Owned(
777 new (getSema().Context) DeclStmt(
778 DeclGroupRef::Create(getSema().Context,
779 Decls, NumDecls),
780 StartLoc, EndLoc));
781 }
Mike Stump11289f42009-09-09 15:08:12 +0000782
Anders Carlssonaaeef072010-01-24 05:50:09 +0000783 /// \brief Build a new inline asm statement.
784 ///
785 /// By default, performs semantic analysis to build the new statement.
786 /// Subclasses may override this routine to provide different behavior.
787 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
788 bool IsSimple,
789 bool IsVolatile,
790 unsigned NumOutputs,
791 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000792 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000793 MultiExprArg Constraints,
794 MultiExprArg Exprs,
795 ExprArg AsmString,
796 MultiExprArg Clobbers,
797 SourceLocation RParenLoc,
798 bool MSAsm) {
799 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
800 NumInputs, Names, move(Constraints),
801 move(Exprs), move(AsmString), move(Clobbers),
802 RParenLoc, MSAsm);
803 }
804
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 /// \brief Build a new C++ exception declaration.
806 ///
807 /// By default, performs semantic analysis to build the new decaration.
808 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000809 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000810 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000811 IdentifierInfo *Name,
812 SourceLocation Loc,
813 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000814 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 TypeRange);
816 }
817
818 /// \brief Build a new C++ catch statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
822 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
823 VarDecl *ExceptionDecl,
824 StmtArg Handler) {
825 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000826 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 Handler.takeAs<Stmt>()));
828 }
Mike Stump11289f42009-09-09 15:08:12 +0000829
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 /// \brief Build a new C++ try statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
834 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
835 StmtArg TryBlock,
836 MultiStmtArg Handlers) {
837 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
838 }
Mike Stump11289f42009-09-09 15:08:12 +0000839
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 /// \brief Build a new expression that references a declaration.
841 ///
842 /// By default, performs semantic analysis to build the new expression.
843 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000844 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
845 LookupResult &R,
846 bool RequiresADL) {
847 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
848 }
849
850
851 /// \brief Build a new expression that references a declaration.
852 ///
853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000855 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
856 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000857 ValueDecl *VD, SourceLocation Loc,
858 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000859 CXXScopeSpec SS;
860 SS.setScopeRep(Qualifier);
861 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000862
863 // FIXME: loses template args.
864
865 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000866 }
Mike Stump11289f42009-09-09 15:08:12 +0000867
Douglas Gregora16548e2009-08-11 05:31:07 +0000868 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000869 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000870 /// By default, performs semantic analysis to build the new expression.
871 /// Subclasses may override this routine to provide different behavior.
872 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
873 SourceLocation RParen) {
874 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
875 }
876
Douglas Gregorad8a3362009-09-04 17:36:40 +0000877 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000878 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000879 /// By default, performs semantic analysis to build the new expression.
880 /// Subclasses may override this routine to provide different behavior.
881 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
882 SourceLocation OperatorLoc,
883 bool isArrow,
884 SourceLocation DestroyedTypeLoc,
885 QualType DestroyedType,
886 NestedNameSpecifier *Qualifier,
887 SourceRange QualifierRange) {
888 CXXScopeSpec SS;
889 if (Qualifier) {
890 SS.setRange(QualifierRange);
891 SS.setScopeRep(Qualifier);
892 }
893
John McCall2d74de92009-12-01 22:10:20 +0000894 QualType BaseType = ((Expr*) Base.get())->getType();
895
Mike Stump11289f42009-09-09 15:08:12 +0000896 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000897 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
898 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000899
John McCall2d74de92009-12-01 22:10:20 +0000900 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
901 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000902 SS, /*FIXME: FirstQualifier*/ 0,
903 Name, DestroyedTypeLoc,
904 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000905 }
906
Douglas Gregora16548e2009-08-11 05:31:07 +0000907 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000908 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 /// By default, performs semantic analysis to build the new expression.
910 /// Subclasses may override this routine to provide different behavior.
911 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
912 UnaryOperator::Opcode Opc,
913 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000914 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000915 }
Mike Stump11289f42009-09-09 15:08:12 +0000916
Douglas Gregora16548e2009-08-11 05:31:07 +0000917 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000918 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000919 /// By default, performs semantic analysis to build the new expression.
920 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000921 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000922 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000924 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000925 }
926
Mike Stump11289f42009-09-09 15:08:12 +0000927 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000929 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 /// By default, performs semantic analysis to build the new expression.
931 /// Subclasses may override this routine to provide different behavior.
932 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
933 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000934 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
936 OpLoc, isSizeOf, R);
937 if (Result.isInvalid())
938 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000939
Douglas Gregora16548e2009-08-11 05:31:07 +0000940 SubExpr.release();
941 return move(Result);
942 }
Mike Stump11289f42009-09-09 15:08:12 +0000943
Douglas Gregora16548e2009-08-11 05:31:07 +0000944 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000945 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000946 /// By default, performs semantic analysis to build the new expression.
947 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000948 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000949 SourceLocation LBracketLoc,
950 ExprArg RHS,
951 SourceLocation RBracketLoc) {
952 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000953 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000954 RBracketLoc);
955 }
956
957 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000958 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000959 /// By default, performs semantic analysis to build the new expression.
960 /// Subclasses may override this routine to provide different behavior.
961 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
962 MultiExprArg Args,
963 SourceLocation *CommaLocs,
964 SourceLocation RParenLoc) {
965 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
966 move(Args), CommaLocs, RParenLoc);
967 }
968
969 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000970 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000971 /// By default, performs semantic analysis to build the new expression.
972 /// Subclasses may override this routine to provide different behavior.
973 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000974 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000975 NestedNameSpecifier *Qualifier,
976 SourceRange QualifierRange,
977 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000978 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000979 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000980 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000981 if (!Member->getDeclName()) {
982 // We have a reference to an unnamed field.
983 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000985 Expr *BaseExpr = Base.takeAs<Expr>();
986 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
987 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000988
Mike Stump11289f42009-09-09 15:08:12 +0000989 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000990 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000991 Member, MemberLoc,
992 cast<FieldDecl>(Member)->getType());
993 return getSema().Owned(ME);
994 }
Mike Stump11289f42009-09-09 15:08:12 +0000995
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000996 CXXScopeSpec SS;
997 if (Qualifier) {
998 SS.setRange(QualifierRange);
999 SS.setScopeRep(Qualifier);
1000 }
1001
John McCall2d74de92009-12-01 22:10:20 +00001002 QualType BaseType = ((Expr*) Base.get())->getType();
1003
John McCall38836f02010-01-15 08:34:02 +00001004 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1005 Sema::LookupMemberName);
1006 R.addDecl(Member);
1007 R.resolveKind();
1008
John McCall2d74de92009-12-01 22:10:20 +00001009 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1010 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001011 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001012 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001013 }
Mike Stump11289f42009-09-09 15:08:12 +00001014
Douglas Gregora16548e2009-08-11 05:31:07 +00001015 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001016 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001017 /// By default, performs semantic analysis to build the new expression.
1018 /// Subclasses may override this routine to provide different behavior.
1019 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1020 BinaryOperator::Opcode Opc,
1021 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001022 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1023 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 }
1025
1026 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001027 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001028 /// By default, performs semantic analysis to build the new expression.
1029 /// Subclasses may override this routine to provide different behavior.
1030 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1031 SourceLocation QuestionLoc,
1032 ExprArg LHS,
1033 SourceLocation ColonLoc,
1034 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001035 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001036 move(LHS), move(RHS));
1037 }
1038
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001040 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 /// By default, performs semantic analysis to build the new expression.
1042 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001043 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1044 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 SourceLocation RParenLoc,
1046 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001047 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1048 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001052 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
1055 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001056 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001057 SourceLocation RParenLoc,
1058 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001059 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1060 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001061 }
Mike Stump11289f42009-09-09 15:08:12 +00001062
Douglas Gregora16548e2009-08-11 05:31:07 +00001063 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001064 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// By default, performs semantic analysis to build the new expression.
1066 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001067 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 SourceLocation OpLoc,
1069 SourceLocation AccessorLoc,
1070 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001071
John McCall10eae182009-11-30 22:42:35 +00001072 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001073 QualType BaseType = ((Expr*) Base.get())->getType();
1074 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001075 OpLoc, /*IsArrow*/ false,
1076 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001077 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001078 AccessorLoc,
1079 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001080 }
Mike Stump11289f42009-09-09 15:08:12 +00001081
Douglas Gregora16548e2009-08-11 05:31:07 +00001082 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001083 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 /// By default, performs semantic analysis to build the new expression.
1085 /// Subclasses may override this routine to provide different behavior.
1086 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1087 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001088 SourceLocation RBraceLoc,
1089 QualType ResultTy) {
1090 OwningExprResult Result
1091 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1092 if (Result.isInvalid() || ResultTy->isDependentType())
1093 return move(Result);
1094
1095 // Patch in the result type we were given, which may have been computed
1096 // when the initial InitListExpr was built.
1097 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1098 ILE->setType(ResultTy);
1099 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 }
Mike Stump11289f42009-09-09 15:08:12 +00001101
Douglas Gregora16548e2009-08-11 05:31:07 +00001102 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001103 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// By default, performs semantic analysis to build the new expression.
1105 /// Subclasses may override this routine to provide different behavior.
1106 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1107 MultiExprArg ArrayExprs,
1108 SourceLocation EqualOrColonLoc,
1109 bool GNUSyntax,
1110 ExprArg Init) {
1111 OwningExprResult Result
1112 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1113 move(Init));
1114 if (Result.isInvalid())
1115 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001116
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 ArrayExprs.release();
1118 return move(Result);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001122 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 /// By default, builds the implicit value initialization without performing
1124 /// any semantic analysis. Subclasses may override this routine to provide
1125 /// different behavior.
1126 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1127 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001131 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 /// By default, performs semantic analysis to build the new expression.
1133 /// Subclasses may override this routine to provide different behavior.
1134 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1135 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001136 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 RParenLoc);
1138 }
1139
1140 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001141 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
1144 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1145 MultiExprArg SubExprs,
1146 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001147 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1148 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001149 }
Mike Stump11289f42009-09-09 15:08:12 +00001150
Douglas Gregora16548e2009-08-11 05:31:07 +00001151 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001152 ///
1153 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 /// rather than attempting to map the label statement itself.
1155 /// Subclasses may override this routine to provide different behavior.
1156 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1157 SourceLocation LabelLoc,
1158 LabelStmt *Label) {
1159 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1160 }
Mike Stump11289f42009-09-09 15:08:12 +00001161
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001163 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001164 /// By default, performs semantic analysis to build the new expression.
1165 /// Subclasses may override this routine to provide different behavior.
1166 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1167 StmtArg SubStmt,
1168 SourceLocation RParenLoc) {
1169 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1170 }
Mike Stump11289f42009-09-09 15:08:12 +00001171
Douglas Gregora16548e2009-08-11 05:31:07 +00001172 /// \brief Build a new __builtin_types_compatible_p expression.
1173 ///
1174 /// By default, performs semantic analysis to build the new expression.
1175 /// Subclasses may override this routine to provide different behavior.
1176 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1177 QualType T1, QualType T2,
1178 SourceLocation RParenLoc) {
1179 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1180 T1.getAsOpaquePtr(),
1181 T2.getAsOpaquePtr(),
1182 RParenLoc);
1183 }
Mike Stump11289f42009-09-09 15:08:12 +00001184
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// \brief Build a new __builtin_choose_expr expression.
1186 ///
1187 /// By default, performs semantic analysis to build the new expression.
1188 /// Subclasses may override this routine to provide different behavior.
1189 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1190 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1191 SourceLocation RParenLoc) {
1192 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1193 move(Cond), move(LHS), move(RHS),
1194 RParenLoc);
1195 }
Mike Stump11289f42009-09-09 15:08:12 +00001196
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// \brief Build a new overloaded operator call expression.
1198 ///
1199 /// By default, performs semantic analysis to build the new expression.
1200 /// The semantic analysis provides the behavior of template instantiation,
1201 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001202 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 /// argument-dependent lookup, etc. Subclasses may override this routine to
1204 /// provide different behavior.
1205 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1206 SourceLocation OpLoc,
1207 ExprArg Callee,
1208 ExprArg First,
1209 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001210
1211 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001212 /// reinterpret_cast.
1213 ///
1214 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001215 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 /// Subclasses may override this routine to provide different behavior.
1217 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1218 Stmt::StmtClass Class,
1219 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001220 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 SourceLocation RAngleLoc,
1222 SourceLocation LParenLoc,
1223 ExprArg SubExpr,
1224 SourceLocation RParenLoc) {
1225 switch (Class) {
1226 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001227 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001228 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 move(SubExpr), RParenLoc);
1230
1231 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001232 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001233 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001237 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001238 RAngleLoc, LParenLoc,
1239 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001243 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001244 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001246
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 default:
1248 assert(false && "Invalid C++ named cast");
1249 break;
1250 }
Mike Stump11289f42009-09-09 15:08:12 +00001251
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 return getSema().ExprError();
1253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 /// \brief Build a new C++ static_cast expression.
1256 ///
1257 /// By default, performs semantic analysis to build the new expression.
1258 /// Subclasses may override this routine to provide different behavior.
1259 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1260 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001261 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 SourceLocation RAngleLoc,
1263 SourceLocation LParenLoc,
1264 ExprArg SubExpr,
1265 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001266 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1267 TInfo, move(SubExpr),
1268 SourceRange(LAngleLoc, RAngleLoc),
1269 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001270 }
1271
1272 /// \brief Build a new C++ dynamic_cast expression.
1273 ///
1274 /// By default, performs semantic analysis to build the new expression.
1275 /// Subclasses may override this routine to provide different behavior.
1276 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1277 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001278 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 SourceLocation RAngleLoc,
1280 SourceLocation LParenLoc,
1281 ExprArg SubExpr,
1282 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001283 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1284 TInfo, move(SubExpr),
1285 SourceRange(LAngleLoc, RAngleLoc),
1286 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 }
1288
1289 /// \brief Build a new C++ reinterpret_cast expression.
1290 ///
1291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
1293 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1294 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001295 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 SourceLocation RAngleLoc,
1297 SourceLocation LParenLoc,
1298 ExprArg SubExpr,
1299 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001300 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1301 TInfo, move(SubExpr),
1302 SourceRange(LAngleLoc, RAngleLoc),
1303 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001304 }
1305
1306 /// \brief Build a new C++ const_cast expression.
1307 ///
1308 /// By default, performs semantic analysis to build the new expression.
1309 /// Subclasses may override this routine to provide different behavior.
1310 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1311 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001312 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 SourceLocation RAngleLoc,
1314 SourceLocation LParenLoc,
1315 ExprArg SubExpr,
1316 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001317 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1318 TInfo, move(SubExpr),
1319 SourceRange(LAngleLoc, RAngleLoc),
1320 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 }
Mike Stump11289f42009-09-09 15:08:12 +00001322
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// \brief Build a new C++ functional-style cast expression.
1324 ///
1325 /// By default, performs semantic analysis to build the new expression.
1326 /// Subclasses may override this routine to provide different behavior.
1327 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001328 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 SourceLocation LParenLoc,
1330 ExprArg SubExpr,
1331 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001332 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001334 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001336 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001337 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 RParenLoc);
1339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new C++ typeid(type) expression.
1342 ///
1343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
1345 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1346 SourceLocation LParenLoc,
1347 QualType T,
1348 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001349 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 T.getAsOpaquePtr(), RParenLoc);
1351 }
Mike Stump11289f42009-09-09 15:08:12 +00001352
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 /// \brief Build a new C++ typeid(expr) expression.
1354 ///
1355 /// By default, performs semantic analysis to build the new expression.
1356 /// Subclasses may override this routine to provide different behavior.
1357 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1358 SourceLocation LParenLoc,
1359 ExprArg Operand,
1360 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001361 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001362 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1363 RParenLoc);
1364 if (Result.isInvalid())
1365 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001366
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1368 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001369 }
1370
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 /// \brief Build a new C++ "this" expression.
1372 ///
1373 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001374 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001376 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001377 QualType ThisType,
1378 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001380 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1381 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 }
1383
1384 /// \brief Build a new C++ throw expression.
1385 ///
1386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
1388 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1389 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1390 }
1391
1392 /// \brief Build a new C++ default-argument expression.
1393 ///
1394 /// By default, builds a new default-argument expression, which does not
1395 /// require any semantic analysis. Subclasses may override this routine to
1396 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001397 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1398 ParmVarDecl *Param) {
1399 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1400 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 }
1402
1403 /// \brief Build a new C++ zero-initialization 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 RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 SourceLocation LParenLoc,
1409 QualType T,
1410 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001411 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1412 T.getAsOpaquePtr(), LParenLoc,
1413 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 0, RParenLoc);
1415 }
Mike Stump11289f42009-09-09 15:08:12 +00001416
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 /// \brief Build a new C++ "new" expression.
1418 ///
1419 /// By default, performs semantic analysis to build the new expression.
1420 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001421 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 bool UseGlobal,
1423 SourceLocation PlacementLParen,
1424 MultiExprArg PlacementArgs,
1425 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001426 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001427 QualType AllocType,
1428 SourceLocation TypeLoc,
1429 SourceRange TypeRange,
1430 ExprArg ArraySize,
1431 SourceLocation ConstructorLParen,
1432 MultiExprArg ConstructorArgs,
1433 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001434 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 PlacementLParen,
1436 move(PlacementArgs),
1437 PlacementRParen,
1438 ParenTypeId,
1439 AllocType,
1440 TypeLoc,
1441 TypeRange,
1442 move(ArraySize),
1443 ConstructorLParen,
1444 move(ConstructorArgs),
1445 ConstructorRParen);
1446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 /// \brief Build a new C++ "delete" expression.
1449 ///
1450 /// By default, performs semantic analysis to build the new expression.
1451 /// Subclasses may override this routine to provide different behavior.
1452 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1453 bool IsGlobalDelete,
1454 bool IsArrayForm,
1455 ExprArg Operand) {
1456 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1457 move(Operand));
1458 }
Mike Stump11289f42009-09-09 15:08:12 +00001459
Douglas Gregora16548e2009-08-11 05:31:07 +00001460 /// \brief Build a new unary type trait expression.
1461 ///
1462 /// By default, performs semantic analysis to build the new expression.
1463 /// Subclasses may override this routine to provide different behavior.
1464 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1465 SourceLocation StartLoc,
1466 SourceLocation LParenLoc,
1467 QualType T,
1468 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001469 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 T.getAsOpaquePtr(), RParenLoc);
1471 }
1472
Mike Stump11289f42009-09-09 15:08:12 +00001473 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001474 /// expression.
1475 ///
1476 /// By default, performs semantic analysis to build the new expression.
1477 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001478 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 SourceRange QualifierRange,
1480 DeclarationName Name,
1481 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001482 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 CXXScopeSpec SS;
1484 SS.setRange(QualifierRange);
1485 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001486
1487 if (TemplateArgs)
1488 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1489 *TemplateArgs);
1490
1491 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 }
1493
1494 /// \brief Build a new template-id expression.
1495 ///
1496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001498 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1499 LookupResult &R,
1500 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001501 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001502 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 }
1504
1505 /// \brief Build a new object-construction expression.
1506 ///
1507 /// By default, performs semantic analysis to build the new expression.
1508 /// Subclasses may override this routine to provide different behavior.
1509 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001510 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 CXXConstructorDecl *Constructor,
1512 bool IsElidable,
1513 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001514 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1515 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1516 ConvertedArgs))
1517 return getSema().ExprError();
1518
1519 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1520 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 }
1522
1523 /// \brief Build a new object-construction expression.
1524 ///
1525 /// By default, performs semantic analysis to build the new expression.
1526 /// Subclasses may override this routine to provide different behavior.
1527 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1528 QualType T,
1529 SourceLocation LParenLoc,
1530 MultiExprArg Args,
1531 SourceLocation *Commas,
1532 SourceLocation RParenLoc) {
1533 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1534 T.getAsOpaquePtr(),
1535 LParenLoc,
1536 move(Args),
1537 Commas,
1538 RParenLoc);
1539 }
1540
1541 /// \brief Build a new object-construction expression.
1542 ///
1543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
1545 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1546 QualType T,
1547 SourceLocation LParenLoc,
1548 MultiExprArg Args,
1549 SourceLocation *Commas,
1550 SourceLocation RParenLoc) {
1551 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1552 /*FIXME*/LParenLoc),
1553 T.getAsOpaquePtr(),
1554 LParenLoc,
1555 move(Args),
1556 Commas,
1557 RParenLoc);
1558 }
Mike Stump11289f42009-09-09 15:08:12 +00001559
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// \brief Build a new member reference expression.
1561 ///
1562 /// By default, performs semantic analysis to build the new expression.
1563 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001564 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001565 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 bool IsArrow,
1567 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001568 NestedNameSpecifier *Qualifier,
1569 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001570 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001571 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001572 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001573 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001575 SS.setRange(QualifierRange);
1576 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001577
John McCall2d74de92009-12-01 22:10:20 +00001578 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1579 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001580 SS, FirstQualifierInScope,
1581 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001582 }
1583
John McCall10eae182009-11-30 22:42:35 +00001584 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001588 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001589 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001590 SourceLocation OperatorLoc,
1591 bool IsArrow,
1592 NestedNameSpecifier *Qualifier,
1593 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001594 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001595 LookupResult &R,
1596 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001597 CXXScopeSpec SS;
1598 SS.setRange(QualifierRange);
1599 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001600
John McCall2d74de92009-12-01 22:10:20 +00001601 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1602 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001603 SS, FirstQualifierInScope,
1604 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001605 }
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// \brief Build a new Objective-C @encode expression.
1608 ///
1609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1612 QualType T,
1613 SourceLocation RParenLoc) {
1614 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1615 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001616 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001617
1618 /// \brief Build a new Objective-C protocol expression.
1619 ///
1620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
1622 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1623 SourceLocation AtLoc,
1624 SourceLocation ProtoLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation RParenLoc) {
1627 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1628 Protocol->getIdentifier(),
1629 AtLoc,
1630 ProtoLoc,
1631 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001632 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 }
Mike Stump11289f42009-09-09 15:08:12 +00001634
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// \brief Build a new shuffle vector expression.
1636 ///
1637 /// By default, performs semantic analysis to build the new expression.
1638 /// Subclasses may override this routine to provide different behavior.
1639 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1640 MultiExprArg SubExprs,
1641 SourceLocation RParenLoc) {
1642 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001643 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1645 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1646 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1647 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001648
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 // Build a reference to the __builtin_shufflevector builtin
1650 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001651 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001653 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001655
1656 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 unsigned NumSubExprs = SubExprs.size();
1658 Expr **Subs = (Expr **)SubExprs.release();
1659 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1660 Subs, NumSubExprs,
1661 Builtin->getResultType(),
1662 RParenLoc);
1663 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001664
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 // Type-check the __builtin_shufflevector expression.
1666 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1667 if (Result.isInvalid())
1668 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001669
Douglas Gregora16548e2009-08-11 05:31:07 +00001670 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001671 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001672 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001673};
Douglas Gregora16548e2009-08-11 05:31:07 +00001674
Douglas Gregorebe10102009-08-20 07:17:43 +00001675template<typename Derived>
1676Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1677 if (!S)
1678 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregorebe10102009-08-20 07:17:43 +00001680 switch (S->getStmtClass()) {
1681 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregorebe10102009-08-20 07:17:43 +00001683 // Transform individual statement nodes
1684#define STMT(Node, Parent) \
1685 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1686#define EXPR(Node, Parent)
1687#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001688
Douglas Gregorebe10102009-08-20 07:17:43 +00001689 // Transform expressions by calling TransformExpr.
1690#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001691#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001692#define EXPR(Node, Parent) case Stmt::Node##Class:
1693#include "clang/AST/StmtNodes.def"
1694 {
1695 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1696 if (E.isInvalid())
1697 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001698
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001699 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001700 }
Mike Stump11289f42009-09-09 15:08:12 +00001701 }
1702
Douglas Gregorebe10102009-08-20 07:17:43 +00001703 return SemaRef.Owned(S->Retain());
1704}
Mike Stump11289f42009-09-09 15:08:12 +00001705
1706
Douglas Gregore922c772009-08-04 22:27:00 +00001707template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001708Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001709 if (!E)
1710 return SemaRef.Owned(E);
1711
1712 switch (E->getStmtClass()) {
1713 case Stmt::NoStmtClass: break;
1714#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001715#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001716#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001717 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001718#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001719 }
1720
Douglas Gregora16548e2009-08-11 05:31:07 +00001721 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001722}
1723
1724template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001725NestedNameSpecifier *
1726TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001727 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001728 QualType ObjectType,
1729 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001730 if (!NNS)
1731 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregorebe10102009-08-20 07:17:43 +00001733 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001734 NestedNameSpecifier *Prefix = NNS->getPrefix();
1735 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001736 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001737 ObjectType,
1738 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 if (!Prefix)
1740 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001741
1742 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001743 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001744 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001745 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001746 }
Mike Stump11289f42009-09-09 15:08:12 +00001747
Douglas Gregor1135c352009-08-06 05:28:30 +00001748 switch (NNS->getKind()) {
1749 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001750 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001751 "Identifier nested-name-specifier with no prefix or object type");
1752 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1753 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001755
1756 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001757 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001758 ObjectType,
1759 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001760
Douglas Gregor1135c352009-08-06 05:28:30 +00001761 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001762 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001763 = cast_or_null<NamespaceDecl>(
1764 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001765 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 Prefix == NNS->getPrefix() &&
1767 NS == NNS->getAsNamespace())
1768 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregor1135c352009-08-06 05:28:30 +00001770 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1771 }
Mike Stump11289f42009-09-09 15:08:12 +00001772
Douglas Gregor1135c352009-08-06 05:28:30 +00001773 case NestedNameSpecifier::Global:
1774 // There is no meaningful transformation that one could perform on the
1775 // global scope.
1776 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregor1135c352009-08-06 05:28:30 +00001778 case NestedNameSpecifier::TypeSpecWithTemplate:
1779 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001780 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001781 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1782 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001783 if (T.isNull())
1784 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001785
Douglas Gregor1135c352009-08-06 05:28:30 +00001786 if (!getDerived().AlwaysRebuild() &&
1787 Prefix == NNS->getPrefix() &&
1788 T == QualType(NNS->getAsType(), 0))
1789 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001790
1791 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1792 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001793 T);
1794 }
1795 }
Mike Stump11289f42009-09-09 15:08:12 +00001796
Douglas Gregor1135c352009-08-06 05:28:30 +00001797 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001798 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001799}
1800
1801template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001802DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001803TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001804 SourceLocation Loc,
1805 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001806 if (!Name)
1807 return Name;
1808
1809 switch (Name.getNameKind()) {
1810 case DeclarationName::Identifier:
1811 case DeclarationName::ObjCZeroArgSelector:
1812 case DeclarationName::ObjCOneArgSelector:
1813 case DeclarationName::ObjCMultiArgSelector:
1814 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001815 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001816 case DeclarationName::CXXUsingDirective:
1817 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregorf816bd72009-09-03 22:13:48 +00001819 case DeclarationName::CXXConstructorName:
1820 case DeclarationName::CXXDestructorName:
1821 case DeclarationName::CXXConversionFunctionName: {
1822 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001823 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1824 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001825 if (T.isNull())
1826 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001827
Douglas Gregorf816bd72009-09-03 22:13:48 +00001828 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001829 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001830 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001831 }
Mike Stump11289f42009-09-09 15:08:12 +00001832 }
1833
Douglas Gregorf816bd72009-09-03 22:13:48 +00001834 return DeclarationName();
1835}
1836
1837template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001838TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001839TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1840 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001841 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001842 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001843 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001844 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1845 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001846 if (!NNS)
1847 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001850 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1852 if (!TransTemplate)
1853 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregor71dc5092009-08-06 06:41:21 +00001855 if (!getDerived().AlwaysRebuild() &&
1856 NNS == QTN->getQualifier() &&
1857 TransTemplate == Template)
1858 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1861 TransTemplate);
1862 }
Mike Stump11289f42009-09-09 15:08:12 +00001863
John McCalle66edc12009-11-24 19:00:30 +00001864 // These should be getting filtered out before they make it into the AST.
1865 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 }
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001869 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001870 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001871 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1872 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001873 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor71dc5092009-08-06 06:41:21 +00001876 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001877 NNS == DTN->getQualifier() &&
1878 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001879 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001880
Douglas Gregor71395fa2009-11-04 00:56:37 +00001881 if (DTN->isIdentifier())
1882 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1883 ObjectType);
1884
1885 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1886 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001887 }
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregor71dc5092009-08-06 06:41:21 +00001889 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001890 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001891 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1892 if (!TransTemplate)
1893 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001894
Douglas Gregor71dc5092009-08-06 06:41:21 +00001895 if (!getDerived().AlwaysRebuild() &&
1896 TransTemplate == Template)
1897 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregor71dc5092009-08-06 06:41:21 +00001899 return TemplateName(TransTemplate);
1900 }
Mike Stump11289f42009-09-09 15:08:12 +00001901
John McCalle66edc12009-11-24 19:00:30 +00001902 // These should be getting filtered out before they reach the AST.
1903 assert(false && "overloaded function decl survived to here");
1904 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001905}
1906
1907template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001908void TreeTransform<Derived>::InventTemplateArgumentLoc(
1909 const TemplateArgument &Arg,
1910 TemplateArgumentLoc &Output) {
1911 SourceLocation Loc = getDerived().getBaseLocation();
1912 switch (Arg.getKind()) {
1913 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001914 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001915 break;
1916
1917 case TemplateArgument::Type:
1918 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001919 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001920
1921 break;
1922
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001923 case TemplateArgument::Template:
1924 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1925 break;
1926
John McCall0ad16662009-10-29 08:12:44 +00001927 case TemplateArgument::Expression:
1928 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1929 break;
1930
1931 case TemplateArgument::Declaration:
1932 case TemplateArgument::Integral:
1933 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001934 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001935 break;
1936 }
1937}
1938
1939template<typename Derived>
1940bool TreeTransform<Derived>::TransformTemplateArgument(
1941 const TemplateArgumentLoc &Input,
1942 TemplateArgumentLoc &Output) {
1943 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001944 switch (Arg.getKind()) {
1945 case TemplateArgument::Null:
1946 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001947 Output = Input;
1948 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregore922c772009-08-04 22:27:00 +00001950 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001951 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001952 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001953 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001954
1955 DI = getDerived().TransformType(DI);
1956 if (!DI) return true;
1957
1958 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1959 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001960 }
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregore922c772009-08-04 22:27:00 +00001962 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001963 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001964 DeclarationName Name;
1965 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1966 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001967 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001968 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001969 if (!D) return true;
1970
John McCall0d07eb32009-10-29 18:45:58 +00001971 Expr *SourceExpr = Input.getSourceDeclExpression();
1972 if (SourceExpr) {
1973 EnterExpressionEvaluationContext Unevaluated(getSema(),
1974 Action::Unevaluated);
1975 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1976 if (E.isInvalid())
1977 SourceExpr = NULL;
1978 else {
1979 SourceExpr = E.takeAs<Expr>();
1980 SourceExpr->Retain();
1981 }
1982 }
1983
1984 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001985 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001988 case TemplateArgument::Template: {
1989 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1990 TemplateName Template
1991 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1992 if (Template.isNull())
1993 return true;
1994
1995 Output = TemplateArgumentLoc(TemplateArgument(Template),
1996 Input.getTemplateQualifierRange(),
1997 Input.getTemplateNameLoc());
1998 return false;
1999 }
2000
Douglas Gregore922c772009-08-04 22:27:00 +00002001 case TemplateArgument::Expression: {
2002 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002003 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002004 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002005
John McCall0ad16662009-10-29 08:12:44 +00002006 Expr *InputExpr = Input.getSourceExpression();
2007 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2008
2009 Sema::OwningExprResult E
2010 = getDerived().TransformExpr(InputExpr);
2011 if (E.isInvalid()) return true;
2012
2013 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002014 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002015 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2016 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002017 }
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregore922c772009-08-04 22:27:00 +00002019 case TemplateArgument::Pack: {
2020 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2021 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002022 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002023 AEnd = Arg.pack_end();
2024 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002025
John McCall0ad16662009-10-29 08:12:44 +00002026 // FIXME: preserve source information here when we start
2027 // caring about parameter packs.
2028
John McCall0d07eb32009-10-29 18:45:58 +00002029 TemplateArgumentLoc InputArg;
2030 TemplateArgumentLoc OutputArg;
2031 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2032 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002033 return true;
2034
John McCall0d07eb32009-10-29 18:45:58 +00002035 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002036 }
2037 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002038 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002039 true);
John McCall0d07eb32009-10-29 18:45:58 +00002040 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002041 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002042 }
2043 }
Mike Stump11289f42009-09-09 15:08:12 +00002044
Douglas Gregore922c772009-08-04 22:27:00 +00002045 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002046 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002047}
2048
Douglas Gregord6ff3322009-08-04 16:50:30 +00002049//===----------------------------------------------------------------------===//
2050// Type transformation
2051//===----------------------------------------------------------------------===//
2052
2053template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002054QualType TreeTransform<Derived>::TransformType(QualType T,
2055 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002056 if (getDerived().AlreadyTransformed(T))
2057 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002058
John McCall550e0c22009-10-21 00:40:46 +00002059 // Temporary workaround. All of these transformations should
2060 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002061 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002062 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002063
Douglas Gregorfe17d252010-02-16 19:09:40 +00002064 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002065
John McCall550e0c22009-10-21 00:40:46 +00002066 if (!NewDI)
2067 return QualType();
2068
2069 return NewDI->getType();
2070}
2071
2072template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002073TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2074 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002075 if (getDerived().AlreadyTransformed(DI->getType()))
2076 return DI;
2077
2078 TypeLocBuilder TLB;
2079
2080 TypeLoc TL = DI->getTypeLoc();
2081 TLB.reserve(TL.getFullDataSize());
2082
Douglas Gregorfe17d252010-02-16 19:09:40 +00002083 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002084 if (Result.isNull())
2085 return 0;
2086
John McCallbcd03502009-12-07 02:54:59 +00002087 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002088}
2089
2090template<typename Derived>
2091QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002092TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2093 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002094 switch (T.getTypeLocClass()) {
2095#define ABSTRACT_TYPELOC(CLASS, PARENT)
2096#define TYPELOC(CLASS, PARENT) \
2097 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002098 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2099 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002100#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002101 }
Mike Stump11289f42009-09-09 15:08:12 +00002102
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002103 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002104 return QualType();
2105}
2106
2107/// FIXME: By default, this routine adds type qualifiers only to types
2108/// that can have qualifiers, and silently suppresses those qualifiers
2109/// that are not permitted (e.g., qualifiers on reference or function
2110/// types). This is the right thing for template instantiation, but
2111/// probably not for other clients.
2112template<typename Derived>
2113QualType
2114TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002115 QualifiedTypeLoc T,
2116 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002117 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002118
Douglas Gregorfe17d252010-02-16 19:09:40 +00002119 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2120 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002121 if (Result.isNull())
2122 return QualType();
2123
2124 // Silently suppress qualifiers if the result type can't be qualified.
2125 // FIXME: this is the right thing for template instantiation, but
2126 // probably not for other clients.
2127 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002128 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002129
John McCall550e0c22009-10-21 00:40:46 +00002130 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2131
2132 TLB.push<QualifiedTypeLoc>(Result);
2133
2134 // No location information to preserve.
2135
2136 return Result;
2137}
2138
2139template <class TyLoc> static inline
2140QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2141 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2142 NewT.setNameLoc(T.getNameLoc());
2143 return T.getType();
2144}
2145
2146// Ugly metaprogramming macros because I couldn't be bothered to make
2147// the equivalent template version work.
2148#define TransformPointerLikeType(TypeClass) do { \
2149 QualType PointeeType \
2150 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2151 if (PointeeType.isNull()) \
2152 return QualType(); \
2153 \
2154 QualType Result = TL.getType(); \
2155 if (getDerived().AlwaysRebuild() || \
2156 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002157 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2158 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002159 if (Result.isNull()) \
2160 return QualType(); \
2161 } \
2162 \
2163 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2164 NewT.setSigilLoc(TL.getSigilLoc()); \
2165 \
2166 return Result; \
2167} while(0)
2168
John McCall550e0c22009-10-21 00:40:46 +00002169template<typename Derived>
2170QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002171 BuiltinTypeLoc T,
2172 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002173 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2174 NewT.setBuiltinLoc(T.getBuiltinLoc());
2175 if (T.needsExtraLocalData())
2176 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2177 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002178}
Mike Stump11289f42009-09-09 15:08:12 +00002179
Douglas Gregord6ff3322009-08-04 16:50:30 +00002180template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002181QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002182 ComplexTypeLoc T,
2183 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002184 // FIXME: recurse?
2185 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002186}
Mike Stump11289f42009-09-09 15:08:12 +00002187
Douglas Gregord6ff3322009-08-04 16:50:30 +00002188template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002189QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002190 PointerTypeLoc TL,
2191 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002192 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002193}
Mike Stump11289f42009-09-09 15:08:12 +00002194
2195template<typename Derived>
2196QualType
John McCall550e0c22009-10-21 00:40:46 +00002197TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002198 BlockPointerTypeLoc TL,
2199 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002200 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002201}
2202
John McCall70dd5f62009-10-30 00:06:24 +00002203/// Transforms a reference type. Note that somewhat paradoxically we
2204/// don't care whether the type itself is an l-value type or an r-value
2205/// type; we only care if the type was *written* as an l-value type
2206/// or an r-value type.
2207template<typename Derived>
2208QualType
2209TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002210 ReferenceTypeLoc TL,
2211 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002212 const ReferenceType *T = TL.getTypePtr();
2213
2214 // Note that this works with the pointee-as-written.
2215 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2216 if (PointeeType.isNull())
2217 return QualType();
2218
2219 QualType Result = TL.getType();
2220 if (getDerived().AlwaysRebuild() ||
2221 PointeeType != T->getPointeeTypeAsWritten()) {
2222 Result = getDerived().RebuildReferenceType(PointeeType,
2223 T->isSpelledAsLValue(),
2224 TL.getSigilLoc());
2225 if (Result.isNull())
2226 return QualType();
2227 }
2228
2229 // r-value references can be rebuilt as l-value references.
2230 ReferenceTypeLoc NewTL;
2231 if (isa<LValueReferenceType>(Result))
2232 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2233 else
2234 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2235 NewTL.setSigilLoc(TL.getSigilLoc());
2236
2237 return Result;
2238}
2239
Mike Stump11289f42009-09-09 15:08:12 +00002240template<typename Derived>
2241QualType
John McCall550e0c22009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002243 LValueReferenceTypeLoc TL,
2244 QualType ObjectType) {
2245 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002246}
2247
Mike Stump11289f42009-09-09 15:08:12 +00002248template<typename Derived>
2249QualType
John McCall550e0c22009-10-21 00:40:46 +00002250TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002251 RValueReferenceTypeLoc TL,
2252 QualType ObjectType) {
2253 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254}
Mike Stump11289f42009-09-09 15:08:12 +00002255
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002257QualType
John McCall550e0c22009-10-21 00:40:46 +00002258TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002259 MemberPointerTypeLoc TL,
2260 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002261 MemberPointerType *T = TL.getTypePtr();
2262
2263 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002264 if (PointeeType.isNull())
2265 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002266
John McCall550e0c22009-10-21 00:40:46 +00002267 // TODO: preserve source information for this.
2268 QualType ClassType
2269 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002270 if (ClassType.isNull())
2271 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002272
John McCall550e0c22009-10-21 00:40:46 +00002273 QualType Result = TL.getType();
2274 if (getDerived().AlwaysRebuild() ||
2275 PointeeType != T->getPointeeType() ||
2276 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002277 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2278 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002279 if (Result.isNull())
2280 return QualType();
2281 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002282
John McCall550e0c22009-10-21 00:40:46 +00002283 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2284 NewTL.setSigilLoc(TL.getSigilLoc());
2285
2286 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002287}
2288
Mike Stump11289f42009-09-09 15:08:12 +00002289template<typename Derived>
2290QualType
John McCall550e0c22009-10-21 00:40:46 +00002291TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002292 ConstantArrayTypeLoc TL,
2293 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002294 ConstantArrayType *T = TL.getTypePtr();
2295 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002296 if (ElementType.isNull())
2297 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCall550e0c22009-10-21 00:40:46 +00002299 QualType Result = TL.getType();
2300 if (getDerived().AlwaysRebuild() ||
2301 ElementType != T->getElementType()) {
2302 Result = getDerived().RebuildConstantArrayType(ElementType,
2303 T->getSizeModifier(),
2304 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002305 T->getIndexTypeCVRQualifiers(),
2306 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002307 if (Result.isNull())
2308 return QualType();
2309 }
2310
2311 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2312 NewTL.setLBracketLoc(TL.getLBracketLoc());
2313 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002314
John McCall550e0c22009-10-21 00:40:46 +00002315 Expr *Size = TL.getSizeExpr();
2316 if (Size) {
2317 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2318 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2319 }
2320 NewTL.setSizeExpr(Size);
2321
2322 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002323}
Mike Stump11289f42009-09-09 15:08:12 +00002324
Douglas Gregord6ff3322009-08-04 16:50:30 +00002325template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002326QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002327 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002328 IncompleteArrayTypeLoc TL,
2329 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002330 IncompleteArrayType *T = TL.getTypePtr();
2331 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002332 if (ElementType.isNull())
2333 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002334
John McCall550e0c22009-10-21 00:40:46 +00002335 QualType Result = TL.getType();
2336 if (getDerived().AlwaysRebuild() ||
2337 ElementType != T->getElementType()) {
2338 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002339 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002340 T->getIndexTypeCVRQualifiers(),
2341 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002342 if (Result.isNull())
2343 return QualType();
2344 }
2345
2346 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2347 NewTL.setLBracketLoc(TL.getLBracketLoc());
2348 NewTL.setRBracketLoc(TL.getRBracketLoc());
2349 NewTL.setSizeExpr(0);
2350
2351 return Result;
2352}
2353
2354template<typename Derived>
2355QualType
2356TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002357 VariableArrayTypeLoc TL,
2358 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002359 VariableArrayType *T = TL.getTypePtr();
2360 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2361 if (ElementType.isNull())
2362 return QualType();
2363
2364 // Array bounds are not potentially evaluated contexts
2365 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2366
2367 Sema::OwningExprResult SizeResult
2368 = getDerived().TransformExpr(T->getSizeExpr());
2369 if (SizeResult.isInvalid())
2370 return QualType();
2371
2372 Expr *Size = static_cast<Expr*>(SizeResult.get());
2373
2374 QualType Result = TL.getType();
2375 if (getDerived().AlwaysRebuild() ||
2376 ElementType != T->getElementType() ||
2377 Size != T->getSizeExpr()) {
2378 Result = getDerived().RebuildVariableArrayType(ElementType,
2379 T->getSizeModifier(),
2380 move(SizeResult),
2381 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002382 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002383 if (Result.isNull())
2384 return QualType();
2385 }
2386 else SizeResult.take();
2387
2388 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2389 NewTL.setLBracketLoc(TL.getLBracketLoc());
2390 NewTL.setRBracketLoc(TL.getRBracketLoc());
2391 NewTL.setSizeExpr(Size);
2392
2393 return Result;
2394}
2395
2396template<typename Derived>
2397QualType
2398TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002399 DependentSizedArrayTypeLoc TL,
2400 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002401 DependentSizedArrayType *T = TL.getTypePtr();
2402 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2403 if (ElementType.isNull())
2404 return QualType();
2405
2406 // Array bounds are not potentially evaluated contexts
2407 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2408
2409 Sema::OwningExprResult SizeResult
2410 = getDerived().TransformExpr(T->getSizeExpr());
2411 if (SizeResult.isInvalid())
2412 return QualType();
2413
2414 Expr *Size = static_cast<Expr*>(SizeResult.get());
2415
2416 QualType Result = TL.getType();
2417 if (getDerived().AlwaysRebuild() ||
2418 ElementType != T->getElementType() ||
2419 Size != T->getSizeExpr()) {
2420 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2421 T->getSizeModifier(),
2422 move(SizeResult),
2423 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002424 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002425 if (Result.isNull())
2426 return QualType();
2427 }
2428 else SizeResult.take();
2429
2430 // We might have any sort of array type now, but fortunately they
2431 // all have the same location layout.
2432 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2433 NewTL.setLBracketLoc(TL.getLBracketLoc());
2434 NewTL.setRBracketLoc(TL.getRBracketLoc());
2435 NewTL.setSizeExpr(Size);
2436
2437 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438}
Mike Stump11289f42009-09-09 15:08:12 +00002439
2440template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002441QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002442 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002443 DependentSizedExtVectorTypeLoc TL,
2444 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002445 DependentSizedExtVectorType *T = TL.getTypePtr();
2446
2447 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448 QualType ElementType = getDerived().TransformType(T->getElementType());
2449 if (ElementType.isNull())
2450 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002451
Douglas Gregore922c772009-08-04 22:27:00 +00002452 // Vector sizes are not potentially evaluated contexts
2453 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2454
Douglas Gregord6ff3322009-08-04 16:50:30 +00002455 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2456 if (Size.isInvalid())
2457 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002458
John McCall550e0c22009-10-21 00:40:46 +00002459 QualType Result = TL.getType();
2460 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002461 ElementType != T->getElementType() ||
2462 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002463 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464 move(Size),
2465 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002466 if (Result.isNull())
2467 return QualType();
2468 }
2469 else Size.take();
2470
2471 // Result might be dependent or not.
2472 if (isa<DependentSizedExtVectorType>(Result)) {
2473 DependentSizedExtVectorTypeLoc NewTL
2474 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2475 NewTL.setNameLoc(TL.getNameLoc());
2476 } else {
2477 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2478 NewTL.setNameLoc(TL.getNameLoc());
2479 }
2480
2481 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482}
Mike Stump11289f42009-09-09 15:08:12 +00002483
2484template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002485QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002486 VectorTypeLoc TL,
2487 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002488 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002489 QualType ElementType = getDerived().TransformType(T->getElementType());
2490 if (ElementType.isNull())
2491 return QualType();
2492
John McCall550e0c22009-10-21 00:40:46 +00002493 QualType Result = TL.getType();
2494 if (getDerived().AlwaysRebuild() ||
2495 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002496 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2497 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002498 if (Result.isNull())
2499 return QualType();
2500 }
2501
2502 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2503 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002504
John McCall550e0c22009-10-21 00:40:46 +00002505 return Result;
2506}
2507
2508template<typename Derived>
2509QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002510 ExtVectorTypeLoc TL,
2511 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002512 VectorType *T = TL.getTypePtr();
2513 QualType ElementType = getDerived().TransformType(T->getElementType());
2514 if (ElementType.isNull())
2515 return QualType();
2516
2517 QualType Result = TL.getType();
2518 if (getDerived().AlwaysRebuild() ||
2519 ElementType != T->getElementType()) {
2520 Result = getDerived().RebuildExtVectorType(ElementType,
2521 T->getNumElements(),
2522 /*FIXME*/ SourceLocation());
2523 if (Result.isNull())
2524 return QualType();
2525 }
2526
2527 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2528 NewTL.setNameLoc(TL.getNameLoc());
2529
2530 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002531}
Mike Stump11289f42009-09-09 15:08:12 +00002532
2533template<typename Derived>
2534QualType
John McCall550e0c22009-10-21 00:40:46 +00002535TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002536 FunctionProtoTypeLoc TL,
2537 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002538 FunctionProtoType *T = TL.getTypePtr();
2539 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540 if (ResultType.isNull())
2541 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002542
John McCall550e0c22009-10-21 00:40:46 +00002543 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002544 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002545 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2546 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2547 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002548
John McCall550e0c22009-10-21 00:40:46 +00002549 QualType NewType;
2550 ParmVarDecl *NewParm;
2551
2552 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002553 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002554 assert(OldDI->getType() == T->getArgType(i));
2555
John McCallbcd03502009-12-07 02:54:59 +00002556 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002557 if (!NewDI)
2558 return QualType();
2559
2560 if (NewDI == OldDI)
2561 NewParm = OldParm;
2562 else
2563 NewParm = ParmVarDecl::Create(SemaRef.Context,
2564 OldParm->getDeclContext(),
2565 OldParm->getLocation(),
2566 OldParm->getIdentifier(),
2567 NewDI->getType(),
2568 NewDI,
2569 OldParm->getStorageClass(),
2570 /* DefArg */ NULL);
2571 NewType = NewParm->getType();
2572
2573 // Deal with the possibility that we don't have a parameter
2574 // declaration for this parameter.
2575 } else {
2576 NewParm = 0;
2577
2578 QualType OldType = T->getArgType(i);
2579 NewType = getDerived().TransformType(OldType);
2580 if (NewType.isNull())
2581 return QualType();
2582 }
2583
2584 ParamTypes.push_back(NewType);
2585 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002586 }
Mike Stump11289f42009-09-09 15:08:12 +00002587
John McCall550e0c22009-10-21 00:40:46 +00002588 QualType Result = TL.getType();
2589 if (getDerived().AlwaysRebuild() ||
2590 ResultType != T->getResultType() ||
2591 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2592 Result = getDerived().RebuildFunctionProtoType(ResultType,
2593 ParamTypes.data(),
2594 ParamTypes.size(),
2595 T->isVariadic(),
2596 T->getTypeQuals());
2597 if (Result.isNull())
2598 return QualType();
2599 }
Mike Stump11289f42009-09-09 15:08:12 +00002600
John McCall550e0c22009-10-21 00:40:46 +00002601 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2602 NewTL.setLParenLoc(TL.getLParenLoc());
2603 NewTL.setRParenLoc(TL.getRParenLoc());
2604 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2605 NewTL.setArg(i, ParamDecls[i]);
2606
2607 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002608}
Mike Stump11289f42009-09-09 15:08:12 +00002609
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610template<typename Derived>
2611QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002612 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002613 FunctionNoProtoTypeLoc TL,
2614 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002615 FunctionNoProtoType *T = TL.getTypePtr();
2616 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2617 if (ResultType.isNull())
2618 return QualType();
2619
2620 QualType Result = TL.getType();
2621 if (getDerived().AlwaysRebuild() ||
2622 ResultType != T->getResultType())
2623 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2624
2625 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2626 NewTL.setLParenLoc(TL.getLParenLoc());
2627 NewTL.setRParenLoc(TL.getRParenLoc());
2628
2629 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002630}
Mike Stump11289f42009-09-09 15:08:12 +00002631
John McCallb96ec562009-12-04 22:46:56 +00002632template<typename Derived> QualType
2633TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002634 UnresolvedUsingTypeLoc TL,
2635 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002636 UnresolvedUsingType *T = TL.getTypePtr();
2637 Decl *D = getDerived().TransformDecl(T->getDecl());
2638 if (!D)
2639 return QualType();
2640
2641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2643 Result = getDerived().RebuildUnresolvedUsingType(D);
2644 if (Result.isNull())
2645 return QualType();
2646 }
2647
2648 // We might get an arbitrary type spec type back. We should at
2649 // least always get a type spec type, though.
2650 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2651 NewTL.setNameLoc(TL.getNameLoc());
2652
2653 return Result;
2654}
2655
Douglas Gregord6ff3322009-08-04 16:50:30 +00002656template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002657QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002658 TypedefTypeLoc TL,
2659 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002660 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002661 TypedefDecl *Typedef
2662 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2663 if (!Typedef)
2664 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002665
John McCall550e0c22009-10-21 00:40:46 +00002666 QualType Result = TL.getType();
2667 if (getDerived().AlwaysRebuild() ||
2668 Typedef != T->getDecl()) {
2669 Result = getDerived().RebuildTypedefType(Typedef);
2670 if (Result.isNull())
2671 return QualType();
2672 }
Mike Stump11289f42009-09-09 15:08:12 +00002673
John McCall550e0c22009-10-21 00:40:46 +00002674 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2675 NewTL.setNameLoc(TL.getNameLoc());
2676
2677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678}
Mike Stump11289f42009-09-09 15:08:12 +00002679
Douglas Gregord6ff3322009-08-04 16:50:30 +00002680template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002681QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002682 TypeOfExprTypeLoc TL,
2683 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002684 // typeof expressions are not potentially evaluated contexts
2685 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002686
John McCalle8595032010-01-13 20:03:27 +00002687 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 if (E.isInvalid())
2689 return QualType();
2690
John McCall550e0c22009-10-21 00:40:46 +00002691 QualType Result = TL.getType();
2692 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002693 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002694 Result = getDerived().RebuildTypeOfExprType(move(E));
2695 if (Result.isNull())
2696 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002697 }
John McCall550e0c22009-10-21 00:40:46 +00002698 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002699
John McCall550e0c22009-10-21 00:40:46 +00002700 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002701 NewTL.setTypeofLoc(TL.getTypeofLoc());
2702 NewTL.setLParenLoc(TL.getLParenLoc());
2703 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002704
2705 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706}
Mike Stump11289f42009-09-09 15:08:12 +00002707
2708template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002709QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002710 TypeOfTypeLoc TL,
2711 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002712 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2713 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2714 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002715 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002716
John McCall550e0c22009-10-21 00:40:46 +00002717 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002718 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2719 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002720 if (Result.isNull())
2721 return QualType();
2722 }
Mike Stump11289f42009-09-09 15:08:12 +00002723
John McCall550e0c22009-10-21 00:40:46 +00002724 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002725 NewTL.setTypeofLoc(TL.getTypeofLoc());
2726 NewTL.setLParenLoc(TL.getLParenLoc());
2727 NewTL.setRParenLoc(TL.getRParenLoc());
2728 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002729
2730 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002731}
Mike Stump11289f42009-09-09 15:08:12 +00002732
2733template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002734QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002735 DecltypeTypeLoc TL,
2736 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002737 DecltypeType *T = TL.getTypePtr();
2738
Douglas Gregore922c772009-08-04 22:27:00 +00002739 // decltype expressions are not potentially evaluated contexts
2740 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002741
Douglas Gregord6ff3322009-08-04 16:50:30 +00002742 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2743 if (E.isInvalid())
2744 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002745
John McCall550e0c22009-10-21 00:40:46 +00002746 QualType Result = TL.getType();
2747 if (getDerived().AlwaysRebuild() ||
2748 E.get() != T->getUnderlyingExpr()) {
2749 Result = getDerived().RebuildDecltypeType(move(E));
2750 if (Result.isNull())
2751 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002752 }
John McCall550e0c22009-10-21 00:40:46 +00002753 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002754
John McCall550e0c22009-10-21 00:40:46 +00002755 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2756 NewTL.setNameLoc(TL.getNameLoc());
2757
2758 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759}
2760
2761template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002762QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002763 RecordTypeLoc TL,
2764 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002765 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002767 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768 if (!Record)
2769 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 QualType Result = TL.getType();
2772 if (getDerived().AlwaysRebuild() ||
2773 Record != T->getDecl()) {
2774 Result = getDerived().RebuildRecordType(Record);
2775 if (Result.isNull())
2776 return QualType();
2777 }
Mike Stump11289f42009-09-09 15:08:12 +00002778
John McCall550e0c22009-10-21 00:40:46 +00002779 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2780 NewTL.setNameLoc(TL.getNameLoc());
2781
2782 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002783}
Mike Stump11289f42009-09-09 15:08:12 +00002784
2785template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002786QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002787 EnumTypeLoc TL,
2788 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002789 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002790 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002791 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002792 if (!Enum)
2793 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002794
John McCall550e0c22009-10-21 00:40:46 +00002795 QualType Result = TL.getType();
2796 if (getDerived().AlwaysRebuild() ||
2797 Enum != T->getDecl()) {
2798 Result = getDerived().RebuildEnumType(Enum);
2799 if (Result.isNull())
2800 return QualType();
2801 }
Mike Stump11289f42009-09-09 15:08:12 +00002802
John McCall550e0c22009-10-21 00:40:46 +00002803 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2804 NewTL.setNameLoc(TL.getNameLoc());
2805
2806 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002807}
John McCallfcc33b02009-09-05 00:15:47 +00002808
2809template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002810QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002811 ElaboratedTypeLoc TL,
2812 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002813 ElaboratedType *T = TL.getTypePtr();
2814
2815 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002816 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2817 if (Underlying.isNull())
2818 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002819
John McCall550e0c22009-10-21 00:40:46 +00002820 QualType Result = TL.getType();
2821 if (getDerived().AlwaysRebuild() ||
2822 Underlying != T->getUnderlyingType()) {
2823 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2824 if (Result.isNull())
2825 return QualType();
2826 }
Mike Stump11289f42009-09-09 15:08:12 +00002827
John McCall550e0c22009-10-21 00:40:46 +00002828 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2829 NewTL.setNameLoc(TL.getNameLoc());
2830
2831 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002832}
Mike Stump11289f42009-09-09 15:08:12 +00002833
2834
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835template<typename Derived>
2836QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002837 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002838 TemplateTypeParmTypeLoc TL,
2839 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002840 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002841}
2842
Mike Stump11289f42009-09-09 15:08:12 +00002843template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002844QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002845 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002846 SubstTemplateTypeParmTypeLoc TL,
2847 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002848 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002849}
2850
2851template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002852QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2853 const TemplateSpecializationType *TST,
2854 QualType ObjectType) {
2855 // FIXME: this entire method is a temporary workaround; callers
2856 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002857
John McCall0ad16662009-10-29 08:12:44 +00002858 // Fake up a TemplateSpecializationTypeLoc.
2859 TypeLocBuilder TLB;
2860 TemplateSpecializationTypeLoc TL
2861 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2862
John McCall0d07eb32009-10-29 18:45:58 +00002863 SourceLocation BaseLoc = getDerived().getBaseLocation();
2864
2865 TL.setTemplateNameLoc(BaseLoc);
2866 TL.setLAngleLoc(BaseLoc);
2867 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002868 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2869 const TemplateArgument &TA = TST->getArg(i);
2870 TemplateArgumentLoc TAL;
2871 getDerived().InventTemplateArgumentLoc(TA, TAL);
2872 TL.setArgLocInfo(i, TAL.getLocInfo());
2873 }
2874
2875 TypeLocBuilder IgnoredTLB;
2876 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002877}
2878
2879template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002880QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002881 TypeLocBuilder &TLB,
2882 TemplateSpecializationTypeLoc TL,
2883 QualType ObjectType) {
2884 const TemplateSpecializationType *T = TL.getTypePtr();
2885
Mike Stump11289f42009-09-09 15:08:12 +00002886 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002887 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002888 if (Template.isNull())
2889 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002890
John McCall6b51f282009-11-23 01:53:49 +00002891 TemplateArgumentListInfo NewTemplateArgs;
2892 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2893 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2894
2895 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2896 TemplateArgumentLoc Loc;
2897 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002898 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002899 NewTemplateArgs.addArgument(Loc);
2900 }
Mike Stump11289f42009-09-09 15:08:12 +00002901
John McCall0ad16662009-10-29 08:12:44 +00002902 // FIXME: maybe don't rebuild if all the template arguments are the same.
2903
2904 QualType Result =
2905 getDerived().RebuildTemplateSpecializationType(Template,
2906 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002907 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002908
2909 if (!Result.isNull()) {
2910 TemplateSpecializationTypeLoc NewTL
2911 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2912 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2913 NewTL.setLAngleLoc(TL.getLAngleLoc());
2914 NewTL.setRAngleLoc(TL.getRAngleLoc());
2915 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2916 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002917 }
Mike Stump11289f42009-09-09 15:08:12 +00002918
John McCall0ad16662009-10-29 08:12:44 +00002919 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920}
Mike Stump11289f42009-09-09 15:08:12 +00002921
2922template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002923QualType
2924TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002925 QualifiedNameTypeLoc TL,
2926 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002927 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928 NestedNameSpecifier *NNS
2929 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002930 SourceRange(),
2931 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002932 if (!NNS)
2933 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002934
Douglas Gregord6ff3322009-08-04 16:50:30 +00002935 QualType Named = getDerived().TransformType(T->getNamedType());
2936 if (Named.isNull())
2937 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002938
John McCall550e0c22009-10-21 00:40:46 +00002939 QualType Result = TL.getType();
2940 if (getDerived().AlwaysRebuild() ||
2941 NNS != T->getQualifier() ||
2942 Named != T->getNamedType()) {
2943 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2944 if (Result.isNull())
2945 return QualType();
2946 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002947
John McCall550e0c22009-10-21 00:40:46 +00002948 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2949 NewTL.setNameLoc(TL.getNameLoc());
2950
2951 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952}
Mike Stump11289f42009-09-09 15:08:12 +00002953
2954template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002955QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002956 TypenameTypeLoc TL,
2957 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002958 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002959
2960 /* FIXME: preserve source information better than this */
2961 SourceRange SR(TL.getNameLoc());
2962
Douglas Gregord6ff3322009-08-04 16:50:30 +00002963 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00002964 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
2965 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002966 if (!NNS)
2967 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002968
John McCall550e0c22009-10-21 00:40:46 +00002969 QualType Result;
2970
Douglas Gregord6ff3322009-08-04 16:50:30 +00002971 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002972 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973 = getDerived().TransformType(QualType(TemplateId, 0));
2974 if (NewTemplateId.isNull())
2975 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002976
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977 if (!getDerived().AlwaysRebuild() &&
2978 NNS == T->getQualifier() &&
2979 NewTemplateId == QualType(TemplateId, 0))
2980 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002981
John McCall550e0c22009-10-21 00:40:46 +00002982 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2983 } else {
John McCall0ad16662009-10-29 08:12:44 +00002984 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002985 }
John McCall550e0c22009-10-21 00:40:46 +00002986 if (Result.isNull())
2987 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002988
John McCall550e0c22009-10-21 00:40:46 +00002989 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2990 NewTL.setNameLoc(TL.getNameLoc());
2991
2992 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002993}
Mike Stump11289f42009-09-09 15:08:12 +00002994
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002996QualType
2997TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002998 ObjCInterfaceTypeLoc TL,
2999 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003000 assert(false && "TransformObjCInterfaceType unimplemented");
3001 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003002}
Mike Stump11289f42009-09-09 15:08:12 +00003003
3004template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003005QualType
3006TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003007 ObjCObjectPointerTypeLoc TL,
3008 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003009 assert(false && "TransformObjCObjectPointerType unimplemented");
3010 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003011}
3012
Douglas Gregord6ff3322009-08-04 16:50:30 +00003013//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003014// Statement transformation
3015//===----------------------------------------------------------------------===//
3016template<typename Derived>
3017Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003018TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3019 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003020}
3021
3022template<typename Derived>
3023Sema::OwningStmtResult
3024TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3025 return getDerived().TransformCompoundStmt(S, false);
3026}
3027
3028template<typename Derived>
3029Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003030TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003031 bool IsStmtExpr) {
3032 bool SubStmtChanged = false;
3033 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3034 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3035 B != BEnd; ++B) {
3036 OwningStmtResult Result = getDerived().TransformStmt(*B);
3037 if (Result.isInvalid())
3038 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003039
Douglas Gregorebe10102009-08-20 07:17:43 +00003040 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3041 Statements.push_back(Result.takeAs<Stmt>());
3042 }
Mike Stump11289f42009-09-09 15:08:12 +00003043
Douglas Gregorebe10102009-08-20 07:17:43 +00003044 if (!getDerived().AlwaysRebuild() &&
3045 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003046 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003047
3048 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3049 move_arg(Statements),
3050 S->getRBracLoc(),
3051 IsStmtExpr);
3052}
Mike Stump11289f42009-09-09 15:08:12 +00003053
Douglas Gregorebe10102009-08-20 07:17:43 +00003054template<typename Derived>
3055Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003056TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003057 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3058 {
3059 // The case value expressions are not potentially evaluated.
3060 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003061
Eli Friedman06577382009-11-19 03:14:00 +00003062 // Transform the left-hand case value.
3063 LHS = getDerived().TransformExpr(S->getLHS());
3064 if (LHS.isInvalid())
3065 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003066
Eli Friedman06577382009-11-19 03:14:00 +00003067 // Transform the right-hand case value (for the GNU case-range extension).
3068 RHS = getDerived().TransformExpr(S->getRHS());
3069 if (RHS.isInvalid())
3070 return SemaRef.StmtError();
3071 }
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 // Build the case statement.
3074 // Case statements are always rebuilt so that they will attached to their
3075 // transformed switch statement.
3076 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3077 move(LHS),
3078 S->getEllipsisLoc(),
3079 move(RHS),
3080 S->getColonLoc());
3081 if (Case.isInvalid())
3082 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 // Transform the statement following the case
3085 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3086 if (SubStmt.isInvalid())
3087 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003088
Douglas Gregorebe10102009-08-20 07:17:43 +00003089 // Attach the body to the case statement
3090 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3091}
3092
3093template<typename Derived>
3094Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003095TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003096 // Transform the statement following the default case
3097 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3098 if (SubStmt.isInvalid())
3099 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003100
Douglas Gregorebe10102009-08-20 07:17:43 +00003101 // Default statements are always rebuilt
3102 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3103 move(SubStmt));
3104}
Mike Stump11289f42009-09-09 15:08:12 +00003105
Douglas Gregorebe10102009-08-20 07:17:43 +00003106template<typename Derived>
3107Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003108TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003109 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3110 if (SubStmt.isInvalid())
3111 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003112
Douglas Gregorebe10102009-08-20 07:17:43 +00003113 // FIXME: Pass the real colon location in.
3114 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3115 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3116 move(SubStmt));
3117}
Mike Stump11289f42009-09-09 15:08:12 +00003118
Douglas Gregorebe10102009-08-20 07:17:43 +00003119template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003120Sema::OwningStmtResult
3121TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003122 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003123 OwningExprResult Cond(SemaRef);
3124 VarDecl *ConditionVar = 0;
3125 if (S->getConditionVariable()) {
3126 ConditionVar
3127 = cast_or_null<VarDecl>(
3128 getDerived().TransformDefinition(S->getConditionVariable()));
3129 if (!ConditionVar)
3130 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003131 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003132 Cond = getDerived().TransformExpr(S->getCond());
3133
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003134 if (Cond.isInvalid())
3135 return SemaRef.StmtError();
3136 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003137
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003138 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003139
Douglas Gregorebe10102009-08-20 07:17:43 +00003140 // Transform the "then" branch.
3141 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3142 if (Then.isInvalid())
3143 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003144
Douglas Gregorebe10102009-08-20 07:17:43 +00003145 // Transform the "else" branch.
3146 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3147 if (Else.isInvalid())
3148 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150 if (!getDerived().AlwaysRebuild() &&
3151 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003152 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 Then.get() == S->getThen() &&
3154 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003155 return SemaRef.Owned(S->Retain());
3156
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003157 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3158 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003159 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003160}
3161
3162template<typename Derived>
3163Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003164TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003165 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003166 OwningExprResult Cond(SemaRef);
3167 VarDecl *ConditionVar = 0;
3168 if (S->getConditionVariable()) {
3169 ConditionVar
3170 = cast_or_null<VarDecl>(
3171 getDerived().TransformDefinition(S->getConditionVariable()));
3172 if (!ConditionVar)
3173 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003174 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003175 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003176
3177 if (Cond.isInvalid())
3178 return SemaRef.StmtError();
3179 }
Mike Stump11289f42009-09-09 15:08:12 +00003180
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003181 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003182
Douglas Gregorebe10102009-08-20 07:17:43 +00003183 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003184 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3185 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 if (Switch.isInvalid())
3187 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregorebe10102009-08-20 07:17:43 +00003189 // Transform the body of the switch statement.
3190 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3191 if (Body.isInvalid())
3192 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003193
Douglas Gregorebe10102009-08-20 07:17:43 +00003194 // Complete the switch statement.
3195 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3196 move(Body));
3197}
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregorebe10102009-08-20 07:17:43 +00003199template<typename Derived>
3200Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003201TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003202 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003203 OwningExprResult Cond(SemaRef);
3204 VarDecl *ConditionVar = 0;
3205 if (S->getConditionVariable()) {
3206 ConditionVar
3207 = cast_or_null<VarDecl>(
3208 getDerived().TransformDefinition(S->getConditionVariable()));
3209 if (!ConditionVar)
3210 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003211 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003212 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003213
3214 if (Cond.isInvalid())
3215 return SemaRef.StmtError();
3216 }
Mike Stump11289f42009-09-09 15:08:12 +00003217
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003218 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003219
Douglas Gregorebe10102009-08-20 07:17:43 +00003220 // Transform the body
3221 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3222 if (Body.isInvalid())
3223 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003224
Douglas Gregorebe10102009-08-20 07:17:43 +00003225 if (!getDerived().AlwaysRebuild() &&
3226 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003227 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003228 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003229 return SemaRef.Owned(S->Retain());
3230
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003231 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3232 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003233}
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregorebe10102009-08-20 07:17:43 +00003235template<typename Derived>
3236Sema::OwningStmtResult
3237TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3238 // Transform the condition
3239 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3240 if (Cond.isInvalid())
3241 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003242
Douglas Gregorebe10102009-08-20 07:17:43 +00003243 // Transform the body
3244 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3245 if (Body.isInvalid())
3246 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 if (!getDerived().AlwaysRebuild() &&
3249 Cond.get() == S->getCond() &&
3250 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003251 return SemaRef.Owned(S->Retain());
3252
Douglas Gregorebe10102009-08-20 07:17:43 +00003253 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3254 /*FIXME:*/S->getWhileLoc(), move(Cond),
3255 S->getRParenLoc());
3256}
Mike Stump11289f42009-09-09 15:08:12 +00003257
Douglas Gregorebe10102009-08-20 07:17:43 +00003258template<typename Derived>
3259Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003260TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003261 // Transform the initialization statement
3262 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3263 if (Init.isInvalid())
3264 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003267 OwningExprResult Cond(SemaRef);
3268 VarDecl *ConditionVar = 0;
3269 if (S->getConditionVariable()) {
3270 ConditionVar
3271 = cast_or_null<VarDecl>(
3272 getDerived().TransformDefinition(S->getConditionVariable()));
3273 if (!ConditionVar)
3274 return SemaRef.StmtError();
3275 } else {
3276 Cond = getDerived().TransformExpr(S->getCond());
3277
3278 if (Cond.isInvalid())
3279 return SemaRef.StmtError();
3280 }
Mike Stump11289f42009-09-09 15:08:12 +00003281
Douglas Gregorebe10102009-08-20 07:17:43 +00003282 // Transform the increment
3283 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3284 if (Inc.isInvalid())
3285 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003286
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 // Transform the body
3288 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3289 if (Body.isInvalid())
3290 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003291
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 if (!getDerived().AlwaysRebuild() &&
3293 Init.get() == S->getInit() &&
3294 Cond.get() == S->getCond() &&
3295 Inc.get() == S->getInc() &&
3296 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003297 return SemaRef.Owned(S->Retain());
3298
Douglas Gregorebe10102009-08-20 07:17:43 +00003299 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003300 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003301 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003302 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003303 S->getRParenLoc(), move(Body));
3304}
3305
3306template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003307Sema::OwningStmtResult
3308TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003310 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003311 S->getLabel());
3312}
3313
3314template<typename Derived>
3315Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003316TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3318 if (Target.isInvalid())
3319 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003320
Douglas Gregorebe10102009-08-20 07:17:43 +00003321 if (!getDerived().AlwaysRebuild() &&
3322 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003323 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003324
3325 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3326 move(Target));
3327}
3328
3329template<typename Derived>
3330Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003331TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3332 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003333}
Mike Stump11289f42009-09-09 15:08:12 +00003334
Douglas Gregorebe10102009-08-20 07:17:43 +00003335template<typename Derived>
3336Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003337TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3338 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregorebe10102009-08-20 07:17:43 +00003341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003344 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3345 if (Result.isInvalid())
3346 return SemaRef.StmtError();
3347
Mike Stump11289f42009-09-09 15:08:12 +00003348 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003349 // to tell whether the return type of the function has changed.
3350 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3351}
Mike Stump11289f42009-09-09 15:08:12 +00003352
Douglas Gregorebe10102009-08-20 07:17:43 +00003353template<typename Derived>
3354Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003355TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003356 bool DeclChanged = false;
3357 llvm::SmallVector<Decl *, 4> Decls;
3358 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3359 D != DEnd; ++D) {
3360 Decl *Transformed = getDerived().TransformDefinition(*D);
3361 if (!Transformed)
3362 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003363
Douglas Gregorebe10102009-08-20 07:17:43 +00003364 if (Transformed != *D)
3365 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003366
Douglas Gregorebe10102009-08-20 07:17:43 +00003367 Decls.push_back(Transformed);
3368 }
Mike Stump11289f42009-09-09 15:08:12 +00003369
Douglas Gregorebe10102009-08-20 07:17:43 +00003370 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003371 return SemaRef.Owned(S->Retain());
3372
3373 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003374 S->getStartLoc(), S->getEndLoc());
3375}
Mike Stump11289f42009-09-09 15:08:12 +00003376
Douglas Gregorebe10102009-08-20 07:17:43 +00003377template<typename Derived>
3378Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003379TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003380 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003381 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003382}
3383
3384template<typename Derived>
3385Sema::OwningStmtResult
3386TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003387
3388 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3389 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003390 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003391
Anders Carlssonaaeef072010-01-24 05:50:09 +00003392 OwningExprResult AsmString(SemaRef);
3393 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3394
3395 bool ExprsChanged = false;
3396
3397 // Go through the outputs.
3398 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003399 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003400
Anders Carlssonaaeef072010-01-24 05:50:09 +00003401 // No need to transform the constraint literal.
3402 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3403
3404 // Transform the output expr.
3405 Expr *OutputExpr = S->getOutputExpr(I);
3406 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3407 if (Result.isInvalid())
3408 return SemaRef.StmtError();
3409
3410 ExprsChanged |= Result.get() != OutputExpr;
3411
3412 Exprs.push_back(Result.takeAs<Expr>());
3413 }
3414
3415 // Go through the inputs.
3416 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003417 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003418
Anders Carlssonaaeef072010-01-24 05:50:09 +00003419 // No need to transform the constraint literal.
3420 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3421
3422 // Transform the input expr.
3423 Expr *InputExpr = S->getInputExpr(I);
3424 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3425 if (Result.isInvalid())
3426 return SemaRef.StmtError();
3427
3428 ExprsChanged |= Result.get() != InputExpr;
3429
3430 Exprs.push_back(Result.takeAs<Expr>());
3431 }
3432
3433 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3434 return SemaRef.Owned(S->Retain());
3435
3436 // Go through the clobbers.
3437 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3438 Clobbers.push_back(S->getClobber(I)->Retain());
3439
3440 // No need to transform the asm string literal.
3441 AsmString = SemaRef.Owned(S->getAsmString());
3442
3443 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3444 S->isSimple(),
3445 S->isVolatile(),
3446 S->getNumOutputs(),
3447 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003448 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003449 move_arg(Constraints),
3450 move_arg(Exprs),
3451 move(AsmString),
3452 move_arg(Clobbers),
3453 S->getRParenLoc(),
3454 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003455}
3456
3457
3458template<typename Derived>
3459Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003460TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 // FIXME: Implement this
3462 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregorebe10102009-08-20 07:17:43 +00003466template<typename Derived>
3467Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003468TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 // FIXME: Implement this
3470 assert(false && "Cannot transform an Objective-C @catch statement");
3471 return SemaRef.Owned(S->Retain());
3472}
Mike Stump11289f42009-09-09 15:08:12 +00003473
Douglas Gregorebe10102009-08-20 07:17:43 +00003474template<typename Derived>
3475Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003476TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003477 // FIXME: Implement this
3478 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003479 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003480}
Mike Stump11289f42009-09-09 15:08:12 +00003481
Douglas Gregorebe10102009-08-20 07:17:43 +00003482template<typename Derived>
3483Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003484TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003485 // FIXME: Implement this
3486 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003487 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003488}
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregorebe10102009-08-20 07:17:43 +00003490template<typename Derived>
3491Sema::OwningStmtResult
3492TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003493 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 // FIXME: Implement this
3495 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003496 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003497}
3498
3499template<typename Derived>
3500Sema::OwningStmtResult
3501TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003502 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003503 // FIXME: Implement this
3504 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003505 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003506}
3507
3508
3509template<typename Derived>
3510Sema::OwningStmtResult
3511TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3512 // Transform the exception declaration, if any.
3513 VarDecl *Var = 0;
3514 if (S->getExceptionDecl()) {
3515 VarDecl *ExceptionDecl = S->getExceptionDecl();
3516 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3517 ExceptionDecl->getDeclName());
3518
3519 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3520 if (T.isNull())
3521 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3524 T,
John McCallbcd03502009-12-07 02:54:59 +00003525 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003526 ExceptionDecl->getIdentifier(),
3527 ExceptionDecl->getLocation(),
3528 /*FIXME: Inaccurate*/
3529 SourceRange(ExceptionDecl->getLocation()));
3530 if (!Var || Var->isInvalidDecl()) {
3531 if (Var)
3532 Var->Destroy(SemaRef.Context);
3533 return SemaRef.StmtError();
3534 }
3535 }
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregorebe10102009-08-20 07:17:43 +00003537 // Transform the actual exception handler.
3538 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3539 if (Handler.isInvalid()) {
3540 if (Var)
3541 Var->Destroy(SemaRef.Context);
3542 return SemaRef.StmtError();
3543 }
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 if (!getDerived().AlwaysRebuild() &&
3546 !Var &&
3547 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003548 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003549
3550 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3551 Var,
3552 move(Handler));
3553}
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555template<typename Derived>
3556Sema::OwningStmtResult
3557TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3558 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003559 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003560 = getDerived().TransformCompoundStmt(S->getTryBlock());
3561 if (TryBlock.isInvalid())
3562 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003563
Douglas Gregorebe10102009-08-20 07:17:43 +00003564 // Transform the handlers.
3565 bool HandlerChanged = false;
3566 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3567 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003568 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003569 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3570 if (Handler.isInvalid())
3571 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003572
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3574 Handlers.push_back(Handler.takeAs<Stmt>());
3575 }
Mike Stump11289f42009-09-09 15:08:12 +00003576
Douglas Gregorebe10102009-08-20 07:17:43 +00003577 if (!getDerived().AlwaysRebuild() &&
3578 TryBlock.get() == S->getTryBlock() &&
3579 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003580 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003581
3582 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003583 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003587// Expression transformation
3588//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003589template<typename Derived>
3590Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003591TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003592 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003593}
Mike Stump11289f42009-09-09 15:08:12 +00003594
3595template<typename Derived>
3596Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003597TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003598 NestedNameSpecifier *Qualifier = 0;
3599 if (E->getQualifier()) {
3600 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3601 E->getQualifierRange());
3602 if (!Qualifier)
3603 return SemaRef.ExprError();
3604 }
John McCallce546572009-12-08 09:08:17 +00003605
3606 ValueDecl *ND
3607 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 if (!ND)
3609 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003611 if (!getDerived().AlwaysRebuild() &&
3612 Qualifier == E->getQualifier() &&
3613 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003614 !E->hasExplicitTemplateArgumentList()) {
3615
3616 // Mark it referenced in the new context regardless.
3617 // FIXME: this is a bit instantiation-specific.
3618 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3619
Mike Stump11289f42009-09-09 15:08:12 +00003620 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003621 }
John McCallce546572009-12-08 09:08:17 +00003622
3623 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3624 if (E->hasExplicitTemplateArgumentList()) {
3625 TemplateArgs = &TransArgs;
3626 TransArgs.setLAngleLoc(E->getLAngleLoc());
3627 TransArgs.setRAngleLoc(E->getRAngleLoc());
3628 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3629 TemplateArgumentLoc Loc;
3630 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3631 return SemaRef.ExprError();
3632 TransArgs.addArgument(Loc);
3633 }
3634 }
3635
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003636 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003637 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003638}
Mike Stump11289f42009-09-09 15:08:12 +00003639
Douglas Gregora16548e2009-08-11 05:31:07 +00003640template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003641Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003642TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003643 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003644}
Mike Stump11289f42009-09-09 15:08:12 +00003645
Douglas Gregora16548e2009-08-11 05:31:07 +00003646template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003647Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003648TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003649 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003650}
Mike Stump11289f42009-09-09 15:08:12 +00003651
Douglas Gregora16548e2009-08-11 05:31:07 +00003652template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003653Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003654TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003655 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003656}
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregora16548e2009-08-11 05:31:07 +00003658template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003659Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003660TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003661 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003662}
Mike Stump11289f42009-09-09 15:08:12 +00003663
Douglas Gregora16548e2009-08-11 05:31:07 +00003664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003665Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003666TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003667 return SemaRef.Owned(E->Retain());
3668}
3669
3670template<typename Derived>
3671Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003672TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003673 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3674 if (SubExpr.isInvalid())
3675 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003676
Douglas Gregora16548e2009-08-11 05:31:07 +00003677 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003678 return SemaRef.Owned(E->Retain());
3679
3680 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003681 E->getRParen());
3682}
3683
Mike Stump11289f42009-09-09 15:08:12 +00003684template<typename Derived>
3685Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003686TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3687 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 if (SubExpr.isInvalid())
3689 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregora16548e2009-08-11 05:31:07 +00003691 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003692 return SemaRef.Owned(E->Retain());
3693
Douglas Gregora16548e2009-08-11 05:31:07 +00003694 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3695 E->getOpcode(),
3696 move(SubExpr));
3697}
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregora16548e2009-08-11 05:31:07 +00003699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003700Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003701TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003702 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003703 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003704
John McCallbcd03502009-12-07 02:54:59 +00003705 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003706 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003707 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003708
John McCall4c98fd82009-11-04 07:28:41 +00003709 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003710 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003711
John McCall4c98fd82009-11-04 07:28:41 +00003712 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003713 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003714 E->getSourceRange());
3715 }
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregora16548e2009-08-11 05:31:07 +00003717 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003718 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003719 // C++0x [expr.sizeof]p1:
3720 // The operand is either an expression, which is an unevaluated operand
3721 // [...]
3722 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregora16548e2009-08-11 05:31:07 +00003724 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3725 if (SubExpr.isInvalid())
3726 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregora16548e2009-08-11 05:31:07 +00003728 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3729 return SemaRef.Owned(E->Retain());
3730 }
Mike Stump11289f42009-09-09 15:08:12 +00003731
Douglas Gregora16548e2009-08-11 05:31:07 +00003732 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3733 E->isSizeOf(),
3734 E->getSourceRange());
3735}
Mike Stump11289f42009-09-09 15:08:12 +00003736
Douglas Gregora16548e2009-08-11 05:31:07 +00003737template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003738Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003739TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003740 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3741 if (LHS.isInvalid())
3742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3745 if (RHS.isInvalid())
3746 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003747
3748
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 if (!getDerived().AlwaysRebuild() &&
3750 LHS.get() == E->getLHS() &&
3751 RHS.get() == E->getRHS())
3752 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003753
Douglas Gregora16548e2009-08-11 05:31:07 +00003754 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3755 /*FIXME:*/E->getLHS()->getLocStart(),
3756 move(RHS),
3757 E->getRBracketLoc());
3758}
Mike Stump11289f42009-09-09 15:08:12 +00003759
3760template<typename Derived>
3761Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003762TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003763 // Transform the callee.
3764 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3765 if (Callee.isInvalid())
3766 return SemaRef.ExprError();
3767
3768 // Transform arguments.
3769 bool ArgChanged = false;
3770 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3771 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3772 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3773 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3774 if (Arg.isInvalid())
3775 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003776
Douglas Gregora16548e2009-08-11 05:31:07 +00003777 // FIXME: Wrong source location information for the ','.
3778 FakeCommaLocs.push_back(
3779 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003780
3781 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 Args.push_back(Arg.takeAs<Expr>());
3783 }
Mike Stump11289f42009-09-09 15:08:12 +00003784
Douglas Gregora16548e2009-08-11 05:31:07 +00003785 if (!getDerived().AlwaysRebuild() &&
3786 Callee.get() == E->getCallee() &&
3787 !ArgChanged)
3788 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregora16548e2009-08-11 05:31:07 +00003790 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003791 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003792 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3793 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3794 move_arg(Args),
3795 FakeCommaLocs.data(),
3796 E->getRParenLoc());
3797}
Mike Stump11289f42009-09-09 15:08:12 +00003798
3799template<typename Derived>
3800Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003801TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003802 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3803 if (Base.isInvalid())
3804 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003805
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003806 NestedNameSpecifier *Qualifier = 0;
3807 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003808 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003809 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3810 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003811 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003812 return SemaRef.ExprError();
3813 }
Mike Stump11289f42009-09-09 15:08:12 +00003814
Eli Friedman2cfcef62009-12-04 06:40:45 +00003815 ValueDecl *Member
3816 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003817 if (!Member)
3818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregora16548e2009-08-11 05:31:07 +00003820 if (!getDerived().AlwaysRebuild() &&
3821 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003822 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003823 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003824 !E->hasExplicitTemplateArgumentList()) {
3825
3826 // Mark it referenced in the new context regardless.
3827 // FIXME: this is a bit instantiation-specific.
3828 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003829 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003830 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003831
John McCall6b51f282009-11-23 01:53:49 +00003832 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003833 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003834 TransArgs.setLAngleLoc(E->getLAngleLoc());
3835 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003836 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003837 TemplateArgumentLoc Loc;
3838 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003839 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003840 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003841 }
3842 }
3843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 // FIXME: Bogus source location for the operator
3845 SourceLocation FakeOperatorLoc
3846 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3847
John McCall38836f02010-01-15 08:34:02 +00003848 // FIXME: to do this check properly, we will need to preserve the
3849 // first-qualifier-in-scope here, just in case we had a dependent
3850 // base (and therefore couldn't do the check) and a
3851 // nested-name-qualifier (and therefore could do the lookup).
3852 NamedDecl *FirstQualifierInScope = 0;
3853
Douglas Gregora16548e2009-08-11 05:31:07 +00003854 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3855 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003856 Qualifier,
3857 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003859 Member,
John McCall6b51f282009-11-23 01:53:49 +00003860 (E->hasExplicitTemplateArgumentList()
3861 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003862 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003863}
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregora16548e2009-08-11 05:31:07 +00003865template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003866Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003867TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003868 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3869 if (LHS.isInvalid())
3870 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregora16548e2009-08-11 05:31:07 +00003872 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3873 if (RHS.isInvalid())
3874 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876 if (!getDerived().AlwaysRebuild() &&
3877 LHS.get() == E->getLHS() &&
3878 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003879 return SemaRef.Owned(E->Retain());
3880
Douglas Gregora16548e2009-08-11 05:31:07 +00003881 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3882 move(LHS), move(RHS));
3883}
3884
Mike Stump11289f42009-09-09 15:08:12 +00003885template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003886Sema::OwningExprResult
3887TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003888 CompoundAssignOperator *E) {
3889 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003890}
Mike Stump11289f42009-09-09 15:08:12 +00003891
Douglas Gregora16548e2009-08-11 05:31:07 +00003892template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003893Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003894TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003895 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3896 if (Cond.isInvalid())
3897 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregora16548e2009-08-11 05:31:07 +00003899 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3900 if (LHS.isInvalid())
3901 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003902
Douglas Gregora16548e2009-08-11 05:31:07 +00003903 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3904 if (RHS.isInvalid())
3905 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003906
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 if (!getDerived().AlwaysRebuild() &&
3908 Cond.get() == E->getCond() &&
3909 LHS.get() == E->getLHS() &&
3910 RHS.get() == E->getRHS())
3911 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003912
3913 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003914 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003915 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003916 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 move(RHS));
3918}
Mike Stump11289f42009-09-09 15:08:12 +00003919
3920template<typename Derived>
3921Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003922TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003923 // Implicit casts are eliminated during transformation, since they
3924 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003925 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003926}
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregora16548e2009-08-11 05:31:07 +00003928template<typename Derived>
3929Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003930TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003931 TypeSourceInfo *OldT;
3932 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 {
3934 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003935 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3937 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003938
John McCall97513962010-01-15 18:39:57 +00003939 OldT = E->getTypeInfoAsWritten();
3940 NewT = getDerived().TransformType(OldT);
3941 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 return SemaRef.ExprError();
3943 }
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregor6131b442009-12-12 18:16:41 +00003945 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003946 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 if (SubExpr.isInvalid())
3948 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003949
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003951 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003953 return SemaRef.Owned(E->Retain());
3954
John McCall97513962010-01-15 18:39:57 +00003955 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3956 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003957 E->getRParenLoc(),
3958 move(SubExpr));
3959}
Mike Stump11289f42009-09-09 15:08:12 +00003960
Douglas Gregora16548e2009-08-11 05:31:07 +00003961template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003962Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003963TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003964 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3965 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3966 if (!NewT)
3967 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003968
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3970 if (Init.isInvalid())
3971 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003974 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003976 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003977
John McCall5d7aa7f2010-01-19 22:33:45 +00003978 // Note: the expression type doesn't necessarily match the
3979 // type-as-written, but that's okay, because it should always be
3980 // derivable from the initializer.
3981
John McCalle15bbff2010-01-18 19:35:47 +00003982 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003983 /*FIXME:*/E->getInitializer()->getLocEnd(),
3984 move(Init));
3985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
Douglas Gregora16548e2009-08-11 05:31:07 +00003987template<typename Derived>
3988Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003989TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003990 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3991 if (Base.isInvalid())
3992 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003993
Douglas Gregora16548e2009-08-11 05:31:07 +00003994 if (!getDerived().AlwaysRebuild() &&
3995 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003996 return SemaRef.Owned(E->Retain());
3997
Douglas Gregora16548e2009-08-11 05:31:07 +00003998 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003999 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4001 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4002 E->getAccessorLoc(),
4003 E->getAccessor());
4004}
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004007Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004008TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004009 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004010
Douglas Gregora16548e2009-08-11 05:31:07 +00004011 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4012 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4013 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4014 if (Init.isInvalid())
4015 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregora16548e2009-08-11 05:31:07 +00004017 InitChanged = InitChanged || Init.get() != E->getInit(I);
4018 Inits.push_back(Init.takeAs<Expr>());
4019 }
Mike Stump11289f42009-09-09 15:08:12 +00004020
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004022 return SemaRef.Owned(E->Retain());
4023
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004025 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004026}
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028template<typename Derived>
4029Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004030TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004031 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregorebe10102009-08-20 07:17:43 +00004033 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004034 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4035 if (Init.isInvalid())
4036 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004037
Douglas Gregorebe10102009-08-20 07:17:43 +00004038 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004039 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4040 bool ExprChanged = false;
4041 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4042 DEnd = E->designators_end();
4043 D != DEnd; ++D) {
4044 if (D->isFieldDesignator()) {
4045 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4046 D->getDotLoc(),
4047 D->getFieldLoc()));
4048 continue;
4049 }
Mike Stump11289f42009-09-09 15:08:12 +00004050
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 if (D->isArrayDesignator()) {
4052 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4053 if (Index.isInvalid())
4054 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004055
4056 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregora16548e2009-08-11 05:31:07 +00004059 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4060 ArrayExprs.push_back(Index.release());
4061 continue;
4062 }
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregora16548e2009-08-11 05:31:07 +00004064 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004065 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4067 if (Start.isInvalid())
4068 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4071 if (End.isInvalid())
4072 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004073
4074 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 End.get(),
4076 D->getLBracketLoc(),
4077 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4080 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004081
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 ArrayExprs.push_back(Start.release());
4083 ArrayExprs.push_back(End.release());
4084 }
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 if (!getDerived().AlwaysRebuild() &&
4087 Init.get() == E->getInit() &&
4088 !ExprChanged)
4089 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4092 E->getEqualOrColonLoc(),
4093 E->usesGNUSyntax(), move(Init));
4094}
Mike Stump11289f42009-09-09 15:08:12 +00004095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004097Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004098TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004099 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004100 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4101
4102 // FIXME: Will we ever have proper type location here? Will we actually
4103 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004104 QualType T = getDerived().TransformType(E->getType());
4105 if (T.isNull())
4106 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 if (!getDerived().AlwaysRebuild() &&
4109 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004110 return SemaRef.Owned(E->Retain());
4111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 return getDerived().RebuildImplicitValueInitExpr(T);
4113}
Mike Stump11289f42009-09-09 15:08:12 +00004114
Douglas Gregora16548e2009-08-11 05:31:07 +00004115template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004116Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004117TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004118 // FIXME: Do we want the type as written?
4119 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004120
Douglas Gregora16548e2009-08-11 05:31:07 +00004121 {
4122 // FIXME: Source location isn't quite accurate.
4123 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4124 T = getDerived().TransformType(E->getType());
4125 if (T.isNull())
4126 return SemaRef.ExprError();
4127 }
Mike Stump11289f42009-09-09 15:08:12 +00004128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4130 if (SubExpr.isInvalid())
4131 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 if (!getDerived().AlwaysRebuild() &&
4134 T == E->getType() &&
4135 SubExpr.get() == E->getSubExpr())
4136 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004137
Douglas Gregora16548e2009-08-11 05:31:07 +00004138 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4139 T, E->getRParenLoc());
4140}
4141
4142template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004143Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004144TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004145 bool ArgumentChanged = false;
4146 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4147 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4148 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4149 if (Init.isInvalid())
4150 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004151
Douglas Gregora16548e2009-08-11 05:31:07 +00004152 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4153 Inits.push_back(Init.takeAs<Expr>());
4154 }
Mike Stump11289f42009-09-09 15:08:12 +00004155
Douglas Gregora16548e2009-08-11 05:31:07 +00004156 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4157 move_arg(Inits),
4158 E->getRParenLoc());
4159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161/// \brief Transform an address-of-label expression.
4162///
4163/// By default, the transformation of an address-of-label expression always
4164/// rebuilds the expression, so that the label identifier can be resolved to
4165/// the corresponding label statement by semantic analysis.
4166template<typename Derived>
4167Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004168TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004169 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4170 E->getLabel());
4171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
4173template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004174Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004175TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004176 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4178 if (SubStmt.isInvalid())
4179 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 if (!getDerived().AlwaysRebuild() &&
4182 SubStmt.get() == E->getSubStmt())
4183 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004184
4185 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 move(SubStmt),
4187 E->getRParenLoc());
4188}
Mike Stump11289f42009-09-09 15:08:12 +00004189
Douglas Gregora16548e2009-08-11 05:31:07 +00004190template<typename Derived>
4191Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004192TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 QualType T1, T2;
4194 {
4195 // FIXME: Source location isn't quite accurate.
4196 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004197
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 T1 = getDerived().TransformType(E->getArgType1());
4199 if (T1.isNull())
4200 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 T2 = getDerived().TransformType(E->getArgType2());
4203 if (T2.isNull())
4204 return SemaRef.ExprError();
4205 }
4206
4207 if (!getDerived().AlwaysRebuild() &&
4208 T1 == E->getArgType1() &&
4209 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004210 return SemaRef.Owned(E->Retain());
4211
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4213 T1, T2, E->getRParenLoc());
4214}
Mike Stump11289f42009-09-09 15:08:12 +00004215
Douglas Gregora16548e2009-08-11 05:31:07 +00004216template<typename Derived>
4217Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004218TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4220 if (Cond.isInvalid())
4221 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004222
Douglas Gregora16548e2009-08-11 05:31:07 +00004223 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4224 if (LHS.isInvalid())
4225 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004226
Douglas Gregora16548e2009-08-11 05:31:07 +00004227 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4228 if (RHS.isInvalid())
4229 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004230
Douglas Gregora16548e2009-08-11 05:31:07 +00004231 if (!getDerived().AlwaysRebuild() &&
4232 Cond.get() == E->getCond() &&
4233 LHS.get() == E->getLHS() &&
4234 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004235 return SemaRef.Owned(E->Retain());
4236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4238 move(Cond), move(LHS), move(RHS),
4239 E->getRParenLoc());
4240}
Mike Stump11289f42009-09-09 15:08:12 +00004241
Douglas Gregora16548e2009-08-11 05:31:07 +00004242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004243Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004244TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004245 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004246}
4247
4248template<typename Derived>
4249Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004250TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004251 switch (E->getOperator()) {
4252 case OO_New:
4253 case OO_Delete:
4254 case OO_Array_New:
4255 case OO_Array_Delete:
4256 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4257 return SemaRef.ExprError();
4258
4259 case OO_Call: {
4260 // This is a call to an object's operator().
4261 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4262
4263 // Transform the object itself.
4264 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4265 if (Object.isInvalid())
4266 return SemaRef.ExprError();
4267
4268 // FIXME: Poor location information
4269 SourceLocation FakeLParenLoc
4270 = SemaRef.PP.getLocForEndOfToken(
4271 static_cast<Expr *>(Object.get())->getLocEnd());
4272
4273 // Transform the call arguments.
4274 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4275 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4276 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004277 if (getDerived().DropCallArgument(E->getArg(I)))
4278 break;
4279
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004280 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4281 if (Arg.isInvalid())
4282 return SemaRef.ExprError();
4283
4284 // FIXME: Poor source location information.
4285 SourceLocation FakeCommaLoc
4286 = SemaRef.PP.getLocForEndOfToken(
4287 static_cast<Expr *>(Arg.get())->getLocEnd());
4288 FakeCommaLocs.push_back(FakeCommaLoc);
4289 Args.push_back(Arg.release());
4290 }
4291
4292 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4293 move_arg(Args),
4294 FakeCommaLocs.data(),
4295 E->getLocEnd());
4296 }
4297
4298#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4299 case OO_##Name:
4300#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4301#include "clang/Basic/OperatorKinds.def"
4302 case OO_Subscript:
4303 // Handled below.
4304 break;
4305
4306 case OO_Conditional:
4307 llvm_unreachable("conditional operator is not actually overloadable");
4308 return SemaRef.ExprError();
4309
4310 case OO_None:
4311 case NUM_OVERLOADED_OPERATORS:
4312 llvm_unreachable("not an overloaded operator?");
4313 return SemaRef.ExprError();
4314 }
4315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4317 if (Callee.isInvalid())
4318 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004319
John McCall47f29ea2009-12-08 09:21:05 +00004320 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 if (First.isInvalid())
4322 return SemaRef.ExprError();
4323
4324 OwningExprResult Second(SemaRef);
4325 if (E->getNumArgs() == 2) {
4326 Second = getDerived().TransformExpr(E->getArg(1));
4327 if (Second.isInvalid())
4328 return SemaRef.ExprError();
4329 }
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 if (!getDerived().AlwaysRebuild() &&
4332 Callee.get() == E->getCallee() &&
4333 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004334 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4335 return SemaRef.Owned(E->Retain());
4336
Douglas Gregora16548e2009-08-11 05:31:07 +00004337 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4338 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004339 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004340 move(First),
4341 move(Second));
4342}
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344template<typename Derived>
4345Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004346TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4347 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004351Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004353 TypeSourceInfo *OldT;
4354 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 {
4356 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004357 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4359 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004360
John McCall97513962010-01-15 18:39:57 +00004361 OldT = E->getTypeInfoAsWritten();
4362 NewT = getDerived().TransformType(OldT);
4363 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004364 return SemaRef.ExprError();
4365 }
Mike Stump11289f42009-09-09 15:08:12 +00004366
Douglas Gregor6131b442009-12-12 18:16:41 +00004367 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004368 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 if (SubExpr.isInvalid())
4370 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004373 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004375 return SemaRef.Owned(E->Retain());
4376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004378 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4380 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4381 SourceLocation FakeRParenLoc
4382 = SemaRef.PP.getLocForEndOfToken(
4383 E->getSubExpr()->getSourceRange().getEnd());
4384 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004385 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004387 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 FakeRAngleLoc,
4389 FakeRAngleLoc,
4390 move(SubExpr),
4391 FakeRParenLoc);
4392}
Mike Stump11289f42009-09-09 15:08:12 +00004393
Douglas Gregora16548e2009-08-11 05:31:07 +00004394template<typename Derived>
4395Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004396TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4397 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004398}
Mike Stump11289f42009-09-09 15:08:12 +00004399
4400template<typename Derived>
4401Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004402TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4403 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004404}
4405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406template<typename Derived>
4407Sema::OwningExprResult
4408TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004409 CXXReinterpretCastExpr *E) {
4410 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004411}
Mike Stump11289f42009-09-09 15:08:12 +00004412
Douglas Gregora16548e2009-08-11 05:31:07 +00004413template<typename Derived>
4414Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004415TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4416 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004417}
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregora16548e2009-08-11 05:31:07 +00004419template<typename Derived>
4420Sema::OwningExprResult
4421TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004422 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004423 TypeSourceInfo *OldT;
4424 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 {
4426 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004427
John McCall97513962010-01-15 18:39:57 +00004428 OldT = E->getTypeInfoAsWritten();
4429 NewT = getDerived().TransformType(OldT);
4430 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004431 return SemaRef.ExprError();
4432 }
Mike Stump11289f42009-09-09 15:08:12 +00004433
Douglas Gregor6131b442009-12-12 18:16:41 +00004434 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004435 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 if (SubExpr.isInvalid())
4437 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004438
Douglas Gregora16548e2009-08-11 05:31:07 +00004439 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004440 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004442 return SemaRef.Owned(E->Retain());
4443
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 // FIXME: The end of the type's source range is wrong
4445 return getDerived().RebuildCXXFunctionalCastExpr(
4446 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004447 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 /*FIXME:*/E->getSubExpr()->getLocStart(),
4449 move(SubExpr),
4450 E->getRParenLoc());
4451}
Mike Stump11289f42009-09-09 15:08:12 +00004452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453template<typename Derived>
4454Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004455TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (E->isTypeOperand()) {
4457 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459 QualType T = getDerived().TransformType(E->getTypeOperand());
4460 if (T.isNull())
4461 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 if (!getDerived().AlwaysRebuild() &&
4464 T == E->getTypeOperand())
4465 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4468 /*FIXME:*/E->getLocStart(),
4469 T,
4470 E->getLocEnd());
4471 }
Mike Stump11289f42009-09-09 15:08:12 +00004472
Douglas Gregora16548e2009-08-11 05:31:07 +00004473 // We don't know whether the expression is potentially evaluated until
4474 // after we perform semantic analysis, so the expression is potentially
4475 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004476 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004477 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4480 if (SubExpr.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 if (!getDerived().AlwaysRebuild() &&
4484 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004485 return SemaRef.Owned(E->Retain());
4486
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4488 /*FIXME:*/E->getLocStart(),
4489 move(SubExpr),
4490 E->getLocEnd());
4491}
4492
4493template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004494Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004495TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004496 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004497}
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499template<typename Derived>
4500Sema::OwningExprResult
4501TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004502 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004503 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506template<typename Derived>
4507Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511 QualType T = getDerived().TransformType(E->getType());
4512 if (T.isNull())
4513 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004514
Douglas Gregora16548e2009-08-11 05:31:07 +00004515 if (!getDerived().AlwaysRebuild() &&
4516 T == E->getType())
4517 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregorb15af892010-01-07 23:12:05 +00004519 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004520}
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregora16548e2009-08-11 05:31:07 +00004522template<typename Derived>
4523Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004524TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004525 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4526 if (SubExpr.isInvalid())
4527 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 if (!getDerived().AlwaysRebuild() &&
4530 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004531 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004532
4533 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4534}
Mike Stump11289f42009-09-09 15:08:12 +00004535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536template<typename Derived>
4537Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004538TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004539 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004540 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4541 if (!Param)
4542 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Chandler Carruth794da4c2010-02-08 06:42:49 +00004544 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 Param == E->getParam())
4546 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregor033f6752009-12-23 23:03:06 +00004548 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004549}
Mike Stump11289f42009-09-09 15:08:12 +00004550
Douglas Gregora16548e2009-08-11 05:31:07 +00004551template<typename Derived>
4552Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004553TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4555
4556 QualType T = getDerived().TransformType(E->getType());
4557 if (T.isNull())
4558 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregora16548e2009-08-11 05:31:07 +00004560 if (!getDerived().AlwaysRebuild() &&
4561 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004562 return SemaRef.Owned(E->Retain());
4563
4564 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004565 /*FIXME:*/E->getTypeBeginLoc(),
4566 T,
4567 E->getRParenLoc());
4568}
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570template<typename Derived>
4571Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004572TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004573 // Transform the type that we're allocating
4574 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4575 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4576 if (AllocType.isNull())
4577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregora16548e2009-08-11 05:31:07 +00004579 // Transform the size of the array we're allocating (if any).
4580 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4581 if (ArraySize.isInvalid())
4582 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004583
Douglas Gregora16548e2009-08-11 05:31:07 +00004584 // Transform the placement arguments (if any).
4585 bool ArgumentChanged = false;
4586 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4587 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4588 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4589 if (Arg.isInvalid())
4590 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004591
Douglas Gregora16548e2009-08-11 05:31:07 +00004592 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4593 PlacementArgs.push_back(Arg.take());
4594 }
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregorebe10102009-08-20 07:17:43 +00004596 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4598 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4599 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4600 if (Arg.isInvalid())
4601 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004602
Douglas Gregora16548e2009-08-11 05:31:07 +00004603 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4604 ConstructorArgs.push_back(Arg.take());
4605 }
Mike Stump11289f42009-09-09 15:08:12 +00004606
Douglas Gregora16548e2009-08-11 05:31:07 +00004607 if (!getDerived().AlwaysRebuild() &&
4608 AllocType == E->getAllocatedType() &&
4609 ArraySize.get() == E->getArraySize() &&
4610 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004611 return SemaRef.Owned(E->Retain());
4612
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004613 if (!ArraySize.get()) {
4614 // If no array size was specified, but the new expression was
4615 // instantiated with an array type (e.g., "new T" where T is
4616 // instantiated with "int[4]"), extract the outer bound from the
4617 // array type as our array size. We do this with constant and
4618 // dependently-sized array types.
4619 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4620 if (!ArrayT) {
4621 // Do nothing
4622 } else if (const ConstantArrayType *ConsArrayT
4623 = dyn_cast<ConstantArrayType>(ArrayT)) {
4624 ArraySize
4625 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4626 ConsArrayT->getSize(),
4627 SemaRef.Context.getSizeType(),
4628 /*FIXME:*/E->getLocStart()));
4629 AllocType = ConsArrayT->getElementType();
4630 } else if (const DependentSizedArrayType *DepArrayT
4631 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4632 if (DepArrayT->getSizeExpr()) {
4633 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4634 AllocType = DepArrayT->getElementType();
4635 }
4636 }
4637 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4639 E->isGlobalNew(),
4640 /*FIXME:*/E->getLocStart(),
4641 move_arg(PlacementArgs),
4642 /*FIXME:*/E->getLocStart(),
4643 E->isParenTypeId(),
4644 AllocType,
4645 /*FIXME:*/E->getLocStart(),
4646 /*FIXME:*/SourceRange(),
4647 move(ArraySize),
4648 /*FIXME:*/E->getLocStart(),
4649 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004650 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004651}
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653template<typename Derived>
4654Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004655TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004656 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4657 if (Operand.isInvalid())
4658 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004661 Operand.get() == E->getArgument())
4662 return SemaRef.Owned(E->Retain());
4663
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4665 E->isGlobalDelete(),
4666 E->isArrayForm(),
4667 move(Operand));
4668}
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670template<typename Derived>
4671Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004672TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004673 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004674 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4675 if (Base.isInvalid())
4676 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregorad8a3362009-09-04 17:36:40 +00004678 NestedNameSpecifier *Qualifier
4679 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4680 E->getQualifierRange());
4681 if (E->getQualifier() && !Qualifier)
4682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregorad8a3362009-09-04 17:36:40 +00004684 QualType DestroyedType;
4685 {
4686 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4687 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4688 if (DestroyedType.isNull())
4689 return SemaRef.ExprError();
4690 }
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregorad8a3362009-09-04 17:36:40 +00004692 if (!getDerived().AlwaysRebuild() &&
4693 Base.get() == E->getBase() &&
4694 Qualifier == E->getQualifier() &&
4695 DestroyedType == E->getDestroyedType())
4696 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregorad8a3362009-09-04 17:36:40 +00004698 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4699 E->getOperatorLoc(),
4700 E->isArrow(),
4701 E->getDestroyedTypeLoc(),
4702 DestroyedType,
4703 Qualifier,
4704 E->getQualifierRange());
4705}
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregorad8a3362009-09-04 17:36:40 +00004707template<typename Derived>
4708Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004709TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004710 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004711 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4712
4713 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4714 Sema::LookupOrdinaryName);
4715
4716 // Transform all the decls.
4717 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4718 E = Old->decls_end(); I != E; ++I) {
4719 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004720 if (!InstD) {
4721 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4722 // This can happen because of dependent hiding.
4723 if (isa<UsingShadowDecl>(*I))
4724 continue;
4725 else
4726 return SemaRef.ExprError();
4727 }
John McCalle66edc12009-11-24 19:00:30 +00004728
4729 // Expand using declarations.
4730 if (isa<UsingDecl>(InstD)) {
4731 UsingDecl *UD = cast<UsingDecl>(InstD);
4732 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4733 E = UD->shadow_end(); I != E; ++I)
4734 R.addDecl(*I);
4735 continue;
4736 }
4737
4738 R.addDecl(InstD);
4739 }
4740
4741 // Resolve a kind, but don't do any further analysis. If it's
4742 // ambiguous, the callee needs to deal with it.
4743 R.resolveKind();
4744
4745 // Rebuild the nested-name qualifier, if present.
4746 CXXScopeSpec SS;
4747 NestedNameSpecifier *Qualifier = 0;
4748 if (Old->getQualifier()) {
4749 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4750 Old->getQualifierRange());
4751 if (!Qualifier)
4752 return SemaRef.ExprError();
4753
4754 SS.setScopeRep(Qualifier);
4755 SS.setRange(Old->getQualifierRange());
4756 }
4757
4758 // If we have no template arguments, it's a normal declaration name.
4759 if (!Old->hasExplicitTemplateArgs())
4760 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4761
4762 // If we have template arguments, rebuild them, then rebuild the
4763 // templateid expression.
4764 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4765 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4766 TemplateArgumentLoc Loc;
4767 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4768 return SemaRef.ExprError();
4769 TransArgs.addArgument(Loc);
4770 }
4771
4772 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4773 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004774}
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776template<typename Derived>
4777Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004778TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 QualType T = getDerived().TransformType(E->getQueriedType());
4782 if (T.isNull())
4783 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 if (!getDerived().AlwaysRebuild() &&
4786 T == E->getQueriedType())
4787 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004788
Douglas Gregora16548e2009-08-11 05:31:07 +00004789 // FIXME: Bad location information
4790 SourceLocation FakeLParenLoc
4791 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004792
4793 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 E->getLocStart(),
4795 /*FIXME:*/FakeLParenLoc,
4796 T,
4797 E->getLocEnd());
4798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800template<typename Derived>
4801Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004802TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004803 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004805 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4806 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 if (!NNS)
4808 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
4810 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004811 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4812 if (!Name)
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
John McCalle66edc12009-11-24 19:00:30 +00004815 if (!E->hasExplicitTemplateArgs()) {
4816 if (!getDerived().AlwaysRebuild() &&
4817 NNS == E->getQualifier() &&
4818 Name == E->getDeclName())
4819 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004820
John McCalle66edc12009-11-24 19:00:30 +00004821 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4822 E->getQualifierRange(),
4823 Name, E->getLocation(),
4824 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004825 }
John McCall6b51f282009-11-23 01:53:49 +00004826
4827 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004828 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004829 TemplateArgumentLoc Loc;
4830 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004832 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 }
4834
John McCalle66edc12009-11-24 19:00:30 +00004835 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4836 E->getQualifierRange(),
4837 Name, E->getLocation(),
4838 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004839}
4840
4841template<typename Derived>
4842Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004843TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004844 // CXXConstructExprs are always implicit, so when we have a
4845 // 1-argument construction we just transform that argument.
4846 if (E->getNumArgs() == 1 ||
4847 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4848 return getDerived().TransformExpr(E->getArg(0));
4849
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4851
4852 QualType T = getDerived().TransformType(E->getType());
4853 if (T.isNull())
4854 return SemaRef.ExprError();
4855
4856 CXXConstructorDecl *Constructor
4857 = cast_or_null<CXXConstructorDecl>(
4858 getDerived().TransformDecl(E->getConstructor()));
4859 if (!Constructor)
4860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 bool ArgumentChanged = false;
4863 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004864 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 ArgEnd = E->arg_end();
4866 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004867 if (getDerived().DropCallArgument(*Arg)) {
4868 ArgumentChanged = true;
4869 break;
4870 }
4871
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4873 if (TransArg.isInvalid())
4874 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004875
Douglas Gregora16548e2009-08-11 05:31:07 +00004876 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4877 Args.push_back(TransArg.takeAs<Expr>());
4878 }
4879
4880 if (!getDerived().AlwaysRebuild() &&
4881 T == E->getType() &&
4882 Constructor == E->getConstructor() &&
4883 !ArgumentChanged)
4884 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004885
Douglas Gregordb121ba2009-12-14 16:27:04 +00004886 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4887 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 move_arg(Args));
4889}
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891/// \brief Transform a C++ temporary-binding expression.
4892///
Douglas Gregor363b1512009-12-24 18:51:59 +00004893/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4894/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004895template<typename Derived>
4896Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004897TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004898 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004899}
Mike Stump11289f42009-09-09 15:08:12 +00004900
Anders Carlssonba6c4372010-01-29 02:39:32 +00004901/// \brief Transform a C++ reference-binding expression.
4902///
4903/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4904/// transform the subexpression and return that.
4905template<typename Derived>
4906Sema::OwningExprResult
4907TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4908 return getDerived().TransformExpr(E->getSubExpr());
4909}
4910
Mike Stump11289f42009-09-09 15:08:12 +00004911/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004912/// be destroyed after the expression is evaluated.
4913///
Douglas Gregor363b1512009-12-24 18:51:59 +00004914/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4915/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004916template<typename Derived>
4917Sema::OwningExprResult
4918TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004919 CXXExprWithTemporaries *E) {
4920 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004921}
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregora16548e2009-08-11 05:31:07 +00004923template<typename Derived>
4924Sema::OwningExprResult
4925TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004926 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004927 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4928 QualType T = getDerived().TransformType(E->getType());
4929 if (T.isNull())
4930 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004931
Douglas Gregora16548e2009-08-11 05:31:07 +00004932 CXXConstructorDecl *Constructor
4933 = cast_or_null<CXXConstructorDecl>(
4934 getDerived().TransformDecl(E->getConstructor()));
4935 if (!Constructor)
4936 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 bool ArgumentChanged = false;
4939 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4940 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004941 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004942 ArgEnd = E->arg_end();
4943 Arg != ArgEnd; ++Arg) {
4944 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4945 if (TransArg.isInvalid())
4946 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004947
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4949 Args.push_back((Expr *)TransArg.release());
4950 }
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 if (!getDerived().AlwaysRebuild() &&
4953 T == E->getType() &&
4954 Constructor == E->getConstructor() &&
4955 !ArgumentChanged)
4956 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004957
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 // FIXME: Bogus location information
4959 SourceLocation CommaLoc;
4960 if (Args.size() > 1) {
4961 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004962 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4964 }
4965 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4966 T,
4967 /*FIXME:*/E->getTypeBeginLoc(),
4968 move_arg(Args),
4969 &CommaLoc,
4970 E->getLocEnd());
4971}
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973template<typename Derived>
4974Sema::OwningExprResult
4975TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004976 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004977 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4978 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4979 if (T.isNull())
4980 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004981
Douglas Gregora16548e2009-08-11 05:31:07 +00004982 bool ArgumentChanged = false;
4983 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4984 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4985 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4986 ArgEnd = E->arg_end();
4987 Arg != ArgEnd; ++Arg) {
4988 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4989 if (TransArg.isInvalid())
4990 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4993 FakeCommaLocs.push_back(
4994 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4995 Args.push_back(TransArg.takeAs<Expr>());
4996 }
Mike Stump11289f42009-09-09 15:08:12 +00004997
Douglas Gregora16548e2009-08-11 05:31:07 +00004998 if (!getDerived().AlwaysRebuild() &&
4999 T == E->getTypeAsWritten() &&
5000 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005001 return SemaRef.Owned(E->Retain());
5002
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 // FIXME: we're faking the locations of the commas
5004 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5005 T,
5006 E->getLParenLoc(),
5007 move_arg(Args),
5008 FakeCommaLocs.data(),
5009 E->getRParenLoc());
5010}
Mike Stump11289f42009-09-09 15:08:12 +00005011
Douglas Gregora16548e2009-08-11 05:31:07 +00005012template<typename Derived>
5013Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005014TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005015 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005016 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005017 OwningExprResult Base(SemaRef, (Expr*) 0);
5018 Expr *OldBase;
5019 QualType BaseType;
5020 QualType ObjectType;
5021 if (!E->isImplicitAccess()) {
5022 OldBase = E->getBase();
5023 Base = getDerived().TransformExpr(OldBase);
5024 if (Base.isInvalid())
5025 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005026
John McCall2d74de92009-12-01 22:10:20 +00005027 // Start the member reference and compute the object's type.
5028 Sema::TypeTy *ObjectTy = 0;
5029 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5030 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005031 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00005032 ObjectTy);
5033 if (Base.isInvalid())
5034 return SemaRef.ExprError();
5035
5036 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5037 BaseType = ((Expr*) Base.get())->getType();
5038 } else {
5039 OldBase = 0;
5040 BaseType = getDerived().TransformType(E->getBaseType());
5041 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5042 }
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005044 // Transform the first part of the nested-name-specifier that qualifies
5045 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005046 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005047 = getDerived().TransformFirstQualifierInScope(
5048 E->getFirstQualifierFoundInScope(),
5049 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005050
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005051 NestedNameSpecifier *Qualifier = 0;
5052 if (E->getQualifier()) {
5053 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5054 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005055 ObjectType,
5056 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005057 if (!Qualifier)
5058 return SemaRef.ExprError();
5059 }
Mike Stump11289f42009-09-09 15:08:12 +00005060
5061 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005062 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005063 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005064 if (!Name)
5065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005066
John McCall2d74de92009-12-01 22:10:20 +00005067 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005068 // This is a reference to a member without an explicitly-specified
5069 // template argument list. Optimize for this common case.
5070 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005071 Base.get() == OldBase &&
5072 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005073 Qualifier == E->getQualifier() &&
5074 Name == E->getMember() &&
5075 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005076 return SemaRef.Owned(E->Retain());
5077
John McCall8cd78132009-11-19 22:55:06 +00005078 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005079 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005080 E->isArrow(),
5081 E->getOperatorLoc(),
5082 Qualifier,
5083 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005084 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005085 Name,
5086 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005087 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005088 }
5089
John McCall6b51f282009-11-23 01:53:49 +00005090 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005091 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005092 TemplateArgumentLoc Loc;
5093 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005094 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005095 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005096 }
Mike Stump11289f42009-09-09 15:08:12 +00005097
John McCall8cd78132009-11-19 22:55:06 +00005098 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005099 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 E->isArrow(),
5101 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005102 Qualifier,
5103 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005104 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005105 Name,
5106 E->getMemberLoc(),
5107 &TransArgs);
5108}
5109
5110template<typename Derived>
5111Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005112TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005113 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005114 OwningExprResult Base(SemaRef, (Expr*) 0);
5115 QualType BaseType;
5116 if (!Old->isImplicitAccess()) {
5117 Base = getDerived().TransformExpr(Old->getBase());
5118 if (Base.isInvalid())
5119 return SemaRef.ExprError();
5120 BaseType = ((Expr*) Base.get())->getType();
5121 } else {
5122 BaseType = getDerived().TransformType(Old->getBaseType());
5123 }
John McCall10eae182009-11-30 22:42:35 +00005124
5125 NestedNameSpecifier *Qualifier = 0;
5126 if (Old->getQualifier()) {
5127 Qualifier
5128 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
5129 Old->getQualifierRange());
5130 if (Qualifier == 0)
5131 return SemaRef.ExprError();
5132 }
5133
5134 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5135 Sema::LookupOrdinaryName);
5136
5137 // Transform all the decls.
5138 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5139 E = Old->decls_end(); I != E; ++I) {
5140 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005141 if (!InstD) {
5142 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5143 // This can happen because of dependent hiding.
5144 if (isa<UsingShadowDecl>(*I))
5145 continue;
5146 else
5147 return SemaRef.ExprError();
5148 }
John McCall10eae182009-11-30 22:42:35 +00005149
5150 // Expand using declarations.
5151 if (isa<UsingDecl>(InstD)) {
5152 UsingDecl *UD = cast<UsingDecl>(InstD);
5153 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5154 E = UD->shadow_end(); I != E; ++I)
5155 R.addDecl(*I);
5156 continue;
5157 }
5158
5159 R.addDecl(InstD);
5160 }
5161
5162 R.resolveKind();
5163
5164 TemplateArgumentListInfo TransArgs;
5165 if (Old->hasExplicitTemplateArgs()) {
5166 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5167 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5168 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5169 TemplateArgumentLoc Loc;
5170 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5171 Loc))
5172 return SemaRef.ExprError();
5173 TransArgs.addArgument(Loc);
5174 }
5175 }
John McCall38836f02010-01-15 08:34:02 +00005176
5177 // FIXME: to do this check properly, we will need to preserve the
5178 // first-qualifier-in-scope here, just in case we had a dependent
5179 // base (and therefore couldn't do the check) and a
5180 // nested-name-qualifier (and therefore could do the lookup).
5181 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005182
5183 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005184 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005185 Old->getOperatorLoc(),
5186 Old->isArrow(),
5187 Qualifier,
5188 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005189 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005190 R,
5191 (Old->hasExplicitTemplateArgs()
5192 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005193}
5194
5195template<typename Derived>
5196Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005197TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005198 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005199}
5200
Mike Stump11289f42009-09-09 15:08:12 +00005201template<typename Derived>
5202Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005204 // FIXME: poor source location
5205 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5206 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5207 if (EncodedType.isNull())
5208 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005209
Douglas Gregora16548e2009-08-11 05:31:07 +00005210 if (!getDerived().AlwaysRebuild() &&
5211 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005212 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005213
5214 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5215 EncodedType,
5216 E->getRParenLoc());
5217}
Mike Stump11289f42009-09-09 15:08:12 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219template<typename Derived>
5220Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005221TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005222 // FIXME: Implement this!
5223 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005224 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005225}
5226
Mike Stump11289f42009-09-09 15:08:12 +00005227template<typename Derived>
5228Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005230 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005231}
5232
Mike Stump11289f42009-09-09 15:08:12 +00005233template<typename Derived>
5234Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005235TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005236 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 = cast_or_null<ObjCProtocolDecl>(
5238 getDerived().TransformDecl(E->getProtocol()));
5239 if (!Protocol)
5240 return SemaRef.ExprError();
5241
5242 if (!getDerived().AlwaysRebuild() &&
5243 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005244 return SemaRef.Owned(E->Retain());
5245
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 return getDerived().RebuildObjCProtocolExpr(Protocol,
5247 E->getAtLoc(),
5248 /*FIXME:*/E->getAtLoc(),
5249 /*FIXME:*/E->getAtLoc(),
5250 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252}
5253
Mike Stump11289f42009-09-09 15:08:12 +00005254template<typename Derived>
5255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005256TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 // FIXME: Implement this!
5258 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005259 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005260}
5261
Mike Stump11289f42009-09-09 15:08:12 +00005262template<typename Derived>
5263Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005264TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 // FIXME: Implement this!
5266 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005267 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005268}
5269
Mike Stump11289f42009-09-09 15:08:12 +00005270template<typename Derived>
5271Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005272TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005273 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005274 // FIXME: Implement this!
5275 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005276 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005277}
5278
Mike Stump11289f42009-09-09 15:08:12 +00005279template<typename Derived>
5280Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005281TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 // FIXME: Implement this!
5283 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005284 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005285}
5286
Mike Stump11289f42009-09-09 15:08:12 +00005287template<typename Derived>
5288Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005289TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 // FIXME: Implement this!
5291 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005292 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293}
5294
Mike Stump11289f42009-09-09 15:08:12 +00005295template<typename Derived>
5296Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005297TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005298 bool ArgumentChanged = false;
5299 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5300 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5301 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5302 if (SubExpr.isInvalid())
5303 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005304
Douglas Gregora16548e2009-08-11 05:31:07 +00005305 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5306 SubExprs.push_back(SubExpr.takeAs<Expr>());
5307 }
Mike Stump11289f42009-09-09 15:08:12 +00005308
Douglas Gregora16548e2009-08-11 05:31:07 +00005309 if (!getDerived().AlwaysRebuild() &&
5310 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005311 return SemaRef.Owned(E->Retain());
5312
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5314 move_arg(SubExprs),
5315 E->getRParenLoc());
5316}
5317
Mike Stump11289f42009-09-09 15:08:12 +00005318template<typename Derived>
5319Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005320TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 // FIXME: Implement this!
5322 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005323 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005324}
5325
Mike Stump11289f42009-09-09 15:08:12 +00005326template<typename Derived>
5327Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005328TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005329 // FIXME: Implement this!
5330 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005331 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005332}
Mike Stump11289f42009-09-09 15:08:12 +00005333
Douglas Gregora16548e2009-08-11 05:31:07 +00005334//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335// Type reconstruction
5336//===----------------------------------------------------------------------===//
5337
Mike Stump11289f42009-09-09 15:08:12 +00005338template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005339QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5340 SourceLocation Star) {
5341 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005342 getDerived().getBaseEntity());
5343}
5344
Mike Stump11289f42009-09-09 15:08:12 +00005345template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005346QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5347 SourceLocation Star) {
5348 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005349 getDerived().getBaseEntity());
5350}
5351
Mike Stump11289f42009-09-09 15:08:12 +00005352template<typename Derived>
5353QualType
John McCall70dd5f62009-10-30 00:06:24 +00005354TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5355 bool WrittenAsLValue,
5356 SourceLocation Sigil) {
5357 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5358 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005359}
5360
5361template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005362QualType
John McCall70dd5f62009-10-30 00:06:24 +00005363TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5364 QualType ClassType,
5365 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005366 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005367 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005368}
5369
5370template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005371QualType
John McCall70dd5f62009-10-30 00:06:24 +00005372TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5373 SourceLocation Sigil) {
5374 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005375 getDerived().getBaseEntity());
5376}
5377
5378template<typename Derived>
5379QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005380TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5381 ArrayType::ArraySizeModifier SizeMod,
5382 const llvm::APInt *Size,
5383 Expr *SizeExpr,
5384 unsigned IndexTypeQuals,
5385 SourceRange BracketsRange) {
5386 if (SizeExpr || !Size)
5387 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5388 IndexTypeQuals, BracketsRange,
5389 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005390
5391 QualType Types[] = {
5392 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5393 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5394 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005395 };
5396 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5397 QualType SizeType;
5398 for (unsigned I = 0; I != NumTypes; ++I)
5399 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5400 SizeType = Types[I];
5401 break;
5402 }
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregord6ff3322009-08-04 16:50:30 +00005404 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005405 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005406 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005407 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005408}
Mike Stump11289f42009-09-09 15:08:12 +00005409
Douglas Gregord6ff3322009-08-04 16:50:30 +00005410template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005411QualType
5412TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005413 ArrayType::ArraySizeModifier SizeMod,
5414 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005415 unsigned IndexTypeQuals,
5416 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005417 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005418 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419}
5420
5421template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005422QualType
Mike Stump11289f42009-09-09 15:08:12 +00005423TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005424 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005425 unsigned IndexTypeQuals,
5426 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005427 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005428 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005429}
Mike Stump11289f42009-09-09 15:08:12 +00005430
Douglas Gregord6ff3322009-08-04 16:50:30 +00005431template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005432QualType
5433TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005436 unsigned IndexTypeQuals,
5437 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005438 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005439 SizeExpr.takeAs<Expr>(),
5440 IndexTypeQuals, BracketsRange);
5441}
5442
5443template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005444QualType
5445TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005446 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005448 unsigned IndexTypeQuals,
5449 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005450 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005451 SizeExpr.takeAs<Expr>(),
5452 IndexTypeQuals, BracketsRange);
5453}
5454
5455template<typename Derived>
5456QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005457 unsigned NumElements,
5458 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005459 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005460 return SemaRef.Context.getVectorType(ElementType, NumElements,
5461 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005462}
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregord6ff3322009-08-04 16:50:30 +00005464template<typename Derived>
5465QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5466 unsigned NumElements,
5467 SourceLocation AttributeLoc) {
5468 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5469 NumElements, true);
5470 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005471 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005472 AttributeLoc);
5473 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5474 AttributeLoc);
5475}
Mike Stump11289f42009-09-09 15:08:12 +00005476
Douglas Gregord6ff3322009-08-04 16:50:30 +00005477template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005478QualType
5479TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005480 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005481 SourceLocation AttributeLoc) {
5482 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5483}
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregord6ff3322009-08-04 16:50:30 +00005485template<typename Derived>
5486QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005487 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005488 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005489 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005490 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005491 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005492 Quals,
5493 getDerived().getBaseLocation(),
5494 getDerived().getBaseEntity());
5495}
Mike Stump11289f42009-09-09 15:08:12 +00005496
Douglas Gregord6ff3322009-08-04 16:50:30 +00005497template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005498QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5499 return SemaRef.Context.getFunctionNoProtoType(T);
5500}
5501
5502template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005503QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5504 assert(D && "no decl found");
5505 if (D->isInvalidDecl()) return QualType();
5506
5507 TypeDecl *Ty;
5508 if (isa<UsingDecl>(D)) {
5509 UsingDecl *Using = cast<UsingDecl>(D);
5510 assert(Using->isTypeName() &&
5511 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5512
5513 // A valid resolved using typename decl points to exactly one type decl.
5514 assert(++Using->shadow_begin() == Using->shadow_end());
5515 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5516
5517 } else {
5518 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5519 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5520 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5521 }
5522
5523 return SemaRef.Context.getTypeDeclType(Ty);
5524}
5525
5526template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005527QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005528 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5529}
5530
5531template<typename Derived>
5532QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5533 return SemaRef.Context.getTypeOfType(Underlying);
5534}
5535
5536template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005537QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005538 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5539}
5540
5541template<typename Derived>
5542QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005543 TemplateName Template,
5544 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005545 const TemplateArgumentListInfo &TemplateArgs) {
5546 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005547}
Mike Stump11289f42009-09-09 15:08:12 +00005548
Douglas Gregor1135c352009-08-06 05:28:30 +00005549template<typename Derived>
5550NestedNameSpecifier *
5551TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5552 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005553 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005554 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005555 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005556 CXXScopeSpec SS;
5557 // FIXME: The source location information is all wrong.
5558 SS.setRange(Range);
5559 SS.setScopeRep(Prefix);
5560 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005561 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005562 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005563 ObjectType,
5564 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005565 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005566}
5567
5568template<typename Derived>
5569NestedNameSpecifier *
5570TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5571 SourceRange Range,
5572 NamespaceDecl *NS) {
5573 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5574}
5575
5576template<typename Derived>
5577NestedNameSpecifier *
5578TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5579 SourceRange Range,
5580 bool TemplateKW,
5581 QualType T) {
5582 if (T->isDependentType() || T->isRecordType() ||
5583 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005584 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005585 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5586 T.getTypePtr());
5587 }
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregor1135c352009-08-06 05:28:30 +00005589 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5590 return 0;
5591}
Mike Stump11289f42009-09-09 15:08:12 +00005592
Douglas Gregor71dc5092009-08-06 06:41:21 +00005593template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005594TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005595TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5596 bool TemplateKW,
5597 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005598 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005599 Template);
5600}
5601
5602template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005603TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005604TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005605 const IdentifierInfo &II,
5606 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005607 CXXScopeSpec SS;
5608 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005609 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005610 UnqualifiedId Name;
5611 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005612 return getSema().ActOnDependentTemplateName(
5613 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005614 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005615 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005616 ObjectType.getAsOpaquePtr(),
5617 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005618 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005619}
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregora16548e2009-08-11 05:31:07 +00005621template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005622TemplateName
5623TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5624 OverloadedOperatorKind Operator,
5625 QualType ObjectType) {
5626 CXXScopeSpec SS;
5627 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5628 SS.setScopeRep(Qualifier);
5629 UnqualifiedId Name;
5630 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5631 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5632 Operator, SymbolLocations);
5633 return getSema().ActOnDependentTemplateName(
5634 /*FIXME:*/getDerived().getBaseLocation(),
5635 SS,
5636 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005637 ObjectType.getAsOpaquePtr(),
5638 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005639 .template getAsVal<TemplateName>();
5640}
5641
5642template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005643Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005644TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5645 SourceLocation OpLoc,
5646 ExprArg Callee,
5647 ExprArg First,
5648 ExprArg Second) {
5649 Expr *FirstExpr = (Expr *)First.get();
5650 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005651 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005652 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005655 if (Op == OO_Subscript) {
5656 if (!FirstExpr->getType()->isOverloadableType() &&
5657 !SecondExpr->getType()->isOverloadableType())
5658 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005659 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005660 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005661 } else if (Op == OO_Arrow) {
5662 // -> is never a builtin operation.
5663 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005664 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005665 if (!FirstExpr->getType()->isOverloadableType()) {
5666 // The argument is not of overloadable type, so try to create a
5667 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005668 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005669 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005670
Douglas Gregora16548e2009-08-11 05:31:07 +00005671 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5672 }
5673 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005674 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 !SecondExpr->getType()->isOverloadableType()) {
5676 // Neither of the arguments is an overloadable type, so try to
5677 // create a built-in binary operation.
5678 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005679 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5681 if (Result.isInvalid())
5682 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005683
Douglas Gregora16548e2009-08-11 05:31:07 +00005684 First.release();
5685 Second.release();
5686 return move(Result);
5687 }
5688 }
Mike Stump11289f42009-09-09 15:08:12 +00005689
5690 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005692 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005693
John McCalld14a8642009-11-21 08:51:07 +00005694 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5695 assert(ULE->requiresADL());
5696
5697 // FIXME: Do we have to check
5698 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005699 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005700 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005701 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005702 }
Mike Stump11289f42009-09-09 15:08:12 +00005703
Douglas Gregora16548e2009-08-11 05:31:07 +00005704 // Add any functions found via argument-dependent lookup.
5705 Expr *Args[2] = { FirstExpr, SecondExpr };
5706 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005707
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 // Create the overloaded operator invocation for unary operators.
5709 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005710 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5712 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5713 }
Mike Stump11289f42009-09-09 15:08:12 +00005714
Sebastian Redladba46e2009-10-29 20:17:01 +00005715 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005716 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5717 OpLoc,
5718 move(First),
5719 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005720
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005722 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005724 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5726 if (Result.isInvalid())
5727 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005728
Douglas Gregora16548e2009-08-11 05:31:07 +00005729 First.release();
5730 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005731 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005732}
Mike Stump11289f42009-09-09 15:08:12 +00005733
Douglas Gregord6ff3322009-08-04 16:50:30 +00005734} // end namespace clang
5735
5736#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H