blob: 419dd9c00f96ef912699ec377aad3d5678af4e28 [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.
194 QualType TransformType(QualType T);
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.
John McCallbcd03502009-12-07 02:54:59 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000205
206 /// \brief Transform the given type-with-location into a new
207 /// type, collecting location information in the given builder
208 /// as necessary.
209 ///
210 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000213 ///
Mike Stump11289f42009-09-09 15:08:12 +0000214 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000215 /// appropriate TransformXXXStmt function to transform a specific kind of
216 /// statement or the TransformExpr() function to transform an expression.
217 /// Subclasses may override this function to transform statements using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000221 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000223 /// \brief Transform the given expression.
224 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000225 /// By default, this routine transforms an expression by delegating to the
226 /// appropriate TransformXXXExpr function to build a new expression.
227 /// Subclasses may override this function to transform expressions using some
228 /// other mechanism.
229 ///
230 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000231 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000232
Douglas Gregord6ff3322009-08-04 16:50:30 +0000233 /// \brief Transform the given declaration, which is referenced from a type
234 /// or expression.
235 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000236 /// By default, acts as the identity function on declarations. Subclasses
237 /// may override this function to provide alternate behavior.
238 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000239
240 /// \brief Transform the definition of the given declaration.
241 ///
Mike Stump11289f42009-09-09 15:08:12 +0000242 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000243 /// Subclasses may override this function to provide alternate behavior.
244 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000245
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000246 /// \brief Transform the given declaration, which was the first part of a
247 /// nested-name-specifier in a member access expression.
248 ///
249 /// This specific declaration transformation only applies to the first
250 /// identifier in a nested-name-specifier of a member access expression, e.g.,
251 /// the \c T in \c x->T::member
252 ///
253 /// By default, invokes TransformDecl() to transform the declaration.
254 /// Subclasses may override this function to provide alternate behavior.
255 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
256 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
257 }
258
Douglas Gregord6ff3322009-08-04 16:50:30 +0000259 /// \brief Transform the given nested-name-specifier.
260 ///
Mike Stump11289f42009-09-09 15:08:12 +0000261 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000262 /// nested-name-specifier. Subclasses may override this function to provide
263 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000264 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000265 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000266 QualType ObjectType = QualType(),
267 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregorf816bd72009-09-03 22:13:48 +0000269 /// \brief Transform the given declaration name.
270 ///
271 /// By default, transforms the types of conversion function, constructor,
272 /// and destructor names and then (if needed) rebuilds the declaration name.
273 /// Identifiers and selectors are returned unmodified. Sublcasses may
274 /// override this function to provide alternate behavior.
275 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000276 SourceLocation Loc,
277 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000278
Douglas Gregord6ff3322009-08-04 16:50:30 +0000279 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000280 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000281 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000282 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000284 TemplateName TransformTemplateName(TemplateName Name,
285 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000286
Douglas Gregord6ff3322009-08-04 16:50:30 +0000287 /// \brief Transform the given template argument.
288 ///
Mike Stump11289f42009-09-09 15:08:12 +0000289 /// By default, this operation transforms the type, expression, or
290 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000291 /// new template argument from the transformed result. Subclasses may
292 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000293 ///
294 /// Returns true if there was an error.
295 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
296 TemplateArgumentLoc &Output);
297
298 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
299 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
300 TemplateArgumentLoc &ArgLoc);
301
John McCallbcd03502009-12-07 02:54:59 +0000302 /// \brief Fakes up a TypeSourceInfo for a type.
303 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
304 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000305 getDerived().getBaseLocation());
306 }
Mike Stump11289f42009-09-09 15:08:12 +0000307
John McCall550e0c22009-10-21 00:40:46 +0000308#define ABSTRACT_TYPELOC(CLASS, PARENT)
309#define TYPELOC(CLASS, PARENT) \
310 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
311#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000312
John McCall70dd5f62009-10-30 00:06:24 +0000313 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
314
Douglas Gregorc59e5612009-10-19 22:04:39 +0000315 QualType
316 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
317 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000318
319 QualType
320 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
321 TemplateSpecializationTypeLoc TL,
322 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000323
Douglas Gregorebe10102009-08-20 07:17:43 +0000324 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000325
Douglas Gregorebe10102009-08-20 07:17:43 +0000326#define STMT(Node, Parent) \
327 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000328#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000329 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000330#define ABSTRACT_EXPR(Node, Parent)
331#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000332
Douglas Gregord6ff3322009-08-04 16:50:30 +0000333 /// \brief Build a new pointer type given its pointee type.
334 ///
335 /// By default, performs semantic analysis when building the pointer type.
336 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000337 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000338
339 /// \brief Build a new block pointer type given its pointee type.
340 ///
Mike Stump11289f42009-09-09 15:08:12 +0000341 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000342 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000343 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000344
John McCall70dd5f62009-10-30 00:06:24 +0000345 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000346 ///
John McCall70dd5f62009-10-30 00:06:24 +0000347 /// By default, performs semantic analysis when building the
348 /// reference type. Subclasses may override this routine to provide
349 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 ///
John McCall70dd5f62009-10-30 00:06:24 +0000351 /// \param LValue whether the type was written with an lvalue sigil
352 /// or an rvalue sigil.
353 QualType RebuildReferenceType(QualType ReferentType,
354 bool LValue,
355 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000356
Douglas Gregord6ff3322009-08-04 16:50:30 +0000357 /// \brief Build a new member pointer type given the pointee type and the
358 /// class type it refers into.
359 ///
360 /// By default, performs semantic analysis when building the member pointer
361 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000362 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
363 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000364
John McCall550e0c22009-10-21 00:40:46 +0000365 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000366 QualType RebuildObjCObjectPointerType(QualType PointeeType,
367 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000368
Douglas Gregord6ff3322009-08-04 16:50:30 +0000369 /// \brief Build a new array type given the element type, size
370 /// modifier, size of the array (if known), size expression, and index type
371 /// qualifiers.
372 ///
373 /// By default, performs semantic analysis when building the array type.
374 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000375 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 QualType RebuildArrayType(QualType ElementType,
377 ArrayType::ArraySizeModifier SizeMod,
378 const llvm::APInt *Size,
379 Expr *SizeExpr,
380 unsigned IndexTypeQuals,
381 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000382
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 /// \brief Build a new constant array type given the element type, size
384 /// modifier, (known) size of the array, and index type qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 ArrayType::ArraySizeModifier SizeMod,
390 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394 /// \brief Build a new incomplete array type given the element type, size
395 /// modifier, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000401 unsigned IndexTypeQuals,
402 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000403
Mike Stump11289f42009-09-09 15:08:12 +0000404 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000405 /// size modifier, size expression, and index type qualifiers.
406 ///
407 /// By default, performs semantic analysis when building the array type.
408 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000409 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000410 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000411 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000412 unsigned IndexTypeQuals,
413 SourceRange BracketsRange);
414
Mike Stump11289f42009-09-09 15:08:12 +0000415 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416 /// size modifier, size expression, and index type qualifiers.
417 ///
418 /// By default, performs semantic analysis when building the array type.
419 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000420 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000421 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000422 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 unsigned IndexTypeQuals,
424 SourceRange BracketsRange);
425
426 /// \brief Build a new vector type given the element type and
427 /// number of elements.
428 ///
429 /// By default, performs semantic analysis when building the vector type.
430 /// Subclasses may override this routine to provide different behavior.
431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike 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) {
527 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000528 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000529 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000532 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533
534 /// \brief Build a new typename type that refers to an identifier.
535 ///
536 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000537 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000539 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000540 const IdentifierInfo *Id,
541 SourceRange SR) {
542 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Douglas Gregor1135c352009-08-06 05:28:30 +0000545 /// \brief Build a new nested-name-specifier given the prefix and an
546 /// identifier that names the next step in the nested-name-specifier.
547 ///
548 /// By default, performs semantic analysis when building the new
549 /// nested-name-specifier. Subclasses may override this routine to provide
550 /// different behavior.
551 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
552 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000553 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000554 QualType ObjectType,
555 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// namespace named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 NamespaceDecl *NS);
566
567 /// \brief Build a new nested-name-specifier given the prefix and the
568 /// type named in the next step in the nested-name-specifier.
569 ///
570 /// By default, performs semantic analysis when building the new
571 /// nested-name-specifier. Subclasses may override this routine to provide
572 /// different behavior.
573 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
574 SourceRange Range,
575 bool TemplateKW,
576 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000577
578 /// \brief Build a new template name given a nested name specifier, a flag
579 /// indicating whether the "template" keyword was provided, and the template
580 /// that the template name refers to.
581 ///
582 /// By default, builds the new template name directly. Subclasses may override
583 /// this routine to provide different behavior.
584 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
585 bool TemplateKW,
586 TemplateDecl *Template);
587
Douglas Gregor71dc5092009-08-06 06:41:21 +0000588 /// \brief Build a new template name given a nested name specifier and the
589 /// name that is referred to as a template.
590 ///
591 /// By default, performs semantic analysis to determine whether the name can
592 /// be resolved to a specific template, then builds the appropriate kind of
593 /// template name. Subclasses may override this routine to provide different
594 /// behavior.
595 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000596 const IdentifierInfo &II,
597 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000598
Douglas Gregor71395fa2009-11-04 00:56:37 +0000599 /// \brief Build a new template name given a nested name specifier and the
600 /// overloaded operator name that is referred to as a template.
601 ///
602 /// By default, performs semantic analysis to determine whether the name can
603 /// be resolved to a specific template, then builds the appropriate kind of
604 /// template name. Subclasses may override this routine to provide different
605 /// behavior.
606 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
607 OverloadedOperatorKind Operator,
608 QualType ObjectType);
609
Douglas Gregorebe10102009-08-20 07:17:43 +0000610 /// \brief Build a new compound statement.
611 ///
612 /// By default, performs semantic analysis to build the new statement.
613 /// Subclasses may override this routine to provide different behavior.
614 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
615 MultiStmtArg Statements,
616 SourceLocation RBraceLoc,
617 bool IsStmtExpr) {
618 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
619 IsStmtExpr);
620 }
621
622 /// \brief Build a new case statement.
623 ///
624 /// By default, performs semantic analysis to build the new statement.
625 /// Subclasses may override this routine to provide different behavior.
626 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
627 ExprArg LHS,
628 SourceLocation EllipsisLoc,
629 ExprArg RHS,
630 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000631 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000632 ColonLoc);
633 }
Mike Stump11289f42009-09-09 15:08:12 +0000634
Douglas Gregorebe10102009-08-20 07:17:43 +0000635 /// \brief Attach the body to a new case statement.
636 ///
637 /// By default, performs semantic analysis to build the new statement.
638 /// Subclasses may override this routine to provide different behavior.
639 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
640 getSema().ActOnCaseStmtBody(S.get(), move(Body));
641 return move(S);
642 }
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregorebe10102009-08-20 07:17:43 +0000644 /// \brief Build a new default statement.
645 ///
646 /// By default, performs semantic analysis to build the new statement.
647 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000648 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000649 SourceLocation ColonLoc,
650 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000651 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000652 /*CurScope=*/0);
653 }
Mike Stump11289f42009-09-09 15:08:12 +0000654
Douglas Gregorebe10102009-08-20 07:17:43 +0000655 /// \brief Build a new label statement.
656 ///
657 /// By default, performs semantic analysis to build the new statement.
658 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000659 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000660 IdentifierInfo *Id,
661 SourceLocation ColonLoc,
662 StmtArg SubStmt) {
663 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
664 }
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregorebe10102009-08-20 07:17:43 +0000666 /// \brief Build a new "if" statement.
667 ///
668 /// By default, performs semantic analysis to build the new statement.
669 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000670 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000671 VarDecl *CondVar, StmtArg Then,
672 SourceLocation ElseLoc, StmtArg Else) {
673 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
674 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000675 }
Mike Stump11289f42009-09-09 15:08:12 +0000676
Douglas Gregorebe10102009-08-20 07:17:43 +0000677 /// \brief Start building a new switch statement.
678 ///
679 /// By default, performs semantic analysis to build the new statement.
680 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000681 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
682 VarDecl *CondVar) {
683 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 }
Mike Stump11289f42009-09-09 15:08:12 +0000685
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 /// \brief Attach the body to the switch statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000690 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 StmtArg Switch, StmtArg Body) {
692 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
693 move(Body));
694 }
695
696 /// \brief Build a new while statement.
697 ///
698 /// By default, performs semantic analysis to build the new statement.
699 /// Subclasses may override this routine to provide different behavior.
700 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
701 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000702 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000703 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000704 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
705 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 }
Mike Stump11289f42009-09-09 15:08:12 +0000707
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 /// \brief Build a new do-while statement.
709 ///
710 /// By default, performs semantic analysis to build the new statement.
711 /// Subclasses may override this routine to provide different behavior.
712 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
713 SourceLocation WhileLoc,
714 SourceLocation LParenLoc,
715 ExprArg Cond,
716 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000717 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000718 move(Cond), RParenLoc);
719 }
720
721 /// \brief Build a new for statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000725 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000727 StmtArg Init, Sema::FullExprArg Cond,
728 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000730 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
731 DeclPtrTy::make(CondVar),
732 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
740 SourceLocation LabelLoc,
741 LabelStmt *Label) {
742 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
743 }
744
745 /// \brief Build a new indirect goto statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
750 SourceLocation StarLoc,
751 ExprArg Target) {
752 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new return statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
760 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Build a new declaration statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
769 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000770 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 SourceLocation EndLoc) {
772 return getSema().Owned(
773 new (getSema().Context) DeclStmt(
774 DeclGroupRef::Create(getSema().Context,
775 Decls, NumDecls),
776 StartLoc, EndLoc));
777 }
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 /// \brief Build a new C++ exception declaration.
780 ///
781 /// By default, performs semantic analysis to build the new decaration.
782 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000783 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000784 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 IdentifierInfo *Name,
786 SourceLocation Loc,
787 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000788 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 TypeRange);
790 }
791
792 /// \brief Build a new C++ catch statement.
793 ///
794 /// By default, performs semantic analysis to build the new statement.
795 /// Subclasses may override this routine to provide different behavior.
796 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
797 VarDecl *ExceptionDecl,
798 StmtArg Handler) {
799 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000800 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 Handler.takeAs<Stmt>()));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 /// \brief Build a new C++ try statement.
805 ///
806 /// By default, performs semantic analysis to build the new statement.
807 /// Subclasses may override this routine to provide different behavior.
808 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
809 StmtArg TryBlock,
810 MultiStmtArg Handlers) {
811 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregora16548e2009-08-11 05:31:07 +0000814 /// \brief Build a new expression that references a declaration.
815 ///
816 /// By default, performs semantic analysis to build the new expression.
817 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000818 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
819 LookupResult &R,
820 bool RequiresADL) {
821 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
822 }
823
824
825 /// \brief Build a new expression that references a declaration.
826 ///
827 /// By default, performs semantic analysis to build the new expression.
828 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000829 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
830 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000831 ValueDecl *VD, SourceLocation Loc,
832 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000833 CXXScopeSpec SS;
834 SS.setScopeRep(Qualifier);
835 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000836
837 // FIXME: loses template args.
838
839 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 }
Mike Stump11289f42009-09-09 15:08:12 +0000841
Douglas Gregora16548e2009-08-11 05:31:07 +0000842 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000843 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
847 SourceLocation RParen) {
848 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
849 }
850
Douglas Gregorad8a3362009-09-04 17:36:40 +0000851 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000852 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
855 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
856 SourceLocation OperatorLoc,
857 bool isArrow,
858 SourceLocation DestroyedTypeLoc,
859 QualType DestroyedType,
860 NestedNameSpecifier *Qualifier,
861 SourceRange QualifierRange) {
862 CXXScopeSpec SS;
863 if (Qualifier) {
864 SS.setRange(QualifierRange);
865 SS.setScopeRep(Qualifier);
866 }
867
John McCall2d74de92009-12-01 22:10:20 +0000868 QualType BaseType = ((Expr*) Base.get())->getType();
869
Mike Stump11289f42009-09-09 15:08:12 +0000870 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000871 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
872 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000873
John McCall2d74de92009-12-01 22:10:20 +0000874 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
875 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000876 SS, /*FIXME: FirstQualifier*/ 0,
877 Name, DestroyedTypeLoc,
878 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000879 }
880
Douglas Gregora16548e2009-08-11 05:31:07 +0000881 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
885 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
886 UnaryOperator::Opcode Opc,
887 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000888 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 }
Mike Stump11289f42009-09-09 15:08:12 +0000890
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000895 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000896 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000897 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000898 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 }
900
Mike Stump11289f42009-09-09 15:08:12 +0000901 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000902 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000903 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 /// By default, performs semantic analysis to build the new expression.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
907 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000908 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
910 OpLoc, isSizeOf, R);
911 if (Result.isInvalid())
912 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000913
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 SubExpr.release();
915 return move(Result);
916 }
Mike Stump11289f42009-09-09 15:08:12 +0000917
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000919 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// By default, performs semantic analysis to build the new expression.
921 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000922 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 SourceLocation LBracketLoc,
924 ExprArg RHS,
925 SourceLocation RBracketLoc) {
926 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000927 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 RBracketLoc);
929 }
930
931 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000932 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000933 /// By default, performs semantic analysis to build the new expression.
934 /// Subclasses may override this routine to provide different behavior.
935 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
936 MultiExprArg Args,
937 SourceLocation *CommaLocs,
938 SourceLocation RParenLoc) {
939 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
940 move(Args), CommaLocs, RParenLoc);
941 }
942
943 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000944 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000945 /// By default, performs semantic analysis to build the new expression.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000948 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000949 NestedNameSpecifier *Qualifier,
950 SourceRange QualifierRange,
951 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000952 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000953 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000954 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000955 if (!Member->getDeclName()) {
956 // We have a reference to an unnamed field.
957 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000958
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000959 Expr *BaseExpr = Base.takeAs<Expr>();
960 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
961 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000962
Mike Stump11289f42009-09-09 15:08:12 +0000963 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000964 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000965 Member, MemberLoc,
966 cast<FieldDecl>(Member)->getType());
967 return getSema().Owned(ME);
968 }
Mike Stump11289f42009-09-09 15:08:12 +0000969
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000970 CXXScopeSpec SS;
971 if (Qualifier) {
972 SS.setRange(QualifierRange);
973 SS.setScopeRep(Qualifier);
974 }
975
John McCall2d74de92009-12-01 22:10:20 +0000976 QualType BaseType = ((Expr*) Base.get())->getType();
977
978 // FIXME: wait, this is re-performing lookup?
979 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
980 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000981 SS, FirstQualifierInScope,
982 Member->getDeclName(), MemberLoc,
983 ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000984 }
Mike Stump11289f42009-09-09 15:08:12 +0000985
Douglas Gregora16548e2009-08-11 05:31:07 +0000986 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000987 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000988 /// By default, performs semantic analysis to build the new expression.
989 /// Subclasses may override this routine to provide different behavior.
990 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
991 BinaryOperator::Opcode Opc,
992 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000993 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
994 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000995 }
996
997 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000998 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 /// By default, performs semantic analysis to build the new expression.
1000 /// Subclasses may override this routine to provide different behavior.
1001 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1002 SourceLocation QuestionLoc,
1003 ExprArg LHS,
1004 SourceLocation ColonLoc,
1005 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001006 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001007 move(LHS), move(RHS));
1008 }
1009
Douglas Gregora16548e2009-08-11 05:31:07 +00001010 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
1014 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1015 QualType ExplicitTy,
1016 SourceLocation RParenLoc,
1017 ExprArg SubExpr) {
1018 return getSema().ActOnCastExpr(/*Scope=*/0,
1019 LParenLoc,
1020 ExplicitTy.getAsOpaquePtr(),
1021 RParenLoc,
1022 move(SubExpr));
1023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1030 QualType T,
1031 SourceLocation RParenLoc,
1032 ExprArg Init) {
1033 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1034 RParenLoc, move(Init));
1035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001041 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 SourceLocation OpLoc,
1043 SourceLocation AccessorLoc,
1044 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001045
John McCall10eae182009-11-30 22:42:35 +00001046 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001047 QualType BaseType = ((Expr*) Base.get())->getType();
1048 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001049 OpLoc, /*IsArrow*/ false,
1050 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001051 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001052 AccessorLoc,
1053 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001057 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 /// By default, performs semantic analysis to build the new expression.
1059 /// Subclasses may override this routine to provide different behavior.
1060 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1061 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001062 SourceLocation RBraceLoc,
1063 QualType ResultTy) {
1064 OwningExprResult Result
1065 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1066 if (Result.isInvalid() || ResultTy->isDependentType())
1067 return move(Result);
1068
1069 // Patch in the result type we were given, which may have been computed
1070 // when the initial InitListExpr was built.
1071 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1072 ILE->setType(ResultTy);
1073 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001074 }
Mike Stump11289f42009-09-09 15:08:12 +00001075
Douglas Gregora16548e2009-08-11 05:31:07 +00001076 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001077 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001078 /// By default, performs semantic analysis to build the new expression.
1079 /// Subclasses may override this routine to provide different behavior.
1080 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1081 MultiExprArg ArrayExprs,
1082 SourceLocation EqualOrColonLoc,
1083 bool GNUSyntax,
1084 ExprArg Init) {
1085 OwningExprResult Result
1086 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1087 move(Init));
1088 if (Result.isInvalid())
1089 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregora16548e2009-08-11 05:31:07 +00001091 ArrayExprs.release();
1092 return move(Result);
1093 }
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregora16548e2009-08-11 05:31:07 +00001095 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001096 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001097 /// By default, builds the implicit value initialization without performing
1098 /// any semantic analysis. Subclasses may override this routine to provide
1099 /// different behavior.
1100 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1101 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1102 }
Mike Stump11289f42009-09-09 15:08:12 +00001103
Douglas Gregora16548e2009-08-11 05:31:07 +00001104 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001105 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 /// By default, performs semantic analysis to build the new expression.
1107 /// Subclasses may override this routine to provide different behavior.
1108 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1109 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001110 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 RParenLoc);
1112 }
1113
1114 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// By default, performs semantic analysis to build the new expression.
1117 /// Subclasses may override this routine to provide different behavior.
1118 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1119 MultiExprArg SubExprs,
1120 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001121 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1122 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001123 }
Mike Stump11289f42009-09-09 15:08:12 +00001124
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001126 ///
1127 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// rather than attempting to map the label statement itself.
1129 /// Subclasses may override this routine to provide different behavior.
1130 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1131 SourceLocation LabelLoc,
1132 LabelStmt *Label) {
1133 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1141 StmtArg SubStmt,
1142 SourceLocation RParenLoc) {
1143 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 /// \brief Build a new __builtin_types_compatible_p expression.
1147 ///
1148 /// By default, performs semantic analysis to build the new expression.
1149 /// Subclasses may override this routine to provide different behavior.
1150 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1151 QualType T1, QualType T2,
1152 SourceLocation RParenLoc) {
1153 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1154 T1.getAsOpaquePtr(),
1155 T2.getAsOpaquePtr(),
1156 RParenLoc);
1157 }
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregora16548e2009-08-11 05:31:07 +00001159 /// \brief Build a new __builtin_choose_expr expression.
1160 ///
1161 /// By default, performs semantic analysis to build the new expression.
1162 /// Subclasses may override this routine to provide different behavior.
1163 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1164 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1165 SourceLocation RParenLoc) {
1166 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1167 move(Cond), move(LHS), move(RHS),
1168 RParenLoc);
1169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// \brief Build a new overloaded operator call expression.
1172 ///
1173 /// By default, performs semantic analysis to build the new expression.
1174 /// The semantic analysis provides the behavior of template instantiation,
1175 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001176 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001177 /// argument-dependent lookup, etc. Subclasses may override this routine to
1178 /// provide different behavior.
1179 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1180 SourceLocation OpLoc,
1181 ExprArg Callee,
1182 ExprArg First,
1183 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001184
1185 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// reinterpret_cast.
1187 ///
1188 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001189 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001190 /// Subclasses may override this routine to provide different behavior.
1191 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1192 Stmt::StmtClass Class,
1193 SourceLocation LAngleLoc,
1194 QualType T,
1195 SourceLocation RAngleLoc,
1196 SourceLocation LParenLoc,
1197 ExprArg SubExpr,
1198 SourceLocation RParenLoc) {
1199 switch (Class) {
1200 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001201 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1202 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 move(SubExpr), RParenLoc);
1204
1205 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001206 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1207 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001211 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1212 RAngleLoc, LParenLoc,
1213 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001214 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001215
Douglas Gregora16548e2009-08-11 05:31:07 +00001216 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001217 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1218 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 default:
1222 assert(false && "Invalid C++ named cast");
1223 break;
1224 }
Mike Stump11289f42009-09-09 15:08:12 +00001225
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 return getSema().ExprError();
1227 }
Mike Stump11289f42009-09-09 15:08:12 +00001228
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 /// \brief Build a new C++ static_cast expression.
1230 ///
1231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
1233 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1234 SourceLocation LAngleLoc,
1235 QualType T,
1236 SourceLocation RAngleLoc,
1237 SourceLocation LParenLoc,
1238 ExprArg SubExpr,
1239 SourceLocation RParenLoc) {
1240 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001241 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 LParenLoc, move(SubExpr), RParenLoc);
1243 }
1244
1245 /// \brief Build a new C++ dynamic_cast expression.
1246 ///
1247 /// By default, performs semantic analysis to build the new expression.
1248 /// Subclasses may override this routine to provide different behavior.
1249 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1250 SourceLocation LAngleLoc,
1251 QualType T,
1252 SourceLocation RAngleLoc,
1253 SourceLocation LParenLoc,
1254 ExprArg SubExpr,
1255 SourceLocation RParenLoc) {
1256 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001257 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 LParenLoc, move(SubExpr), RParenLoc);
1259 }
1260
1261 /// \brief Build a new C++ reinterpret_cast expression.
1262 ///
1263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
1265 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1266 SourceLocation LAngleLoc,
1267 QualType T,
1268 SourceLocation RAngleLoc,
1269 SourceLocation LParenLoc,
1270 ExprArg SubExpr,
1271 SourceLocation RParenLoc) {
1272 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1273 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1274 LParenLoc, move(SubExpr), RParenLoc);
1275 }
1276
1277 /// \brief Build a new C++ const_cast expression.
1278 ///
1279 /// By default, performs semantic analysis to build the new expression.
1280 /// Subclasses may override this routine to provide different behavior.
1281 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1282 SourceLocation LAngleLoc,
1283 QualType T,
1284 SourceLocation RAngleLoc,
1285 SourceLocation LParenLoc,
1286 ExprArg SubExpr,
1287 SourceLocation RParenLoc) {
1288 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001289 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 LParenLoc, move(SubExpr), RParenLoc);
1291 }
Mike Stump11289f42009-09-09 15:08:12 +00001292
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 /// \brief Build a new C++ functional-style cast expression.
1294 ///
1295 /// By default, performs semantic analysis to build the new expression.
1296 /// Subclasses may override this routine to provide different behavior.
1297 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1298 QualType T,
1299 SourceLocation LParenLoc,
1300 ExprArg SubExpr,
1301 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001302 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1304 T.getAsOpaquePtr(),
1305 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001306 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001307 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001308 RParenLoc);
1309 }
Mike Stump11289f42009-09-09 15:08:12 +00001310
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// \brief Build a new C++ typeid(type) expression.
1312 ///
1313 /// By default, performs semantic analysis to build the new expression.
1314 /// Subclasses may override this routine to provide different behavior.
1315 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1316 SourceLocation LParenLoc,
1317 QualType T,
1318 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001319 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 T.getAsOpaquePtr(), RParenLoc);
1321 }
Mike Stump11289f42009-09-09 15:08:12 +00001322
Douglas Gregora16548e2009-08-11 05:31:07 +00001323 /// \brief Build a new C++ typeid(expr) 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 RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1328 SourceLocation LParenLoc,
1329 ExprArg Operand,
1330 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001331 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1333 RParenLoc);
1334 if (Result.isInvalid())
1335 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1338 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001339 }
1340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new C++ "this" expression.
1342 ///
1343 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001344 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001346 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001347 QualType ThisType,
1348 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001350 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1351 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001352 }
1353
1354 /// \brief Build a new C++ throw expression.
1355 ///
1356 /// By default, performs semantic analysis to build the new expression.
1357 /// Subclasses may override this routine to provide different behavior.
1358 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1359 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1360 }
1361
1362 /// \brief Build a new C++ default-argument expression.
1363 ///
1364 /// By default, builds a new default-argument expression, which does not
1365 /// require any semantic analysis. Subclasses may override this routine to
1366 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001367 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1368 ParmVarDecl *Param) {
1369 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1370 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001371 }
1372
1373 /// \brief Build a new C++ zero-initialization expression.
1374 ///
1375 /// By default, performs semantic analysis to build the new expression.
1376 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001377 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 SourceLocation LParenLoc,
1379 QualType T,
1380 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001381 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1382 T.getAsOpaquePtr(), LParenLoc,
1383 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 0, RParenLoc);
1385 }
Mike Stump11289f42009-09-09 15:08:12 +00001386
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 /// \brief Build a new C++ "new" expression.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001391 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 bool UseGlobal,
1393 SourceLocation PlacementLParen,
1394 MultiExprArg PlacementArgs,
1395 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001396 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 QualType AllocType,
1398 SourceLocation TypeLoc,
1399 SourceRange TypeRange,
1400 ExprArg ArraySize,
1401 SourceLocation ConstructorLParen,
1402 MultiExprArg ConstructorArgs,
1403 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001404 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 PlacementLParen,
1406 move(PlacementArgs),
1407 PlacementRParen,
1408 ParenTypeId,
1409 AllocType,
1410 TypeLoc,
1411 TypeRange,
1412 move(ArraySize),
1413 ConstructorLParen,
1414 move(ConstructorArgs),
1415 ConstructorRParen);
1416 }
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// \brief Build a new C++ "delete" expression.
1419 ///
1420 /// By default, performs semantic analysis to build the new expression.
1421 /// Subclasses may override this routine to provide different behavior.
1422 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1423 bool IsGlobalDelete,
1424 bool IsArrayForm,
1425 ExprArg Operand) {
1426 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1427 move(Operand));
1428 }
Mike Stump11289f42009-09-09 15:08:12 +00001429
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// \brief Build a new unary type trait expression.
1431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1435 SourceLocation StartLoc,
1436 SourceLocation LParenLoc,
1437 QualType T,
1438 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001439 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001440 T.getAsOpaquePtr(), RParenLoc);
1441 }
1442
Mike Stump11289f42009-09-09 15:08:12 +00001443 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001448 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 SourceRange QualifierRange,
1450 DeclarationName Name,
1451 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001452 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001453 CXXScopeSpec SS;
1454 SS.setRange(QualifierRange);
1455 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001456
1457 if (TemplateArgs)
1458 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1459 *TemplateArgs);
1460
1461 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
1463
1464 /// \brief Build a new template-id expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001468 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1469 LookupResult &R,
1470 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001471 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001472 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 }
1474
1475 /// \brief Build a new object-construction expression.
1476 ///
1477 /// By default, performs semantic analysis to build the new expression.
1478 /// Subclasses may override this routine to provide different behavior.
1479 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001480 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 CXXConstructorDecl *Constructor,
1482 bool IsElidable,
1483 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001484 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1485 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1486 ConvertedArgs))
1487 return getSema().ExprError();
1488
1489 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1490 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 }
1492
1493 /// \brief Build a new object-construction expression.
1494 ///
1495 /// By default, performs semantic analysis to build the new expression.
1496 /// Subclasses may override this routine to provide different behavior.
1497 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1498 QualType T,
1499 SourceLocation LParenLoc,
1500 MultiExprArg Args,
1501 SourceLocation *Commas,
1502 SourceLocation RParenLoc) {
1503 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1504 T.getAsOpaquePtr(),
1505 LParenLoc,
1506 move(Args),
1507 Commas,
1508 RParenLoc);
1509 }
1510
1511 /// \brief Build a new object-construction expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
1515 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1516 QualType T,
1517 SourceLocation LParenLoc,
1518 MultiExprArg Args,
1519 SourceLocation *Commas,
1520 SourceLocation RParenLoc) {
1521 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1522 /*FIXME*/LParenLoc),
1523 T.getAsOpaquePtr(),
1524 LParenLoc,
1525 move(Args),
1526 Commas,
1527 RParenLoc);
1528 }
Mike Stump11289f42009-09-09 15:08:12 +00001529
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 /// \brief Build a new member reference expression.
1531 ///
1532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001534 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001535 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 bool IsArrow,
1537 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001538 NestedNameSpecifier *Qualifier,
1539 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001540 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001542 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001543 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001545 SS.setRange(QualifierRange);
1546 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001547
John McCall2d74de92009-12-01 22:10:20 +00001548 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1549 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001550 SS, FirstQualifierInScope,
1551 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 }
1553
John McCall10eae182009-11-30 22:42:35 +00001554 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001555 ///
1556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001558 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001559 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001560 SourceLocation OperatorLoc,
1561 bool IsArrow,
1562 NestedNameSpecifier *Qualifier,
1563 SourceRange QualifierRange,
1564 LookupResult &R,
1565 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001566 CXXScopeSpec SS;
1567 SS.setRange(QualifierRange);
1568 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001569
John McCall2d74de92009-12-01 22:10:20 +00001570 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1571 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001572 SS, R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001573 }
Mike Stump11289f42009-09-09 15:08:12 +00001574
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 /// \brief Build a new Objective-C @encode expression.
1576 ///
1577 /// By default, performs semantic analysis to build the new expression.
1578 /// Subclasses may override this routine to provide different behavior.
1579 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1580 QualType T,
1581 SourceLocation RParenLoc) {
1582 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1583 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001584 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001585
1586 /// \brief Build a new Objective-C protocol expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
1590 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1591 SourceLocation AtLoc,
1592 SourceLocation ProtoLoc,
1593 SourceLocation LParenLoc,
1594 SourceLocation RParenLoc) {
1595 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1596 Protocol->getIdentifier(),
1597 AtLoc,
1598 ProtoLoc,
1599 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001600 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 }
Mike Stump11289f42009-09-09 15:08:12 +00001602
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 /// \brief Build a new shuffle vector expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
1607 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1608 MultiExprArg SubExprs,
1609 SourceLocation RParenLoc) {
1610 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001611 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1613 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1614 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1615 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001616
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 // Build a reference to the __builtin_shufflevector builtin
1618 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001619 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001621 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001623
1624 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 unsigned NumSubExprs = SubExprs.size();
1626 Expr **Subs = (Expr **)SubExprs.release();
1627 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1628 Subs, NumSubExprs,
1629 Builtin->getResultType(),
1630 RParenLoc);
1631 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 // Type-check the __builtin_shufflevector expression.
1634 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1635 if (Result.isInvalid())
1636 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001639 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001641};
Douglas Gregora16548e2009-08-11 05:31:07 +00001642
Douglas Gregorebe10102009-08-20 07:17:43 +00001643template<typename Derived>
1644Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1645 if (!S)
1646 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregorebe10102009-08-20 07:17:43 +00001648 switch (S->getStmtClass()) {
1649 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001650
Douglas Gregorebe10102009-08-20 07:17:43 +00001651 // Transform individual statement nodes
1652#define STMT(Node, Parent) \
1653 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1654#define EXPR(Node, Parent)
1655#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregorebe10102009-08-20 07:17:43 +00001657 // Transform expressions by calling TransformExpr.
1658#define STMT(Node, Parent)
1659#define EXPR(Node, Parent) case Stmt::Node##Class:
1660#include "clang/AST/StmtNodes.def"
1661 {
1662 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1663 if (E.isInvalid())
1664 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001665
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001666 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001667 }
Mike Stump11289f42009-09-09 15:08:12 +00001668 }
1669
Douglas Gregorebe10102009-08-20 07:17:43 +00001670 return SemaRef.Owned(S->Retain());
1671}
Mike Stump11289f42009-09-09 15:08:12 +00001672
1673
Douglas Gregore922c772009-08-04 22:27:00 +00001674template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001675Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 if (!E)
1677 return SemaRef.Owned(E);
1678
1679 switch (E->getStmtClass()) {
1680 case Stmt::NoStmtClass: break;
1681#define STMT(Node, Parent) case Stmt::Node##Class: break;
1682#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001683 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001684#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001685 }
1686
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001688}
1689
1690template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001691NestedNameSpecifier *
1692TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001693 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001694 QualType ObjectType,
1695 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001696 if (!NNS)
1697 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001698
Douglas Gregorebe10102009-08-20 07:17:43 +00001699 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001700 NestedNameSpecifier *Prefix = NNS->getPrefix();
1701 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001702 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001703 ObjectType,
1704 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001705 if (!Prefix)
1706 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001707
1708 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001709 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001710 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001711 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001712 }
Mike Stump11289f42009-09-09 15:08:12 +00001713
Douglas Gregor1135c352009-08-06 05:28:30 +00001714 switch (NNS->getKind()) {
1715 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001716 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001717 "Identifier nested-name-specifier with no prefix or object type");
1718 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1719 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001720 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001721
1722 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001723 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001724 ObjectType,
1725 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001726
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001728 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001729 = cast_or_null<NamespaceDecl>(
1730 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001731 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 Prefix == NNS->getPrefix() &&
1733 NS == NNS->getAsNamespace())
1734 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001735
Douglas Gregor1135c352009-08-06 05:28:30 +00001736 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1737 }
Mike Stump11289f42009-09-09 15:08:12 +00001738
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 case NestedNameSpecifier::Global:
1740 // There is no meaningful transformation that one could perform on the
1741 // global scope.
1742 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001743
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 case NestedNameSpecifier::TypeSpecWithTemplate:
1745 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001746 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001748 if (T.isNull())
1749 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001750
Douglas Gregor1135c352009-08-06 05:28:30 +00001751 if (!getDerived().AlwaysRebuild() &&
1752 Prefix == NNS->getPrefix() &&
1753 T == QualType(NNS->getAsType(), 0))
1754 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001755
1756 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1757 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001758 T);
1759 }
1760 }
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregor1135c352009-08-06 05:28:30 +00001762 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001763 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001764}
1765
1766template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001767DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001768TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001769 SourceLocation Loc,
1770 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001771 if (!Name)
1772 return Name;
1773
1774 switch (Name.getNameKind()) {
1775 case DeclarationName::Identifier:
1776 case DeclarationName::ObjCZeroArgSelector:
1777 case DeclarationName::ObjCOneArgSelector:
1778 case DeclarationName::ObjCMultiArgSelector:
1779 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001780 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001781 case DeclarationName::CXXUsingDirective:
1782 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregorf816bd72009-09-03 22:13:48 +00001784 case DeclarationName::CXXConstructorName:
1785 case DeclarationName::CXXDestructorName:
1786 case DeclarationName::CXXConversionFunctionName: {
1787 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001788 QualType T;
1789 if (!ObjectType.isNull() &&
1790 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1791 TemplateSpecializationType *SpecType
1792 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1793 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1794 } else
1795 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001796 if (T.isNull())
1797 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001798
Douglas Gregorf816bd72009-09-03 22:13:48 +00001799 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001800 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001801 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001802 }
Mike Stump11289f42009-09-09 15:08:12 +00001803 }
1804
Douglas Gregorf816bd72009-09-03 22:13:48 +00001805 return DeclarationName();
1806}
1807
1808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001809TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001810TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1811 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001812 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001813 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001814 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1815 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1816 if (!NNS)
1817 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001818
Douglas Gregor71dc5092009-08-06 06:41:21 +00001819 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001820 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001821 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1822 if (!TransTemplate)
1823 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregor71dc5092009-08-06 06:41:21 +00001825 if (!getDerived().AlwaysRebuild() &&
1826 NNS == QTN->getQualifier() &&
1827 TransTemplate == Template)
1828 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001829
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1831 TransTemplate);
1832 }
Mike Stump11289f42009-09-09 15:08:12 +00001833
John McCalle66edc12009-11-24 19:00:30 +00001834 // These should be getting filtered out before they make it into the AST.
1835 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001836 }
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregor71dc5092009-08-06 06:41:21 +00001838 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001839 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1841 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001842 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001843 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregor71dc5092009-08-06 06:41:21 +00001845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001846 NNS == DTN->getQualifier() &&
1847 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregor71395fa2009-11-04 00:56:37 +00001850 if (DTN->isIdentifier())
1851 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1852 ObjectType);
1853
1854 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1855 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 }
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001859 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1861 if (!TransTemplate)
1862 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 if (!getDerived().AlwaysRebuild() &&
1865 TransTemplate == Template)
1866 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 return TemplateName(TransTemplate);
1869 }
Mike Stump11289f42009-09-09 15:08:12 +00001870
John McCalle66edc12009-11-24 19:00:30 +00001871 // These should be getting filtered out before they reach the AST.
1872 assert(false && "overloaded function decl survived to here");
1873 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874}
1875
1876template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001877void TreeTransform<Derived>::InventTemplateArgumentLoc(
1878 const TemplateArgument &Arg,
1879 TemplateArgumentLoc &Output) {
1880 SourceLocation Loc = getDerived().getBaseLocation();
1881 switch (Arg.getKind()) {
1882 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001883 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001884 break;
1885
1886 case TemplateArgument::Type:
1887 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001888 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001889
1890 break;
1891
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001892 case TemplateArgument::Template:
1893 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1894 break;
1895
John McCall0ad16662009-10-29 08:12:44 +00001896 case TemplateArgument::Expression:
1897 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1898 break;
1899
1900 case TemplateArgument::Declaration:
1901 case TemplateArgument::Integral:
1902 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001903 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001904 break;
1905 }
1906}
1907
1908template<typename Derived>
1909bool TreeTransform<Derived>::TransformTemplateArgument(
1910 const TemplateArgumentLoc &Input,
1911 TemplateArgumentLoc &Output) {
1912 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001913 switch (Arg.getKind()) {
1914 case TemplateArgument::Null:
1915 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001916 Output = Input;
1917 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregore922c772009-08-04 22:27:00 +00001919 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001920 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001921 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001922 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001923
1924 DI = getDerived().TransformType(DI);
1925 if (!DI) return true;
1926
1927 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1928 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001929 }
Mike Stump11289f42009-09-09 15:08:12 +00001930
Douglas Gregore922c772009-08-04 22:27:00 +00001931 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001932 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001933 DeclarationName Name;
1934 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1935 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001936 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001937 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001938 if (!D) return true;
1939
John McCall0d07eb32009-10-29 18:45:58 +00001940 Expr *SourceExpr = Input.getSourceDeclExpression();
1941 if (SourceExpr) {
1942 EnterExpressionEvaluationContext Unevaluated(getSema(),
1943 Action::Unevaluated);
1944 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1945 if (E.isInvalid())
1946 SourceExpr = NULL;
1947 else {
1948 SourceExpr = E.takeAs<Expr>();
1949 SourceExpr->Retain();
1950 }
1951 }
1952
1953 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001954 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001957 case TemplateArgument::Template: {
1958 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1959 TemplateName Template
1960 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1961 if (Template.isNull())
1962 return true;
1963
1964 Output = TemplateArgumentLoc(TemplateArgument(Template),
1965 Input.getTemplateQualifierRange(),
1966 Input.getTemplateNameLoc());
1967 return false;
1968 }
1969
Douglas Gregore922c772009-08-04 22:27:00 +00001970 case TemplateArgument::Expression: {
1971 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001972 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001973 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001974
John McCall0ad16662009-10-29 08:12:44 +00001975 Expr *InputExpr = Input.getSourceExpression();
1976 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1977
1978 Sema::OwningExprResult E
1979 = getDerived().TransformExpr(InputExpr);
1980 if (E.isInvalid()) return true;
1981
1982 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001983 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001984 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1985 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001986 }
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregore922c772009-08-04 22:27:00 +00001988 case TemplateArgument::Pack: {
1989 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1990 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001991 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001992 AEnd = Arg.pack_end();
1993 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00001994
John McCall0ad16662009-10-29 08:12:44 +00001995 // FIXME: preserve source information here when we start
1996 // caring about parameter packs.
1997
John McCall0d07eb32009-10-29 18:45:58 +00001998 TemplateArgumentLoc InputArg;
1999 TemplateArgumentLoc OutputArg;
2000 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2001 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002002 return true;
2003
John McCall0d07eb32009-10-29 18:45:58 +00002004 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002005 }
2006 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002007 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002008 true);
John McCall0d07eb32009-10-29 18:45:58 +00002009 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002010 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002011 }
2012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregore922c772009-08-04 22:27:00 +00002014 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002015 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002016}
2017
Douglas Gregord6ff3322009-08-04 16:50:30 +00002018//===----------------------------------------------------------------------===//
2019// Type transformation
2020//===----------------------------------------------------------------------===//
2021
2022template<typename Derived>
2023QualType TreeTransform<Derived>::TransformType(QualType T) {
2024 if (getDerived().AlreadyTransformed(T))
2025 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002026
John McCall550e0c22009-10-21 00:40:46 +00002027 // Temporary workaround. All of these transformations should
2028 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002029 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002030 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002031
John McCallbcd03502009-12-07 02:54:59 +00002032 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002033
John McCall550e0c22009-10-21 00:40:46 +00002034 if (!NewDI)
2035 return QualType();
2036
2037 return NewDI->getType();
2038}
2039
2040template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002041TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002042 if (getDerived().AlreadyTransformed(DI->getType()))
2043 return DI;
2044
2045 TypeLocBuilder TLB;
2046
2047 TypeLoc TL = DI->getTypeLoc();
2048 TLB.reserve(TL.getFullDataSize());
2049
2050 QualType Result = getDerived().TransformType(TLB, TL);
2051 if (Result.isNull())
2052 return 0;
2053
John McCallbcd03502009-12-07 02:54:59 +00002054 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002055}
2056
2057template<typename Derived>
2058QualType
2059TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2060 switch (T.getTypeLocClass()) {
2061#define ABSTRACT_TYPELOC(CLASS, PARENT)
2062#define TYPELOC(CLASS, PARENT) \
2063 case TypeLoc::CLASS: \
2064 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2065#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002068 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002069 return QualType();
2070}
2071
2072/// FIXME: By default, this routine adds type qualifiers only to types
2073/// that can have qualifiers, and silently suppresses those qualifiers
2074/// that are not permitted (e.g., qualifiers on reference or function
2075/// types). This is the right thing for template instantiation, but
2076/// probably not for other clients.
2077template<typename Derived>
2078QualType
2079TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2080 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002081 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002082
2083 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2084 if (Result.isNull())
2085 return QualType();
2086
2087 // Silently suppress qualifiers if the result type can't be qualified.
2088 // FIXME: this is the right thing for template instantiation, but
2089 // probably not for other clients.
2090 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002091 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002092
John McCall550e0c22009-10-21 00:40:46 +00002093 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2094
2095 TLB.push<QualifiedTypeLoc>(Result);
2096
2097 // No location information to preserve.
2098
2099 return Result;
2100}
2101
2102template <class TyLoc> static inline
2103QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2104 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2105 NewT.setNameLoc(T.getNameLoc());
2106 return T.getType();
2107}
2108
2109// Ugly metaprogramming macros because I couldn't be bothered to make
2110// the equivalent template version work.
2111#define TransformPointerLikeType(TypeClass) do { \
2112 QualType PointeeType \
2113 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2114 if (PointeeType.isNull()) \
2115 return QualType(); \
2116 \
2117 QualType Result = TL.getType(); \
2118 if (getDerived().AlwaysRebuild() || \
2119 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002120 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2121 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002122 if (Result.isNull()) \
2123 return QualType(); \
2124 } \
2125 \
2126 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2127 NewT.setSigilLoc(TL.getSigilLoc()); \
2128 \
2129 return Result; \
2130} while(0)
2131
John McCall550e0c22009-10-21 00:40:46 +00002132template<typename Derived>
2133QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2134 BuiltinTypeLoc T) {
2135 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002136}
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregord6ff3322009-08-04 16:50:30 +00002138template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002139QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2140 ComplexTypeLoc T) {
2141 // FIXME: recurse?
2142 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002143}
Mike Stump11289f42009-09-09 15:08:12 +00002144
Douglas Gregord6ff3322009-08-04 16:50:30 +00002145template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002146QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2147 PointerTypeLoc TL) {
2148 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002149}
Mike Stump11289f42009-09-09 15:08:12 +00002150
2151template<typename Derived>
2152QualType
John McCall550e0c22009-10-21 00:40:46 +00002153TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2154 BlockPointerTypeLoc TL) {
2155 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002156}
2157
John McCall70dd5f62009-10-30 00:06:24 +00002158/// Transforms a reference type. Note that somewhat paradoxically we
2159/// don't care whether the type itself is an l-value type or an r-value
2160/// type; we only care if the type was *written* as an l-value type
2161/// or an r-value type.
2162template<typename Derived>
2163QualType
2164TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2165 ReferenceTypeLoc TL) {
2166 const ReferenceType *T = TL.getTypePtr();
2167
2168 // Note that this works with the pointee-as-written.
2169 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2170 if (PointeeType.isNull())
2171 return QualType();
2172
2173 QualType Result = TL.getType();
2174 if (getDerived().AlwaysRebuild() ||
2175 PointeeType != T->getPointeeTypeAsWritten()) {
2176 Result = getDerived().RebuildReferenceType(PointeeType,
2177 T->isSpelledAsLValue(),
2178 TL.getSigilLoc());
2179 if (Result.isNull())
2180 return QualType();
2181 }
2182
2183 // r-value references can be rebuilt as l-value references.
2184 ReferenceTypeLoc NewTL;
2185 if (isa<LValueReferenceType>(Result))
2186 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2187 else
2188 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2189 NewTL.setSigilLoc(TL.getSigilLoc());
2190
2191 return Result;
2192}
2193
Mike Stump11289f42009-09-09 15:08:12 +00002194template<typename Derived>
2195QualType
John McCall550e0c22009-10-21 00:40:46 +00002196TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2197 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002198 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002199}
2200
Mike Stump11289f42009-09-09 15:08:12 +00002201template<typename Derived>
2202QualType
John McCall550e0c22009-10-21 00:40:46 +00002203TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2204 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002205 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002206}
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregord6ff3322009-08-04 16:50:30 +00002208template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002209QualType
John McCall550e0c22009-10-21 00:40:46 +00002210TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2211 MemberPointerTypeLoc TL) {
2212 MemberPointerType *T = TL.getTypePtr();
2213
2214 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002215 if (PointeeType.isNull())
2216 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002217
John McCall550e0c22009-10-21 00:40:46 +00002218 // TODO: preserve source information for this.
2219 QualType ClassType
2220 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002221 if (ClassType.isNull())
2222 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002223
John McCall550e0c22009-10-21 00:40:46 +00002224 QualType Result = TL.getType();
2225 if (getDerived().AlwaysRebuild() ||
2226 PointeeType != T->getPointeeType() ||
2227 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002228 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2229 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002230 if (Result.isNull())
2231 return QualType();
2232 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002233
John McCall550e0c22009-10-21 00:40:46 +00002234 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2235 NewTL.setSigilLoc(TL.getSigilLoc());
2236
2237 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002238}
2239
Mike Stump11289f42009-09-09 15:08:12 +00002240template<typename Derived>
2241QualType
John McCall550e0c22009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2243 ConstantArrayTypeLoc TL) {
2244 ConstantArrayType *T = TL.getTypePtr();
2245 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002246 if (ElementType.isNull())
2247 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002248
John McCall550e0c22009-10-21 00:40:46 +00002249 QualType Result = TL.getType();
2250 if (getDerived().AlwaysRebuild() ||
2251 ElementType != T->getElementType()) {
2252 Result = getDerived().RebuildConstantArrayType(ElementType,
2253 T->getSizeModifier(),
2254 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002255 T->getIndexTypeCVRQualifiers(),
2256 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002257 if (Result.isNull())
2258 return QualType();
2259 }
2260
2261 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2262 NewTL.setLBracketLoc(TL.getLBracketLoc());
2263 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002264
John McCall550e0c22009-10-21 00:40:46 +00002265 Expr *Size = TL.getSizeExpr();
2266 if (Size) {
2267 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2268 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2269 }
2270 NewTL.setSizeExpr(Size);
2271
2272 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002273}
Mike Stump11289f42009-09-09 15:08:12 +00002274
Douglas Gregord6ff3322009-08-04 16:50:30 +00002275template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002276QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002277 TypeLocBuilder &TLB,
2278 IncompleteArrayTypeLoc TL) {
2279 IncompleteArrayType *T = TL.getTypePtr();
2280 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002281 if (ElementType.isNull())
2282 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002283
John McCall550e0c22009-10-21 00:40:46 +00002284 QualType Result = TL.getType();
2285 if (getDerived().AlwaysRebuild() ||
2286 ElementType != T->getElementType()) {
2287 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002288 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002289 T->getIndexTypeCVRQualifiers(),
2290 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002291 if (Result.isNull())
2292 return QualType();
2293 }
2294
2295 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2296 NewTL.setLBracketLoc(TL.getLBracketLoc());
2297 NewTL.setRBracketLoc(TL.getRBracketLoc());
2298 NewTL.setSizeExpr(0);
2299
2300 return Result;
2301}
2302
2303template<typename Derived>
2304QualType
2305TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2306 VariableArrayTypeLoc TL) {
2307 VariableArrayType *T = TL.getTypePtr();
2308 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2309 if (ElementType.isNull())
2310 return QualType();
2311
2312 // Array bounds are not potentially evaluated contexts
2313 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2314
2315 Sema::OwningExprResult SizeResult
2316 = getDerived().TransformExpr(T->getSizeExpr());
2317 if (SizeResult.isInvalid())
2318 return QualType();
2319
2320 Expr *Size = static_cast<Expr*>(SizeResult.get());
2321
2322 QualType Result = TL.getType();
2323 if (getDerived().AlwaysRebuild() ||
2324 ElementType != T->getElementType() ||
2325 Size != T->getSizeExpr()) {
2326 Result = getDerived().RebuildVariableArrayType(ElementType,
2327 T->getSizeModifier(),
2328 move(SizeResult),
2329 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002330 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002331 if (Result.isNull())
2332 return QualType();
2333 }
2334 else SizeResult.take();
2335
2336 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2337 NewTL.setLBracketLoc(TL.getLBracketLoc());
2338 NewTL.setRBracketLoc(TL.getRBracketLoc());
2339 NewTL.setSizeExpr(Size);
2340
2341 return Result;
2342}
2343
2344template<typename Derived>
2345QualType
2346TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2347 DependentSizedArrayTypeLoc TL) {
2348 DependentSizedArrayType *T = TL.getTypePtr();
2349 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2350 if (ElementType.isNull())
2351 return QualType();
2352
2353 // Array bounds are not potentially evaluated contexts
2354 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2355
2356 Sema::OwningExprResult SizeResult
2357 = getDerived().TransformExpr(T->getSizeExpr());
2358 if (SizeResult.isInvalid())
2359 return QualType();
2360
2361 Expr *Size = static_cast<Expr*>(SizeResult.get());
2362
2363 QualType Result = TL.getType();
2364 if (getDerived().AlwaysRebuild() ||
2365 ElementType != T->getElementType() ||
2366 Size != T->getSizeExpr()) {
2367 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2368 T->getSizeModifier(),
2369 move(SizeResult),
2370 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002371 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002372 if (Result.isNull())
2373 return QualType();
2374 }
2375 else SizeResult.take();
2376
2377 // We might have any sort of array type now, but fortunately they
2378 // all have the same location layout.
2379 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2380 NewTL.setLBracketLoc(TL.getLBracketLoc());
2381 NewTL.setRBracketLoc(TL.getRBracketLoc());
2382 NewTL.setSizeExpr(Size);
2383
2384 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002385}
Mike Stump11289f42009-09-09 15:08:12 +00002386
2387template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002388QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002389 TypeLocBuilder &TLB,
2390 DependentSizedExtVectorTypeLoc TL) {
2391 DependentSizedExtVectorType *T = TL.getTypePtr();
2392
2393 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002394 QualType ElementType = getDerived().TransformType(T->getElementType());
2395 if (ElementType.isNull())
2396 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002397
Douglas Gregore922c772009-08-04 22:27:00 +00002398 // Vector sizes are not potentially evaluated contexts
2399 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2400
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2402 if (Size.isInvalid())
2403 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002404
John McCall550e0c22009-10-21 00:40:46 +00002405 QualType Result = TL.getType();
2406 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002407 ElementType != T->getElementType() ||
2408 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002409 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410 move(Size),
2411 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002412 if (Result.isNull())
2413 return QualType();
2414 }
2415 else Size.take();
2416
2417 // Result might be dependent or not.
2418 if (isa<DependentSizedExtVectorType>(Result)) {
2419 DependentSizedExtVectorTypeLoc NewTL
2420 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2421 NewTL.setNameLoc(TL.getNameLoc());
2422 } else {
2423 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2424 NewTL.setNameLoc(TL.getNameLoc());
2425 }
2426
2427 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002428}
Mike Stump11289f42009-09-09 15:08:12 +00002429
2430template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002431QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2432 VectorTypeLoc TL) {
2433 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002434 QualType ElementType = getDerived().TransformType(T->getElementType());
2435 if (ElementType.isNull())
2436 return QualType();
2437
John McCall550e0c22009-10-21 00:40:46 +00002438 QualType Result = TL.getType();
2439 if (getDerived().AlwaysRebuild() ||
2440 ElementType != T->getElementType()) {
2441 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2442 if (Result.isNull())
2443 return QualType();
2444 }
2445
2446 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2447 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002448
John McCall550e0c22009-10-21 00:40:46 +00002449 return Result;
2450}
2451
2452template<typename Derived>
2453QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2454 ExtVectorTypeLoc TL) {
2455 VectorType *T = TL.getTypePtr();
2456 QualType ElementType = getDerived().TransformType(T->getElementType());
2457 if (ElementType.isNull())
2458 return QualType();
2459
2460 QualType Result = TL.getType();
2461 if (getDerived().AlwaysRebuild() ||
2462 ElementType != T->getElementType()) {
2463 Result = getDerived().RebuildExtVectorType(ElementType,
2464 T->getNumElements(),
2465 /*FIXME*/ SourceLocation());
2466 if (Result.isNull())
2467 return QualType();
2468 }
2469
2470 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2471 NewTL.setNameLoc(TL.getNameLoc());
2472
2473 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474}
Mike Stump11289f42009-09-09 15:08:12 +00002475
2476template<typename Derived>
2477QualType
John McCall550e0c22009-10-21 00:40:46 +00002478TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2479 FunctionProtoTypeLoc TL) {
2480 FunctionProtoType *T = TL.getTypePtr();
2481 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482 if (ResultType.isNull())
2483 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002484
John McCall550e0c22009-10-21 00:40:46 +00002485 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002487 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2488 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2489 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002490
John McCall550e0c22009-10-21 00:40:46 +00002491 QualType NewType;
2492 ParmVarDecl *NewParm;
2493
2494 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002495 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002496 assert(OldDI->getType() == T->getArgType(i));
2497
John McCallbcd03502009-12-07 02:54:59 +00002498 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002499 if (!NewDI)
2500 return QualType();
2501
2502 if (NewDI == OldDI)
2503 NewParm = OldParm;
2504 else
2505 NewParm = ParmVarDecl::Create(SemaRef.Context,
2506 OldParm->getDeclContext(),
2507 OldParm->getLocation(),
2508 OldParm->getIdentifier(),
2509 NewDI->getType(),
2510 NewDI,
2511 OldParm->getStorageClass(),
2512 /* DefArg */ NULL);
2513 NewType = NewParm->getType();
2514
2515 // Deal with the possibility that we don't have a parameter
2516 // declaration for this parameter.
2517 } else {
2518 NewParm = 0;
2519
2520 QualType OldType = T->getArgType(i);
2521 NewType = getDerived().TransformType(OldType);
2522 if (NewType.isNull())
2523 return QualType();
2524 }
2525
2526 ParamTypes.push_back(NewType);
2527 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002528 }
Mike Stump11289f42009-09-09 15:08:12 +00002529
John McCall550e0c22009-10-21 00:40:46 +00002530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 ResultType != T->getResultType() ||
2533 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2534 Result = getDerived().RebuildFunctionProtoType(ResultType,
2535 ParamTypes.data(),
2536 ParamTypes.size(),
2537 T->isVariadic(),
2538 T->getTypeQuals());
2539 if (Result.isNull())
2540 return QualType();
2541 }
Mike Stump11289f42009-09-09 15:08:12 +00002542
John McCall550e0c22009-10-21 00:40:46 +00002543 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2544 NewTL.setLParenLoc(TL.getLParenLoc());
2545 NewTL.setRParenLoc(TL.getRParenLoc());
2546 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2547 NewTL.setArg(i, ParamDecls[i]);
2548
2549 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002550}
Mike Stump11289f42009-09-09 15:08:12 +00002551
Douglas Gregord6ff3322009-08-04 16:50:30 +00002552template<typename Derived>
2553QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002554 TypeLocBuilder &TLB,
2555 FunctionNoProtoTypeLoc TL) {
2556 FunctionNoProtoType *T = TL.getTypePtr();
2557 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2558 if (ResultType.isNull())
2559 return QualType();
2560
2561 QualType Result = TL.getType();
2562 if (getDerived().AlwaysRebuild() ||
2563 ResultType != T->getResultType())
2564 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2565
2566 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2567 NewTL.setLParenLoc(TL.getLParenLoc());
2568 NewTL.setRParenLoc(TL.getRParenLoc());
2569
2570 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002571}
Mike Stump11289f42009-09-09 15:08:12 +00002572
John McCallb96ec562009-12-04 22:46:56 +00002573template<typename Derived> QualType
2574TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2575 UnresolvedUsingTypeLoc TL) {
2576 UnresolvedUsingType *T = TL.getTypePtr();
2577 Decl *D = getDerived().TransformDecl(T->getDecl());
2578 if (!D)
2579 return QualType();
2580
2581 QualType Result = TL.getType();
2582 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2583 Result = getDerived().RebuildUnresolvedUsingType(D);
2584 if (Result.isNull())
2585 return QualType();
2586 }
2587
2588 // We might get an arbitrary type spec type back. We should at
2589 // least always get a type spec type, though.
2590 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2591 NewTL.setNameLoc(TL.getNameLoc());
2592
2593 return Result;
2594}
2595
Douglas Gregord6ff3322009-08-04 16:50:30 +00002596template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002597QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2598 TypedefTypeLoc TL) {
2599 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002600 TypedefDecl *Typedef
2601 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2602 if (!Typedef)
2603 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002604
John McCall550e0c22009-10-21 00:40:46 +00002605 QualType Result = TL.getType();
2606 if (getDerived().AlwaysRebuild() ||
2607 Typedef != T->getDecl()) {
2608 Result = getDerived().RebuildTypedefType(Typedef);
2609 if (Result.isNull())
2610 return QualType();
2611 }
Mike Stump11289f42009-09-09 15:08:12 +00002612
John McCall550e0c22009-10-21 00:40:46 +00002613 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2614 NewTL.setNameLoc(TL.getNameLoc());
2615
2616 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002617}
Mike Stump11289f42009-09-09 15:08:12 +00002618
Douglas Gregord6ff3322009-08-04 16:50:30 +00002619template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002620QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2621 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00002622 // typeof expressions are not potentially evaluated contexts
2623 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002624
John McCalle8595032010-01-13 20:03:27 +00002625 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626 if (E.isInvalid())
2627 return QualType();
2628
John McCall550e0c22009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002631 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002632 Result = getDerived().RebuildTypeOfExprType(move(E));
2633 if (Result.isNull())
2634 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635 }
John McCall550e0c22009-10-21 00:40:46 +00002636 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002637
John McCall550e0c22009-10-21 00:40:46 +00002638 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002639 NewTL.setTypeofLoc(TL.getTypeofLoc());
2640 NewTL.setLParenLoc(TL.getLParenLoc());
2641 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002642
2643 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002644}
Mike Stump11289f42009-09-09 15:08:12 +00002645
2646template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002647QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2648 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00002649 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2650 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2651 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002652 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002653
John McCall550e0c22009-10-21 00:40:46 +00002654 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002655 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2656 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002657 if (Result.isNull())
2658 return QualType();
2659 }
Mike Stump11289f42009-09-09 15:08:12 +00002660
John McCall550e0c22009-10-21 00:40:46 +00002661 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002662 NewTL.setTypeofLoc(TL.getTypeofLoc());
2663 NewTL.setLParenLoc(TL.getLParenLoc());
2664 NewTL.setRParenLoc(TL.getRParenLoc());
2665 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002666
2667 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002668}
Mike Stump11289f42009-09-09 15:08:12 +00002669
2670template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002671QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2672 DecltypeTypeLoc TL) {
2673 DecltypeType *T = TL.getTypePtr();
2674
Douglas Gregore922c772009-08-04 22:27:00 +00002675 // decltype expressions are not potentially evaluated contexts
2676 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002677
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2679 if (E.isInvalid())
2680 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002681
John McCall550e0c22009-10-21 00:40:46 +00002682 QualType Result = TL.getType();
2683 if (getDerived().AlwaysRebuild() ||
2684 E.get() != T->getUnderlyingExpr()) {
2685 Result = getDerived().RebuildDecltypeType(move(E));
2686 if (Result.isNull())
2687 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 }
John McCall550e0c22009-10-21 00:40:46 +00002689 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002690
John McCall550e0c22009-10-21 00:40:46 +00002691 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2692 NewTL.setNameLoc(TL.getNameLoc());
2693
2694 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002695}
2696
2697template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002698QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2699 RecordTypeLoc TL) {
2700 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002701 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002702 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002703 if (!Record)
2704 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002705
John McCall550e0c22009-10-21 00:40:46 +00002706 QualType Result = TL.getType();
2707 if (getDerived().AlwaysRebuild() ||
2708 Record != T->getDecl()) {
2709 Result = getDerived().RebuildRecordType(Record);
2710 if (Result.isNull())
2711 return QualType();
2712 }
Mike Stump11289f42009-09-09 15:08:12 +00002713
John McCall550e0c22009-10-21 00:40:46 +00002714 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2715 NewTL.setNameLoc(TL.getNameLoc());
2716
2717 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002718}
Mike Stump11289f42009-09-09 15:08:12 +00002719
2720template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002721QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2722 EnumTypeLoc TL) {
2723 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002724 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002725 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726 if (!Enum)
2727 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002728
John McCall550e0c22009-10-21 00:40:46 +00002729 QualType Result = TL.getType();
2730 if (getDerived().AlwaysRebuild() ||
2731 Enum != T->getDecl()) {
2732 Result = getDerived().RebuildEnumType(Enum);
2733 if (Result.isNull())
2734 return QualType();
2735 }
Mike Stump11289f42009-09-09 15:08:12 +00002736
John McCall550e0c22009-10-21 00:40:46 +00002737 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2738 NewTL.setNameLoc(TL.getNameLoc());
2739
2740 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002741}
John McCallfcc33b02009-09-05 00:15:47 +00002742
2743template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002744QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2745 ElaboratedTypeLoc TL) {
2746 ElaboratedType *T = TL.getTypePtr();
2747
2748 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002749 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2750 if (Underlying.isNull())
2751 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002752
John McCall550e0c22009-10-21 00:40:46 +00002753 QualType Result = TL.getType();
2754 if (getDerived().AlwaysRebuild() ||
2755 Underlying != T->getUnderlyingType()) {
2756 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2757 if (Result.isNull())
2758 return QualType();
2759 }
Mike Stump11289f42009-09-09 15:08:12 +00002760
John McCall550e0c22009-10-21 00:40:46 +00002761 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2762 NewTL.setNameLoc(TL.getNameLoc());
2763
2764 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002765}
Mike Stump11289f42009-09-09 15:08:12 +00002766
2767
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768template<typename Derived>
2769QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002770 TypeLocBuilder &TLB,
2771 TemplateTypeParmTypeLoc TL) {
2772 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002773}
2774
Mike Stump11289f42009-09-09 15:08:12 +00002775template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002776QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002777 TypeLocBuilder &TLB,
2778 SubstTemplateTypeParmTypeLoc TL) {
2779 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002780}
2781
2782template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002783inline QualType
2784TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002785 TypeLocBuilder &TLB,
2786 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002787 return TransformTemplateSpecializationType(TLB, TL, QualType());
2788}
John McCall550e0c22009-10-21 00:40:46 +00002789
John McCall0ad16662009-10-29 08:12:44 +00002790template<typename Derived>
2791QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2792 const TemplateSpecializationType *TST,
2793 QualType ObjectType) {
2794 // FIXME: this entire method is a temporary workaround; callers
2795 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002796
John McCall0ad16662009-10-29 08:12:44 +00002797 // Fake up a TemplateSpecializationTypeLoc.
2798 TypeLocBuilder TLB;
2799 TemplateSpecializationTypeLoc TL
2800 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2801
John McCall0d07eb32009-10-29 18:45:58 +00002802 SourceLocation BaseLoc = getDerived().getBaseLocation();
2803
2804 TL.setTemplateNameLoc(BaseLoc);
2805 TL.setLAngleLoc(BaseLoc);
2806 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002807 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2808 const TemplateArgument &TA = TST->getArg(i);
2809 TemplateArgumentLoc TAL;
2810 getDerived().InventTemplateArgumentLoc(TA, TAL);
2811 TL.setArgLocInfo(i, TAL.getLocInfo());
2812 }
2813
2814 TypeLocBuilder IgnoredTLB;
2815 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002816}
2817
2818template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002819QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002820 TypeLocBuilder &TLB,
2821 TemplateSpecializationTypeLoc TL,
2822 QualType ObjectType) {
2823 const TemplateSpecializationType *T = TL.getTypePtr();
2824
Mike Stump11289f42009-09-09 15:08:12 +00002825 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002826 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002827 if (Template.isNull())
2828 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002829
John McCall6b51f282009-11-23 01:53:49 +00002830 TemplateArgumentListInfo NewTemplateArgs;
2831 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2832 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2833
2834 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2835 TemplateArgumentLoc Loc;
2836 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002838 NewTemplateArgs.addArgument(Loc);
2839 }
Mike Stump11289f42009-09-09 15:08:12 +00002840
John McCall0ad16662009-10-29 08:12:44 +00002841 // FIXME: maybe don't rebuild if all the template arguments are the same.
2842
2843 QualType Result =
2844 getDerived().RebuildTemplateSpecializationType(Template,
2845 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002846 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002847
2848 if (!Result.isNull()) {
2849 TemplateSpecializationTypeLoc NewTL
2850 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2851 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2852 NewTL.setLAngleLoc(TL.getLAngleLoc());
2853 NewTL.setRAngleLoc(TL.getRAngleLoc());
2854 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2855 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002856 }
Mike Stump11289f42009-09-09 15:08:12 +00002857
John McCall0ad16662009-10-29 08:12:44 +00002858 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002859}
Mike Stump11289f42009-09-09 15:08:12 +00002860
2861template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002862QualType
2863TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2864 QualifiedNameTypeLoc TL) {
2865 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002866 NestedNameSpecifier *NNS
2867 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2868 SourceRange());
2869 if (!NNS)
2870 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002871
Douglas Gregord6ff3322009-08-04 16:50:30 +00002872 QualType Named = getDerived().TransformType(T->getNamedType());
2873 if (Named.isNull())
2874 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002875
John McCall550e0c22009-10-21 00:40:46 +00002876 QualType Result = TL.getType();
2877 if (getDerived().AlwaysRebuild() ||
2878 NNS != T->getQualifier() ||
2879 Named != T->getNamedType()) {
2880 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2881 if (Result.isNull())
2882 return QualType();
2883 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002884
John McCall550e0c22009-10-21 00:40:46 +00002885 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2886 NewTL.setNameLoc(TL.getNameLoc());
2887
2888 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889}
Mike Stump11289f42009-09-09 15:08:12 +00002890
2891template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002892QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2893 TypenameTypeLoc TL) {
2894 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002895
2896 /* FIXME: preserve source information better than this */
2897 SourceRange SR(TL.getNameLoc());
2898
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002900 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901 if (!NNS)
2902 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002903
John McCall550e0c22009-10-21 00:40:46 +00002904 QualType Result;
2905
Douglas Gregord6ff3322009-08-04 16:50:30 +00002906 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002907 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002908 = getDerived().TransformType(QualType(TemplateId, 0));
2909 if (NewTemplateId.isNull())
2910 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002911
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912 if (!getDerived().AlwaysRebuild() &&
2913 NNS == T->getQualifier() &&
2914 NewTemplateId == QualType(TemplateId, 0))
2915 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002916
John McCall550e0c22009-10-21 00:40:46 +00002917 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2918 } else {
John McCall0ad16662009-10-29 08:12:44 +00002919 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002920 }
John McCall550e0c22009-10-21 00:40:46 +00002921 if (Result.isNull())
2922 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002923
John McCall550e0c22009-10-21 00:40:46 +00002924 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2925 NewTL.setNameLoc(TL.getNameLoc());
2926
2927 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928}
Mike Stump11289f42009-09-09 15:08:12 +00002929
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002931QualType
2932TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2933 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002934 assert(false && "TransformObjCInterfaceType unimplemented");
2935 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936}
Mike Stump11289f42009-09-09 15:08:12 +00002937
2938template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002939QualType
2940TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2941 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002942 assert(false && "TransformObjCObjectPointerType unimplemented");
2943 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002944}
2945
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002947// Statement transformation
2948//===----------------------------------------------------------------------===//
2949template<typename Derived>
2950Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002951TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2952 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002953}
2954
2955template<typename Derived>
2956Sema::OwningStmtResult
2957TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2958 return getDerived().TransformCompoundStmt(S, false);
2959}
2960
2961template<typename Derived>
2962Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002963TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002964 bool IsStmtExpr) {
2965 bool SubStmtChanged = false;
2966 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2967 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2968 B != BEnd; ++B) {
2969 OwningStmtResult Result = getDerived().TransformStmt(*B);
2970 if (Result.isInvalid())
2971 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002972
Douglas Gregorebe10102009-08-20 07:17:43 +00002973 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2974 Statements.push_back(Result.takeAs<Stmt>());
2975 }
Mike Stump11289f42009-09-09 15:08:12 +00002976
Douglas Gregorebe10102009-08-20 07:17:43 +00002977 if (!getDerived().AlwaysRebuild() &&
2978 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002979 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002980
2981 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2982 move_arg(Statements),
2983 S->getRBracLoc(),
2984 IsStmtExpr);
2985}
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregorebe10102009-08-20 07:17:43 +00002987template<typename Derived>
2988Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002989TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00002990 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2991 {
2992 // The case value expressions are not potentially evaluated.
2993 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002994
Eli Friedman06577382009-11-19 03:14:00 +00002995 // Transform the left-hand case value.
2996 LHS = getDerived().TransformExpr(S->getLHS());
2997 if (LHS.isInvalid())
2998 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002999
Eli Friedman06577382009-11-19 03:14:00 +00003000 // Transform the right-hand case value (for the GNU case-range extension).
3001 RHS = getDerived().TransformExpr(S->getRHS());
3002 if (RHS.isInvalid())
3003 return SemaRef.StmtError();
3004 }
Mike Stump11289f42009-09-09 15:08:12 +00003005
Douglas Gregorebe10102009-08-20 07:17:43 +00003006 // Build the case statement.
3007 // Case statements are always rebuilt so that they will attached to their
3008 // transformed switch statement.
3009 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3010 move(LHS),
3011 S->getEllipsisLoc(),
3012 move(RHS),
3013 S->getColonLoc());
3014 if (Case.isInvalid())
3015 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003016
Douglas Gregorebe10102009-08-20 07:17:43 +00003017 // Transform the statement following the case
3018 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3019 if (SubStmt.isInvalid())
3020 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003021
Douglas Gregorebe10102009-08-20 07:17:43 +00003022 // Attach the body to the case statement
3023 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3024}
3025
3026template<typename Derived>
3027Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003028TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003029 // Transform the statement following the default case
3030 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3031 if (SubStmt.isInvalid())
3032 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003033
Douglas Gregorebe10102009-08-20 07:17:43 +00003034 // Default statements are always rebuilt
3035 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3036 move(SubStmt));
3037}
Mike Stump11289f42009-09-09 15:08:12 +00003038
Douglas Gregorebe10102009-08-20 07:17:43 +00003039template<typename Derived>
3040Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003041TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003042 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3043 if (SubStmt.isInvalid())
3044 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003045
Douglas Gregorebe10102009-08-20 07:17:43 +00003046 // FIXME: Pass the real colon location in.
3047 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3048 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3049 move(SubStmt));
3050}
Mike Stump11289f42009-09-09 15:08:12 +00003051
Douglas Gregorebe10102009-08-20 07:17:43 +00003052template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003053Sema::OwningStmtResult
3054TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003055 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003056 OwningExprResult Cond(SemaRef);
3057 VarDecl *ConditionVar = 0;
3058 if (S->getConditionVariable()) {
3059 ConditionVar
3060 = cast_or_null<VarDecl>(
3061 getDerived().TransformDefinition(S->getConditionVariable()));
3062 if (!ConditionVar)
3063 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003064 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003065 Cond = getDerived().TransformExpr(S->getCond());
3066
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003067 if (Cond.isInvalid())
3068 return SemaRef.StmtError();
3069 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003070
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003071 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 // Transform the "then" branch.
3074 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3075 if (Then.isInvalid())
3076 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003077
Douglas Gregorebe10102009-08-20 07:17:43 +00003078 // Transform the "else" branch.
3079 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3080 if (Else.isInvalid())
3081 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083 if (!getDerived().AlwaysRebuild() &&
3084 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003085 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003086 Then.get() == S->getThen() &&
3087 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003088 return SemaRef.Owned(S->Retain());
3089
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003090 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3091 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003092 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003093}
3094
3095template<typename Derived>
3096Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003097TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003098 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003099 OwningExprResult Cond(SemaRef);
3100 VarDecl *ConditionVar = 0;
3101 if (S->getConditionVariable()) {
3102 ConditionVar
3103 = cast_or_null<VarDecl>(
3104 getDerived().TransformDefinition(S->getConditionVariable()));
3105 if (!ConditionVar)
3106 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003107 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003108 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003109
3110 if (Cond.isInvalid())
3111 return SemaRef.StmtError();
3112 }
Mike Stump11289f42009-09-09 15:08:12 +00003113
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003114 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003115
Douglas Gregorebe10102009-08-20 07:17:43 +00003116 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003117 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3118 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003119 if (Switch.isInvalid())
3120 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003121
Douglas Gregorebe10102009-08-20 07:17:43 +00003122 // Transform the body of the switch statement.
3123 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3124 if (Body.isInvalid())
3125 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003126
Douglas Gregorebe10102009-08-20 07:17:43 +00003127 // Complete the switch statement.
3128 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3129 move(Body));
3130}
Mike Stump11289f42009-09-09 15:08:12 +00003131
Douglas Gregorebe10102009-08-20 07:17:43 +00003132template<typename Derived>
3133Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003134TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003135 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003136 OwningExprResult Cond(SemaRef);
3137 VarDecl *ConditionVar = 0;
3138 if (S->getConditionVariable()) {
3139 ConditionVar
3140 = cast_or_null<VarDecl>(
3141 getDerived().TransformDefinition(S->getConditionVariable()));
3142 if (!ConditionVar)
3143 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003144 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003145 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003146
3147 if (Cond.isInvalid())
3148 return SemaRef.StmtError();
3149 }
Mike Stump11289f42009-09-09 15:08:12 +00003150
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003151 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 // Transform the body
3154 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3155 if (Body.isInvalid())
3156 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 if (!getDerived().AlwaysRebuild() &&
3159 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003160 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003161 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003162 return SemaRef.Owned(S->Retain());
3163
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003164 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3165 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003166}
Mike Stump11289f42009-09-09 15:08:12 +00003167
Douglas Gregorebe10102009-08-20 07:17:43 +00003168template<typename Derived>
3169Sema::OwningStmtResult
3170TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3171 // Transform the condition
3172 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3173 if (Cond.isInvalid())
3174 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003175
Douglas Gregorebe10102009-08-20 07:17:43 +00003176 // Transform the body
3177 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3178 if (Body.isInvalid())
3179 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003180
Douglas Gregorebe10102009-08-20 07:17:43 +00003181 if (!getDerived().AlwaysRebuild() &&
3182 Cond.get() == S->getCond() &&
3183 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003184 return SemaRef.Owned(S->Retain());
3185
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3187 /*FIXME:*/S->getWhileLoc(), move(Cond),
3188 S->getRParenLoc());
3189}
Mike Stump11289f42009-09-09 15:08:12 +00003190
Douglas Gregorebe10102009-08-20 07:17:43 +00003191template<typename Derived>
3192Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003193TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003194 // Transform the initialization statement
3195 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3196 if (Init.isInvalid())
3197 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregorebe10102009-08-20 07:17:43 +00003199 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003200 OwningExprResult Cond(SemaRef);
3201 VarDecl *ConditionVar = 0;
3202 if (S->getConditionVariable()) {
3203 ConditionVar
3204 = cast_or_null<VarDecl>(
3205 getDerived().TransformDefinition(S->getConditionVariable()));
3206 if (!ConditionVar)
3207 return SemaRef.StmtError();
3208 } else {
3209 Cond = getDerived().TransformExpr(S->getCond());
3210
3211 if (Cond.isInvalid())
3212 return SemaRef.StmtError();
3213 }
Mike Stump11289f42009-09-09 15:08:12 +00003214
Douglas Gregorebe10102009-08-20 07:17:43 +00003215 // Transform the increment
3216 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3217 if (Inc.isInvalid())
3218 return SemaRef.StmtError();
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 Init.get() == S->getInit() &&
3227 Cond.get() == S->getCond() &&
3228 Inc.get() == S->getInc() &&
3229 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003230 return SemaRef.Owned(S->Retain());
3231
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003233 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003234 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003235 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003236 S->getRParenLoc(), move(Body));
3237}
3238
3239template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003240Sema::OwningStmtResult
3241TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003243 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003244 S->getLabel());
3245}
3246
3247template<typename Derived>
3248Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003249TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003250 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3251 if (Target.isInvalid())
3252 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregorebe10102009-08-20 07:17:43 +00003254 if (!getDerived().AlwaysRebuild() &&
3255 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003256 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003257
3258 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3259 move(Target));
3260}
3261
3262template<typename Derived>
3263Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003264TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3265 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003266}
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregorebe10102009-08-20 07:17:43 +00003268template<typename Derived>
3269Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003270TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3271 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003272}
Mike Stump11289f42009-09-09 15:08:12 +00003273
Douglas Gregorebe10102009-08-20 07:17:43 +00003274template<typename Derived>
3275Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003276TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003277 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3278 if (Result.isInvalid())
3279 return SemaRef.StmtError();
3280
Mike Stump11289f42009-09-09 15:08:12 +00003281 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003282 // to tell whether the return type of the function has changed.
3283 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3284}
Mike Stump11289f42009-09-09 15:08:12 +00003285
Douglas Gregorebe10102009-08-20 07:17:43 +00003286template<typename Derived>
3287Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003288TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003289 bool DeclChanged = false;
3290 llvm::SmallVector<Decl *, 4> Decls;
3291 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3292 D != DEnd; ++D) {
3293 Decl *Transformed = getDerived().TransformDefinition(*D);
3294 if (!Transformed)
3295 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003296
Douglas Gregorebe10102009-08-20 07:17:43 +00003297 if (Transformed != *D)
3298 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003299
Douglas Gregorebe10102009-08-20 07:17:43 +00003300 Decls.push_back(Transformed);
3301 }
Mike Stump11289f42009-09-09 15:08:12 +00003302
Douglas Gregorebe10102009-08-20 07:17:43 +00003303 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003304 return SemaRef.Owned(S->Retain());
3305
3306 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003307 S->getStartLoc(), S->getEndLoc());
3308}
Mike Stump11289f42009-09-09 15:08:12 +00003309
Douglas Gregorebe10102009-08-20 07:17:43 +00003310template<typename Derived>
3311Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003312TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003313 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003314 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003315}
3316
3317template<typename Derived>
3318Sema::OwningStmtResult
3319TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3320 // FIXME: Implement!
3321 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003322 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003323}
3324
3325
3326template<typename Derived>
3327Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003328TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003329 // FIXME: Implement this
3330 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003331 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003332}
Mike Stump11289f42009-09-09 15:08:12 +00003333
Douglas Gregorebe10102009-08-20 07:17:43 +00003334template<typename Derived>
3335Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003336TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003337 // FIXME: Implement this
3338 assert(false && "Cannot transform an Objective-C @catch statement");
3339 return SemaRef.Owned(S->Retain());
3340}
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregorebe10102009-08-20 07:17:43 +00003342template<typename Derived>
3343Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003344TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003345 // FIXME: Implement this
3346 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003347 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003348}
Mike Stump11289f42009-09-09 15:08:12 +00003349
Douglas Gregorebe10102009-08-20 07:17:43 +00003350template<typename Derived>
3351Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003352TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003353 // FIXME: Implement this
3354 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003355 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003356}
Mike Stump11289f42009-09-09 15:08:12 +00003357
Douglas Gregorebe10102009-08-20 07:17:43 +00003358template<typename Derived>
3359Sema::OwningStmtResult
3360TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003361 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003362 // FIXME: Implement this
3363 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003364 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003365}
3366
3367template<typename Derived>
3368Sema::OwningStmtResult
3369TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003370 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003371 // FIXME: Implement this
3372 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003373 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003374}
3375
3376
3377template<typename Derived>
3378Sema::OwningStmtResult
3379TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3380 // Transform the exception declaration, if any.
3381 VarDecl *Var = 0;
3382 if (S->getExceptionDecl()) {
3383 VarDecl *ExceptionDecl = S->getExceptionDecl();
3384 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3385 ExceptionDecl->getDeclName());
3386
3387 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3388 if (T.isNull())
3389 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003390
Douglas Gregorebe10102009-08-20 07:17:43 +00003391 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3392 T,
John McCallbcd03502009-12-07 02:54:59 +00003393 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003394 ExceptionDecl->getIdentifier(),
3395 ExceptionDecl->getLocation(),
3396 /*FIXME: Inaccurate*/
3397 SourceRange(ExceptionDecl->getLocation()));
3398 if (!Var || Var->isInvalidDecl()) {
3399 if (Var)
3400 Var->Destroy(SemaRef.Context);
3401 return SemaRef.StmtError();
3402 }
3403 }
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregorebe10102009-08-20 07:17:43 +00003405 // Transform the actual exception handler.
3406 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3407 if (Handler.isInvalid()) {
3408 if (Var)
3409 Var->Destroy(SemaRef.Context);
3410 return SemaRef.StmtError();
3411 }
Mike Stump11289f42009-09-09 15:08:12 +00003412
Douglas Gregorebe10102009-08-20 07:17:43 +00003413 if (!getDerived().AlwaysRebuild() &&
3414 !Var &&
3415 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003416 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003417
3418 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3419 Var,
3420 move(Handler));
3421}
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423template<typename Derived>
3424Sema::OwningStmtResult
3425TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3426 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003427 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003428 = getDerived().TransformCompoundStmt(S->getTryBlock());
3429 if (TryBlock.isInvalid())
3430 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003431
Douglas Gregorebe10102009-08-20 07:17:43 +00003432 // Transform the handlers.
3433 bool HandlerChanged = false;
3434 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3435 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003436 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003437 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3438 if (Handler.isInvalid())
3439 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003440
Douglas Gregorebe10102009-08-20 07:17:43 +00003441 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3442 Handlers.push_back(Handler.takeAs<Stmt>());
3443 }
Mike Stump11289f42009-09-09 15:08:12 +00003444
Douglas Gregorebe10102009-08-20 07:17:43 +00003445 if (!getDerived().AlwaysRebuild() &&
3446 TryBlock.get() == S->getTryBlock() &&
3447 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003448 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003449
3450 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003451 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003452}
Mike Stump11289f42009-09-09 15:08:12 +00003453
Douglas Gregorebe10102009-08-20 07:17:43 +00003454//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003455// Expression transformation
3456//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003457template<typename Derived>
3458Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003459TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003460 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003461}
Mike Stump11289f42009-09-09 15:08:12 +00003462
3463template<typename Derived>
3464Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003465TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003466 NestedNameSpecifier *Qualifier = 0;
3467 if (E->getQualifier()) {
3468 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3469 E->getQualifierRange());
3470 if (!Qualifier)
3471 return SemaRef.ExprError();
3472 }
John McCallce546572009-12-08 09:08:17 +00003473
3474 ValueDecl *ND
3475 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003476 if (!ND)
3477 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003478
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003479 if (!getDerived().AlwaysRebuild() &&
3480 Qualifier == E->getQualifier() &&
3481 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003482 !E->hasExplicitTemplateArgumentList()) {
3483
3484 // Mark it referenced in the new context regardless.
3485 // FIXME: this is a bit instantiation-specific.
3486 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3487
Mike Stump11289f42009-09-09 15:08:12 +00003488 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003489 }
John McCallce546572009-12-08 09:08:17 +00003490
3491 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3492 if (E->hasExplicitTemplateArgumentList()) {
3493 TemplateArgs = &TransArgs;
3494 TransArgs.setLAngleLoc(E->getLAngleLoc());
3495 TransArgs.setRAngleLoc(E->getRAngleLoc());
3496 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3497 TemplateArgumentLoc Loc;
3498 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3499 return SemaRef.ExprError();
3500 TransArgs.addArgument(Loc);
3501 }
3502 }
3503
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003504 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003505 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003506}
Mike Stump11289f42009-09-09 15:08:12 +00003507
Douglas Gregora16548e2009-08-11 05:31:07 +00003508template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003509Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003510TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003512}
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregora16548e2009-08-11 05:31:07 +00003514template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003515Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003516TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003517 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003518}
Mike Stump11289f42009-09-09 15:08:12 +00003519
Douglas Gregora16548e2009-08-11 05:31:07 +00003520template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003521Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003522TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003523 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003524}
Mike Stump11289f42009-09-09 15:08:12 +00003525
Douglas Gregora16548e2009-08-11 05:31:07 +00003526template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003527Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003528TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003529 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003530}
Mike Stump11289f42009-09-09 15:08:12 +00003531
Douglas Gregora16548e2009-08-11 05:31:07 +00003532template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003533Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003534TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003535 return SemaRef.Owned(E->Retain());
3536}
3537
3538template<typename Derived>
3539Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003540TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003541 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3542 if (SubExpr.isInvalid())
3543 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003544
Douglas Gregora16548e2009-08-11 05:31:07 +00003545 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003546 return SemaRef.Owned(E->Retain());
3547
3548 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003549 E->getRParen());
3550}
3551
Mike Stump11289f42009-09-09 15:08:12 +00003552template<typename Derived>
3553Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003554TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3555 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003556 if (SubExpr.isInvalid())
3557 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003558
Douglas Gregora16548e2009-08-11 05:31:07 +00003559 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003560 return SemaRef.Owned(E->Retain());
3561
Douglas Gregora16548e2009-08-11 05:31:07 +00003562 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3563 E->getOpcode(),
3564 move(SubExpr));
3565}
Mike Stump11289f42009-09-09 15:08:12 +00003566
Douglas Gregora16548e2009-08-11 05:31:07 +00003567template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003568Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003569TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003570 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003571 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003572
John McCallbcd03502009-12-07 02:54:59 +00003573 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003574 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003575 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003576
John McCall4c98fd82009-11-04 07:28:41 +00003577 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003578 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003579
John McCall4c98fd82009-11-04 07:28:41 +00003580 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003581 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003582 E->getSourceRange());
3583 }
Mike Stump11289f42009-09-09 15:08:12 +00003584
Douglas Gregora16548e2009-08-11 05:31:07 +00003585 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003586 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003587 // C++0x [expr.sizeof]p1:
3588 // The operand is either an expression, which is an unevaluated operand
3589 // [...]
3590 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003591
Douglas Gregora16548e2009-08-11 05:31:07 +00003592 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3593 if (SubExpr.isInvalid())
3594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregora16548e2009-08-11 05:31:07 +00003596 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3597 return SemaRef.Owned(E->Retain());
3598 }
Mike Stump11289f42009-09-09 15:08:12 +00003599
Douglas Gregora16548e2009-08-11 05:31:07 +00003600 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3601 E->isSizeOf(),
3602 E->getSourceRange());
3603}
Mike Stump11289f42009-09-09 15:08:12 +00003604
Douglas Gregora16548e2009-08-11 05:31:07 +00003605template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003606Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003607TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003608 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3609 if (LHS.isInvalid())
3610 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003611
Douglas Gregora16548e2009-08-11 05:31:07 +00003612 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3613 if (RHS.isInvalid())
3614 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003615
3616
Douglas Gregora16548e2009-08-11 05:31:07 +00003617 if (!getDerived().AlwaysRebuild() &&
3618 LHS.get() == E->getLHS() &&
3619 RHS.get() == E->getRHS())
3620 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003621
Douglas Gregora16548e2009-08-11 05:31:07 +00003622 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3623 /*FIXME:*/E->getLHS()->getLocStart(),
3624 move(RHS),
3625 E->getRBracketLoc());
3626}
Mike Stump11289f42009-09-09 15:08:12 +00003627
3628template<typename Derived>
3629Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003630TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003631 // Transform the callee.
3632 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3633 if (Callee.isInvalid())
3634 return SemaRef.ExprError();
3635
3636 // Transform arguments.
3637 bool ArgChanged = false;
3638 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3639 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3640 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3641 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3642 if (Arg.isInvalid())
3643 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003644
Douglas Gregora16548e2009-08-11 05:31:07 +00003645 // FIXME: Wrong source location information for the ','.
3646 FakeCommaLocs.push_back(
3647 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003648
3649 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003650 Args.push_back(Arg.takeAs<Expr>());
3651 }
Mike Stump11289f42009-09-09 15:08:12 +00003652
Douglas Gregora16548e2009-08-11 05:31:07 +00003653 if (!getDerived().AlwaysRebuild() &&
3654 Callee.get() == E->getCallee() &&
3655 !ArgChanged)
3656 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003657
Douglas Gregora16548e2009-08-11 05:31:07 +00003658 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003659 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003660 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3661 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3662 move_arg(Args),
3663 FakeCommaLocs.data(),
3664 E->getRParenLoc());
3665}
Mike Stump11289f42009-09-09 15:08:12 +00003666
3667template<typename Derived>
3668Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003669TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3671 if (Base.isInvalid())
3672 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003674 NestedNameSpecifier *Qualifier = 0;
3675 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003676 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003677 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3678 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003679 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003680 return SemaRef.ExprError();
3681 }
Mike Stump11289f42009-09-09 15:08:12 +00003682
Eli Friedman2cfcef62009-12-04 06:40:45 +00003683 ValueDecl *Member
3684 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003685 if (!Member)
3686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 if (!getDerived().AlwaysRebuild() &&
3689 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003690 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003691 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003692 !E->hasExplicitTemplateArgumentList()) {
3693
3694 // Mark it referenced in the new context regardless.
3695 // FIXME: this is a bit instantiation-specific.
3696 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003697 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003698 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003699
John McCall6b51f282009-11-23 01:53:49 +00003700 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003701 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003702 TransArgs.setLAngleLoc(E->getLAngleLoc());
3703 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003704 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003705 TemplateArgumentLoc Loc;
3706 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003707 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003708 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003709 }
3710 }
3711
Douglas Gregora16548e2009-08-11 05:31:07 +00003712 // FIXME: Bogus source location for the operator
3713 SourceLocation FakeOperatorLoc
3714 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3715
3716 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3717 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003718 Qualifier,
3719 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003720 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003721 Member,
John McCall6b51f282009-11-23 01:53:49 +00003722 (E->hasExplicitTemplateArgumentList()
3723 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003724 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003725}
Mike Stump11289f42009-09-09 15:08:12 +00003726
Douglas Gregora16548e2009-08-11 05:31:07 +00003727template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003728Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003729TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003730 assert(false && "Cannot transform abstract class");
3731 return SemaRef.Owned(E->Retain());
3732}
3733
3734template<typename Derived>
3735Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003736TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003737 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3738 if (LHS.isInvalid())
3739 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003740
Douglas Gregora16548e2009-08-11 05:31:07 +00003741 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3742 if (RHS.isInvalid())
3743 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregora16548e2009-08-11 05:31:07 +00003745 if (!getDerived().AlwaysRebuild() &&
3746 LHS.get() == E->getLHS() &&
3747 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003748 return SemaRef.Owned(E->Retain());
3749
Douglas Gregora16548e2009-08-11 05:31:07 +00003750 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3751 move(LHS), move(RHS));
3752}
3753
Mike Stump11289f42009-09-09 15:08:12 +00003754template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003755Sema::OwningExprResult
3756TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003757 CompoundAssignOperator *E) {
3758 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003759}
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregora16548e2009-08-11 05:31:07 +00003761template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003762Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003763TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003764 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3765 if (Cond.isInvalid())
3766 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregora16548e2009-08-11 05:31:07 +00003768 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3769 if (LHS.isInvalid())
3770 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003771
Douglas Gregora16548e2009-08-11 05:31:07 +00003772 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3773 if (RHS.isInvalid())
3774 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregora16548e2009-08-11 05:31:07 +00003776 if (!getDerived().AlwaysRebuild() &&
3777 Cond.get() == E->getCond() &&
3778 LHS.get() == E->getLHS() &&
3779 RHS.get() == E->getRHS())
3780 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003781
3782 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003783 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003784 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003785 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 move(RHS));
3787}
Mike Stump11289f42009-09-09 15:08:12 +00003788
3789template<typename Derived>
3790Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003791TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003792 // Implicit casts are eliminated during transformation, since they
3793 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003794 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003795}
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797template<typename Derived>
3798Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003799TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003800 assert(false && "Cannot transform abstract class");
3801 return SemaRef.Owned(E->Retain());
3802}
3803
3804template<typename Derived>
3805Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003806TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003807 QualType T;
3808 {
3809 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003810 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003811 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3812 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003813
Douglas Gregora16548e2009-08-11 05:31:07 +00003814 T = getDerived().TransformType(E->getTypeAsWritten());
3815 if (T.isNull())
3816 return SemaRef.ExprError();
3817 }
Mike Stump11289f42009-09-09 15:08:12 +00003818
Douglas Gregor6131b442009-12-12 18:16:41 +00003819 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003820 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003821 if (SubExpr.isInvalid())
3822 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003823
Douglas Gregora16548e2009-08-11 05:31:07 +00003824 if (!getDerived().AlwaysRebuild() &&
3825 T == E->getTypeAsWritten() &&
3826 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003827 return SemaRef.Owned(E->Retain());
3828
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3830 E->getRParenLoc(),
3831 move(SubExpr));
3832}
Mike Stump11289f42009-09-09 15:08:12 +00003833
Douglas Gregora16548e2009-08-11 05:31:07 +00003834template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003835Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003836TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003837 QualType T;
3838 {
3839 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003840 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003841 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3842 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 T = getDerived().TransformType(E->getType());
3845 if (T.isNull())
3846 return SemaRef.ExprError();
3847 }
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3850 if (Init.isInvalid())
3851 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 if (!getDerived().AlwaysRebuild() &&
3854 T == E->getType() &&
3855 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003856 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003857
3858 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3859 /*FIXME:*/E->getInitializer()->getLocEnd(),
3860 move(Init));
3861}
Mike Stump11289f42009-09-09 15:08:12 +00003862
Douglas Gregora16548e2009-08-11 05:31:07 +00003863template<typename Derived>
3864Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003865TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003866 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3867 if (Base.isInvalid())
3868 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003869
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 if (!getDerived().AlwaysRebuild() &&
3871 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003872 return SemaRef.Owned(E->Retain());
3873
Douglas Gregora16548e2009-08-11 05:31:07 +00003874 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003875 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003876 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3877 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3878 E->getAccessorLoc(),
3879 E->getAccessor());
3880}
Mike Stump11289f42009-09-09 15:08:12 +00003881
Douglas Gregora16548e2009-08-11 05:31:07 +00003882template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003883Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003884TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3888 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3889 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3890 if (Init.isInvalid())
3891 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 InitChanged = InitChanged || Init.get() != E->getInit(I);
3894 Inits.push_back(Init.takeAs<Expr>());
3895 }
Mike Stump11289f42009-09-09 15:08:12 +00003896
Douglas Gregora16548e2009-08-11 05:31:07 +00003897 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003898 return SemaRef.Owned(E->Retain());
3899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003901 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregora16548e2009-08-11 05:31:07 +00003904template<typename Derived>
3905Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003906TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003908
Douglas Gregorebe10102009-08-20 07:17:43 +00003909 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003910 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3911 if (Init.isInvalid())
3912 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregorebe10102009-08-20 07:17:43 +00003914 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003915 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3916 bool ExprChanged = false;
3917 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3918 DEnd = E->designators_end();
3919 D != DEnd; ++D) {
3920 if (D->isFieldDesignator()) {
3921 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3922 D->getDotLoc(),
3923 D->getFieldLoc()));
3924 continue;
3925 }
Mike Stump11289f42009-09-09 15:08:12 +00003926
Douglas Gregora16548e2009-08-11 05:31:07 +00003927 if (D->isArrayDesignator()) {
3928 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3929 if (Index.isInvalid())
3930 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003931
3932 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003934
Douglas Gregora16548e2009-08-11 05:31:07 +00003935 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3936 ArrayExprs.push_back(Index.release());
3937 continue;
3938 }
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003941 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3943 if (Start.isInvalid())
3944 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3947 if (End.isInvalid())
3948 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003949
3950 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003951 End.get(),
3952 D->getLBracketLoc(),
3953 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003954
Douglas Gregora16548e2009-08-11 05:31:07 +00003955 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3956 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003957
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 ArrayExprs.push_back(Start.release());
3959 ArrayExprs.push_back(End.release());
3960 }
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 if (!getDerived().AlwaysRebuild() &&
3963 Init.get() == E->getInit() &&
3964 !ExprChanged)
3965 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3968 E->getEqualOrColonLoc(),
3969 E->usesGNUSyntax(), move(Init));
3970}
Mike Stump11289f42009-09-09 15:08:12 +00003971
Douglas Gregora16548e2009-08-11 05:31:07 +00003972template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003973Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003974TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003975 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003976 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3977
3978 // FIXME: Will we ever have proper type location here? Will we actually
3979 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003980 QualType T = getDerived().TransformType(E->getType());
3981 if (T.isNull())
3982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003983
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 if (!getDerived().AlwaysRebuild() &&
3985 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003986 return SemaRef.Owned(E->Retain());
3987
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 return getDerived().RebuildImplicitValueInitExpr(T);
3989}
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003992Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003993TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003994 // FIXME: Do we want the type as written?
3995 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00003996
Douglas Gregora16548e2009-08-11 05:31:07 +00003997 {
3998 // FIXME: Source location isn't quite accurate.
3999 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4000 T = getDerived().TransformType(E->getType());
4001 if (T.isNull())
4002 return SemaRef.ExprError();
4003 }
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4006 if (SubExpr.isInvalid())
4007 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004008
Douglas Gregora16548e2009-08-11 05:31:07 +00004009 if (!getDerived().AlwaysRebuild() &&
4010 T == E->getType() &&
4011 SubExpr.get() == E->getSubExpr())
4012 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregora16548e2009-08-11 05:31:07 +00004014 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4015 T, E->getRParenLoc());
4016}
4017
4018template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004020TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 bool ArgumentChanged = false;
4022 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4023 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4024 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4025 if (Init.isInvalid())
4026 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004027
Douglas Gregora16548e2009-08-11 05:31:07 +00004028 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4029 Inits.push_back(Init.takeAs<Expr>());
4030 }
Mike Stump11289f42009-09-09 15:08:12 +00004031
Douglas Gregora16548e2009-08-11 05:31:07 +00004032 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4033 move_arg(Inits),
4034 E->getRParenLoc());
4035}
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregora16548e2009-08-11 05:31:07 +00004037/// \brief Transform an address-of-label expression.
4038///
4039/// By default, the transformation of an address-of-label expression always
4040/// rebuilds the expression, so that the label identifier can be resolved to
4041/// the corresponding label statement by semantic analysis.
4042template<typename Derived>
4043Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004044TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004045 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4046 E->getLabel());
4047}
Mike Stump11289f42009-09-09 15:08:12 +00004048
4049template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004050Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004051TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004052 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004053 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4054 if (SubStmt.isInvalid())
4055 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004056
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 if (!getDerived().AlwaysRebuild() &&
4058 SubStmt.get() == E->getSubStmt())
4059 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004060
4061 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 move(SubStmt),
4063 E->getRParenLoc());
4064}
Mike Stump11289f42009-09-09 15:08:12 +00004065
Douglas Gregora16548e2009-08-11 05:31:07 +00004066template<typename Derived>
4067Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004068TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004069 QualType T1, T2;
4070 {
4071 // FIXME: Source location isn't quite accurate.
4072 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004073
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 T1 = getDerived().TransformType(E->getArgType1());
4075 if (T1.isNull())
4076 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregora16548e2009-08-11 05:31:07 +00004078 T2 = getDerived().TransformType(E->getArgType2());
4079 if (T2.isNull())
4080 return SemaRef.ExprError();
4081 }
4082
4083 if (!getDerived().AlwaysRebuild() &&
4084 T1 == E->getArgType1() &&
4085 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004086 return SemaRef.Owned(E->Retain());
4087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4089 T1, T2, E->getRParenLoc());
4090}
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregora16548e2009-08-11 05:31:07 +00004092template<typename Derived>
4093Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004094TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004095 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4096 if (Cond.isInvalid())
4097 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregora16548e2009-08-11 05:31:07 +00004099 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4100 if (LHS.isInvalid())
4101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4104 if (RHS.isInvalid())
4105 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004106
Douglas Gregora16548e2009-08-11 05:31:07 +00004107 if (!getDerived().AlwaysRebuild() &&
4108 Cond.get() == E->getCond() &&
4109 LHS.get() == E->getLHS() &&
4110 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004111 return SemaRef.Owned(E->Retain());
4112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4114 move(Cond), move(LHS), move(RHS),
4115 E->getRParenLoc());
4116}
Mike Stump11289f42009-09-09 15:08:12 +00004117
Douglas Gregora16548e2009-08-11 05:31:07 +00004118template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004119Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004120TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004121 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004122}
4123
4124template<typename Derived>
4125Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004126TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004127 switch (E->getOperator()) {
4128 case OO_New:
4129 case OO_Delete:
4130 case OO_Array_New:
4131 case OO_Array_Delete:
4132 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4133 return SemaRef.ExprError();
4134
4135 case OO_Call: {
4136 // This is a call to an object's operator().
4137 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4138
4139 // Transform the object itself.
4140 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4141 if (Object.isInvalid())
4142 return SemaRef.ExprError();
4143
4144 // FIXME: Poor location information
4145 SourceLocation FakeLParenLoc
4146 = SemaRef.PP.getLocForEndOfToken(
4147 static_cast<Expr *>(Object.get())->getLocEnd());
4148
4149 // Transform the call arguments.
4150 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4151 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4152 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004153 if (getDerived().DropCallArgument(E->getArg(I)))
4154 break;
4155
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004156 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4157 if (Arg.isInvalid())
4158 return SemaRef.ExprError();
4159
4160 // FIXME: Poor source location information.
4161 SourceLocation FakeCommaLoc
4162 = SemaRef.PP.getLocForEndOfToken(
4163 static_cast<Expr *>(Arg.get())->getLocEnd());
4164 FakeCommaLocs.push_back(FakeCommaLoc);
4165 Args.push_back(Arg.release());
4166 }
4167
4168 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4169 move_arg(Args),
4170 FakeCommaLocs.data(),
4171 E->getLocEnd());
4172 }
4173
4174#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4175 case OO_##Name:
4176#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4177#include "clang/Basic/OperatorKinds.def"
4178 case OO_Subscript:
4179 // Handled below.
4180 break;
4181
4182 case OO_Conditional:
4183 llvm_unreachable("conditional operator is not actually overloadable");
4184 return SemaRef.ExprError();
4185
4186 case OO_None:
4187 case NUM_OVERLOADED_OPERATORS:
4188 llvm_unreachable("not an overloaded operator?");
4189 return SemaRef.ExprError();
4190 }
4191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4193 if (Callee.isInvalid())
4194 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004195
John McCall47f29ea2009-12-08 09:21:05 +00004196 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 if (First.isInvalid())
4198 return SemaRef.ExprError();
4199
4200 OwningExprResult Second(SemaRef);
4201 if (E->getNumArgs() == 2) {
4202 Second = getDerived().TransformExpr(E->getArg(1));
4203 if (Second.isInvalid())
4204 return SemaRef.ExprError();
4205 }
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 if (!getDerived().AlwaysRebuild() &&
4208 Callee.get() == E->getCallee() &&
4209 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004210 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4211 return SemaRef.Owned(E->Retain());
4212
Douglas Gregora16548e2009-08-11 05:31:07 +00004213 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4214 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004215 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 move(First),
4217 move(Second));
4218}
Mike Stump11289f42009-09-09 15:08:12 +00004219
Douglas Gregora16548e2009-08-11 05:31:07 +00004220template<typename Derived>
4221Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004222TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4223 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004227Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004229 QualType ExplicitTy;
4230 {
4231 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004232 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004233 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4234 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregora16548e2009-08-11 05:31:07 +00004236 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4237 if (ExplicitTy.isNull())
4238 return SemaRef.ExprError();
4239 }
Mike Stump11289f42009-09-09 15:08:12 +00004240
Douglas Gregor6131b442009-12-12 18:16:41 +00004241 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004242 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004243 if (SubExpr.isInvalid())
4244 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregora16548e2009-08-11 05:31:07 +00004246 if (!getDerived().AlwaysRebuild() &&
4247 ExplicitTy == E->getTypeAsWritten() &&
4248 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004249 return SemaRef.Owned(E->Retain());
4250
Douglas Gregora16548e2009-08-11 05:31:07 +00004251 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004252 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4254 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4255 SourceLocation FakeRParenLoc
4256 = SemaRef.PP.getLocForEndOfToken(
4257 E->getSubExpr()->getSourceRange().getEnd());
4258 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004259 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004260 FakeLAngleLoc,
4261 ExplicitTy,
4262 FakeRAngleLoc,
4263 FakeRAngleLoc,
4264 move(SubExpr),
4265 FakeRParenLoc);
4266}
Mike Stump11289f42009-09-09 15:08:12 +00004267
Douglas Gregora16548e2009-08-11 05:31:07 +00004268template<typename Derived>
4269Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004270TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4271 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004272}
Mike Stump11289f42009-09-09 15:08:12 +00004273
4274template<typename Derived>
4275Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004276TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4277 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004278}
4279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280template<typename Derived>
4281Sema::OwningExprResult
4282TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004283 CXXReinterpretCastExpr *E) {
4284 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004285}
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287template<typename Derived>
4288Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004289TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4290 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293template<typename Derived>
4294Sema::OwningExprResult
4295TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004296 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 QualType ExplicitTy;
4298 {
4299 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4302 if (ExplicitTy.isNull())
4303 return SemaRef.ExprError();
4304 }
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregor6131b442009-12-12 18:16:41 +00004306 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004307 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 if (SubExpr.isInvalid())
4309 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 if (!getDerived().AlwaysRebuild() &&
4312 ExplicitTy == E->getTypeAsWritten() &&
4313 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004314 return SemaRef.Owned(E->Retain());
4315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 // FIXME: The end of the type's source range is wrong
4317 return getDerived().RebuildCXXFunctionalCastExpr(
4318 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4319 ExplicitTy,
4320 /*FIXME:*/E->getSubExpr()->getLocStart(),
4321 move(SubExpr),
4322 E->getRParenLoc());
4323}
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325template<typename Derived>
4326Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004327TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 if (E->isTypeOperand()) {
4329 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004330
Douglas Gregora16548e2009-08-11 05:31:07 +00004331 QualType T = getDerived().TransformType(E->getTypeOperand());
4332 if (T.isNull())
4333 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004334
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 if (!getDerived().AlwaysRebuild() &&
4336 T == E->getTypeOperand())
4337 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4340 /*FIXME:*/E->getLocStart(),
4341 T,
4342 E->getLocEnd());
4343 }
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregora16548e2009-08-11 05:31:07 +00004345 // We don't know whether the expression is potentially evaluated until
4346 // after we perform semantic analysis, so the expression is potentially
4347 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004348 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4352 if (SubExpr.isInvalid())
4353 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 if (!getDerived().AlwaysRebuild() &&
4356 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004357 return SemaRef.Owned(E->Retain());
4358
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4360 /*FIXME:*/E->getLocStart(),
4361 move(SubExpr),
4362 E->getLocEnd());
4363}
4364
4365template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004366Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004367TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004368 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004369}
Mike Stump11289f42009-09-09 15:08:12 +00004370
Douglas Gregora16548e2009-08-11 05:31:07 +00004371template<typename Derived>
4372Sema::OwningExprResult
4373TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004374 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004375 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004376}
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378template<typename Derived>
4379Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004380TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383 QualType T = getDerived().TransformType(E->getType());
4384 if (T.isNull())
4385 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004386
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 if (!getDerived().AlwaysRebuild() &&
4388 T == E->getType())
4389 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004390
Douglas Gregorb15af892010-01-07 23:12:05 +00004391 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004392}
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>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004397 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4398 if (SubExpr.isInvalid())
4399 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004400
Douglas Gregora16548e2009-08-11 05:31:07 +00004401 if (!getDerived().AlwaysRebuild() &&
4402 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004403 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004404
4405 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408template<typename Derived>
4409Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004410TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004411 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004412 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4413 if (!Param)
4414 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004415
Douglas Gregora16548e2009-08-11 05:31:07 +00004416 if (getDerived().AlwaysRebuild() &&
4417 Param == E->getParam())
4418 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004419
Douglas Gregor033f6752009-12-23 23:03:06 +00004420 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004421}
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423template<typename Derived>
4424Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004425TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004426 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4427
4428 QualType T = getDerived().TransformType(E->getType());
4429 if (T.isNull())
4430 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004431
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 if (!getDerived().AlwaysRebuild() &&
4433 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004434 return SemaRef.Owned(E->Retain());
4435
4436 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 /*FIXME:*/E->getTypeBeginLoc(),
4438 T,
4439 E->getRParenLoc());
4440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442template<typename Derived>
4443Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004444TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 // Transform the type that we're allocating
4446 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4447 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4448 if (AllocType.isNull())
4449 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 // Transform the size of the array we're allocating (if any).
4452 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4453 if (ArraySize.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 // Transform the placement arguments (if any).
4457 bool ArgumentChanged = false;
4458 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4459 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4460 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4461 if (Arg.isInvalid())
4462 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4465 PlacementArgs.push_back(Arg.take());
4466 }
Mike Stump11289f42009-09-09 15:08:12 +00004467
Douglas Gregorebe10102009-08-20 07:17:43 +00004468 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004469 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4470 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4471 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4472 if (Arg.isInvalid())
4473 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4476 ConstructorArgs.push_back(Arg.take());
4477 }
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 if (!getDerived().AlwaysRebuild() &&
4480 AllocType == E->getAllocatedType() &&
4481 ArraySize.get() == E->getArraySize() &&
4482 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004483 return SemaRef.Owned(E->Retain());
4484
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004485 if (!ArraySize.get()) {
4486 // If no array size was specified, but the new expression was
4487 // instantiated with an array type (e.g., "new T" where T is
4488 // instantiated with "int[4]"), extract the outer bound from the
4489 // array type as our array size. We do this with constant and
4490 // dependently-sized array types.
4491 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4492 if (!ArrayT) {
4493 // Do nothing
4494 } else if (const ConstantArrayType *ConsArrayT
4495 = dyn_cast<ConstantArrayType>(ArrayT)) {
4496 ArraySize
4497 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4498 ConsArrayT->getSize(),
4499 SemaRef.Context.getSizeType(),
4500 /*FIXME:*/E->getLocStart()));
4501 AllocType = ConsArrayT->getElementType();
4502 } else if (const DependentSizedArrayType *DepArrayT
4503 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4504 if (DepArrayT->getSizeExpr()) {
4505 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4506 AllocType = DepArrayT->getElementType();
4507 }
4508 }
4509 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004510 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4511 E->isGlobalNew(),
4512 /*FIXME:*/E->getLocStart(),
4513 move_arg(PlacementArgs),
4514 /*FIXME:*/E->getLocStart(),
4515 E->isParenTypeId(),
4516 AllocType,
4517 /*FIXME:*/E->getLocStart(),
4518 /*FIXME:*/SourceRange(),
4519 move(ArraySize),
4520 /*FIXME:*/E->getLocStart(),
4521 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004522 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004523}
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregora16548e2009-08-11 05:31:07 +00004525template<typename Derived>
4526Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004527TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004528 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4529 if (Operand.isInvalid())
4530 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004533 Operand.get() == E->getArgument())
4534 return SemaRef.Owned(E->Retain());
4535
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4537 E->isGlobalDelete(),
4538 E->isArrayForm(),
4539 move(Operand));
4540}
Mike Stump11289f42009-09-09 15:08:12 +00004541
Douglas Gregora16548e2009-08-11 05:31:07 +00004542template<typename Derived>
4543Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004544TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004545 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004546 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4547 if (Base.isInvalid())
4548 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004549
Douglas Gregorad8a3362009-09-04 17:36:40 +00004550 NestedNameSpecifier *Qualifier
4551 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4552 E->getQualifierRange());
4553 if (E->getQualifier() && !Qualifier)
4554 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004555
Douglas Gregorad8a3362009-09-04 17:36:40 +00004556 QualType DestroyedType;
4557 {
4558 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4559 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4560 if (DestroyedType.isNull())
4561 return SemaRef.ExprError();
4562 }
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregorad8a3362009-09-04 17:36:40 +00004564 if (!getDerived().AlwaysRebuild() &&
4565 Base.get() == E->getBase() &&
4566 Qualifier == E->getQualifier() &&
4567 DestroyedType == E->getDestroyedType())
4568 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004569
Douglas Gregorad8a3362009-09-04 17:36:40 +00004570 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4571 E->getOperatorLoc(),
4572 E->isArrow(),
4573 E->getDestroyedTypeLoc(),
4574 DestroyedType,
4575 Qualifier,
4576 E->getQualifierRange());
4577}
Mike Stump11289f42009-09-09 15:08:12 +00004578
Douglas Gregorad8a3362009-09-04 17:36:40 +00004579template<typename Derived>
4580Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004581TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004582 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004583 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4584
4585 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4586 Sema::LookupOrdinaryName);
4587
4588 // Transform all the decls.
4589 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4590 E = Old->decls_end(); I != E; ++I) {
4591 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004592 if (!InstD) {
4593 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4594 // This can happen because of dependent hiding.
4595 if (isa<UsingShadowDecl>(*I))
4596 continue;
4597 else
4598 return SemaRef.ExprError();
4599 }
John McCalle66edc12009-11-24 19:00:30 +00004600
4601 // Expand using declarations.
4602 if (isa<UsingDecl>(InstD)) {
4603 UsingDecl *UD = cast<UsingDecl>(InstD);
4604 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4605 E = UD->shadow_end(); I != E; ++I)
4606 R.addDecl(*I);
4607 continue;
4608 }
4609
4610 R.addDecl(InstD);
4611 }
4612
4613 // Resolve a kind, but don't do any further analysis. If it's
4614 // ambiguous, the callee needs to deal with it.
4615 R.resolveKind();
4616
4617 // Rebuild the nested-name qualifier, if present.
4618 CXXScopeSpec SS;
4619 NestedNameSpecifier *Qualifier = 0;
4620 if (Old->getQualifier()) {
4621 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4622 Old->getQualifierRange());
4623 if (!Qualifier)
4624 return SemaRef.ExprError();
4625
4626 SS.setScopeRep(Qualifier);
4627 SS.setRange(Old->getQualifierRange());
4628 }
4629
4630 // If we have no template arguments, it's a normal declaration name.
4631 if (!Old->hasExplicitTemplateArgs())
4632 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4633
4634 // If we have template arguments, rebuild them, then rebuild the
4635 // templateid expression.
4636 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4637 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4638 TemplateArgumentLoc Loc;
4639 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4640 return SemaRef.ExprError();
4641 TransArgs.addArgument(Loc);
4642 }
4643
4644 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4645 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004646}
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648template<typename Derived>
4649Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004650TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004652
Douglas Gregora16548e2009-08-11 05:31:07 +00004653 QualType T = getDerived().TransformType(E->getQueriedType());
4654 if (T.isNull())
4655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 if (!getDerived().AlwaysRebuild() &&
4658 T == E->getQueriedType())
4659 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004660
Douglas Gregora16548e2009-08-11 05:31:07 +00004661 // FIXME: Bad location information
4662 SourceLocation FakeLParenLoc
4663 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004664
4665 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 E->getLocStart(),
4667 /*FIXME:*/FakeLParenLoc,
4668 T,
4669 E->getLocEnd());
4670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672template<typename Derived>
4673Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004674TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004675 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004677 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4678 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004679 if (!NNS)
4680 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004681
4682 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004683 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4684 if (!Name)
4685 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004686
John McCalle66edc12009-11-24 19:00:30 +00004687 if (!E->hasExplicitTemplateArgs()) {
4688 if (!getDerived().AlwaysRebuild() &&
4689 NNS == E->getQualifier() &&
4690 Name == E->getDeclName())
4691 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004692
John McCalle66edc12009-11-24 19:00:30 +00004693 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4694 E->getQualifierRange(),
4695 Name, E->getLocation(),
4696 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004697 }
John McCall6b51f282009-11-23 01:53:49 +00004698
4699 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004701 TemplateArgumentLoc Loc;
4702 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004703 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004704 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 }
4706
John McCalle66edc12009-11-24 19:00:30 +00004707 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4708 E->getQualifierRange(),
4709 Name, E->getLocation(),
4710 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004711}
4712
4713template<typename Derived>
4714Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004715TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004716 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4717
4718 QualType T = getDerived().TransformType(E->getType());
4719 if (T.isNull())
4720 return SemaRef.ExprError();
4721
4722 CXXConstructorDecl *Constructor
4723 = cast_or_null<CXXConstructorDecl>(
4724 getDerived().TransformDecl(E->getConstructor()));
4725 if (!Constructor)
4726 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 bool ArgumentChanged = false;
4729 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004730 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004731 ArgEnd = E->arg_end();
4732 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004733 if (getDerived().DropCallArgument(*Arg)) {
4734 ArgumentChanged = true;
4735 break;
4736 }
4737
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4739 if (TransArg.isInvalid())
4740 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4743 Args.push_back(TransArg.takeAs<Expr>());
4744 }
4745
4746 if (!getDerived().AlwaysRebuild() &&
4747 T == E->getType() &&
4748 Constructor == E->getConstructor() &&
4749 !ArgumentChanged)
4750 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregordb121ba2009-12-14 16:27:04 +00004752 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4753 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 move_arg(Args));
4755}
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregora16548e2009-08-11 05:31:07 +00004757/// \brief Transform a C++ temporary-binding expression.
4758///
Douglas Gregor363b1512009-12-24 18:51:59 +00004759/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4760/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004761template<typename Derived>
4762Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004763TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004764 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004765}
Mike Stump11289f42009-09-09 15:08:12 +00004766
4767/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004768/// be destroyed after the expression is evaluated.
4769///
Douglas Gregor363b1512009-12-24 18:51:59 +00004770/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4771/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004772template<typename Derived>
4773Sema::OwningExprResult
4774TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004775 CXXExprWithTemporaries *E) {
4776 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004777}
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779template<typename Derived>
4780Sema::OwningExprResult
4781TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004782 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004783 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4784 QualType T = getDerived().TransformType(E->getType());
4785 if (T.isNull())
4786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788 CXXConstructorDecl *Constructor
4789 = cast_or_null<CXXConstructorDecl>(
4790 getDerived().TransformDecl(E->getConstructor()));
4791 if (!Constructor)
4792 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 bool ArgumentChanged = false;
4795 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4796 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004797 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 ArgEnd = E->arg_end();
4799 Arg != ArgEnd; ++Arg) {
4800 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4801 if (TransArg.isInvalid())
4802 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004803
Douglas Gregora16548e2009-08-11 05:31:07 +00004804 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4805 Args.push_back((Expr *)TransArg.release());
4806 }
Mike Stump11289f42009-09-09 15:08:12 +00004807
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 if (!getDerived().AlwaysRebuild() &&
4809 T == E->getType() &&
4810 Constructor == E->getConstructor() &&
4811 !ArgumentChanged)
4812 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814 // FIXME: Bogus location information
4815 SourceLocation CommaLoc;
4816 if (Args.size() > 1) {
4817 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004818 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004819 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4820 }
4821 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4822 T,
4823 /*FIXME:*/E->getTypeBeginLoc(),
4824 move_arg(Args),
4825 &CommaLoc,
4826 E->getLocEnd());
4827}
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora16548e2009-08-11 05:31:07 +00004829template<typename Derived>
4830Sema::OwningExprResult
4831TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004832 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004833 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4834 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4835 if (T.isNull())
4836 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004837
Douglas Gregora16548e2009-08-11 05:31:07 +00004838 bool ArgumentChanged = false;
4839 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4840 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4841 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4842 ArgEnd = E->arg_end();
4843 Arg != ArgEnd; ++Arg) {
4844 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4845 if (TransArg.isInvalid())
4846 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004847
Douglas Gregora16548e2009-08-11 05:31:07 +00004848 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4849 FakeCommaLocs.push_back(
4850 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4851 Args.push_back(TransArg.takeAs<Expr>());
4852 }
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 if (!getDerived().AlwaysRebuild() &&
4855 T == E->getTypeAsWritten() &&
4856 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004857 return SemaRef.Owned(E->Retain());
4858
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 // FIXME: we're faking the locations of the commas
4860 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4861 T,
4862 E->getLParenLoc(),
4863 move_arg(Args),
4864 FakeCommaLocs.data(),
4865 E->getRParenLoc());
4866}
Mike Stump11289f42009-09-09 15:08:12 +00004867
Douglas Gregora16548e2009-08-11 05:31:07 +00004868template<typename Derived>
4869Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004870TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004871 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004873 OwningExprResult Base(SemaRef, (Expr*) 0);
4874 Expr *OldBase;
4875 QualType BaseType;
4876 QualType ObjectType;
4877 if (!E->isImplicitAccess()) {
4878 OldBase = E->getBase();
4879 Base = getDerived().TransformExpr(OldBase);
4880 if (Base.isInvalid())
4881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004882
John McCall2d74de92009-12-01 22:10:20 +00004883 // Start the member reference and compute the object's type.
4884 Sema::TypeTy *ObjectTy = 0;
4885 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4886 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004887 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004888 ObjectTy);
4889 if (Base.isInvalid())
4890 return SemaRef.ExprError();
4891
4892 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4893 BaseType = ((Expr*) Base.get())->getType();
4894 } else {
4895 OldBase = 0;
4896 BaseType = getDerived().TransformType(E->getBaseType());
4897 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4898 }
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004900 // Transform the first part of the nested-name-specifier that qualifies
4901 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004902 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004903 = getDerived().TransformFirstQualifierInScope(
4904 E->getFirstQualifierFoundInScope(),
4905 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004907 NestedNameSpecifier *Qualifier = 0;
4908 if (E->getQualifier()) {
4909 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4910 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004911 ObjectType,
4912 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004913 if (!Qualifier)
4914 return SemaRef.ExprError();
4915 }
Mike Stump11289f42009-09-09 15:08:12 +00004916
4917 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004918 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004919 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004920 if (!Name)
4921 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004922
John McCall2d74de92009-12-01 22:10:20 +00004923 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004924 // This is a reference to a member without an explicitly-specified
4925 // template argument list. Optimize for this common case.
4926 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004927 Base.get() == OldBase &&
4928 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004929 Qualifier == E->getQualifier() &&
4930 Name == E->getMember() &&
4931 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004932 return SemaRef.Owned(E->Retain());
4933
John McCall8cd78132009-11-19 22:55:06 +00004934 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004935 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004936 E->isArrow(),
4937 E->getOperatorLoc(),
4938 Qualifier,
4939 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004940 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004941 Name,
4942 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004943 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004944 }
4945
John McCall6b51f282009-11-23 01:53:49 +00004946 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004947 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004948 TemplateArgumentLoc Loc;
4949 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004950 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004951 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004952 }
Mike Stump11289f42009-09-09 15:08:12 +00004953
John McCall8cd78132009-11-19 22:55:06 +00004954 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004955 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 E->isArrow(),
4957 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004958 Qualifier,
4959 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004960 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004961 Name,
4962 E->getMemberLoc(),
4963 &TransArgs);
4964}
4965
4966template<typename Derived>
4967Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004968TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004969 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004970 OwningExprResult Base(SemaRef, (Expr*) 0);
4971 QualType BaseType;
4972 if (!Old->isImplicitAccess()) {
4973 Base = getDerived().TransformExpr(Old->getBase());
4974 if (Base.isInvalid())
4975 return SemaRef.ExprError();
4976 BaseType = ((Expr*) Base.get())->getType();
4977 } else {
4978 BaseType = getDerived().TransformType(Old->getBaseType());
4979 }
John McCall10eae182009-11-30 22:42:35 +00004980
4981 NestedNameSpecifier *Qualifier = 0;
4982 if (Old->getQualifier()) {
4983 Qualifier
4984 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4985 Old->getQualifierRange());
4986 if (Qualifier == 0)
4987 return SemaRef.ExprError();
4988 }
4989
4990 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
4991 Sema::LookupOrdinaryName);
4992
4993 // Transform all the decls.
4994 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
4995 E = Old->decls_end(); I != E; ++I) {
4996 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004997 if (!InstD) {
4998 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4999 // This can happen because of dependent hiding.
5000 if (isa<UsingShadowDecl>(*I))
5001 continue;
5002 else
5003 return SemaRef.ExprError();
5004 }
John McCall10eae182009-11-30 22:42:35 +00005005
5006 // Expand using declarations.
5007 if (isa<UsingDecl>(InstD)) {
5008 UsingDecl *UD = cast<UsingDecl>(InstD);
5009 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5010 E = UD->shadow_end(); I != E; ++I)
5011 R.addDecl(*I);
5012 continue;
5013 }
5014
5015 R.addDecl(InstD);
5016 }
5017
5018 R.resolveKind();
5019
5020 TemplateArgumentListInfo TransArgs;
5021 if (Old->hasExplicitTemplateArgs()) {
5022 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5023 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5024 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5025 TemplateArgumentLoc Loc;
5026 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5027 Loc))
5028 return SemaRef.ExprError();
5029 TransArgs.addArgument(Loc);
5030 }
5031 }
5032
5033 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005034 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005035 Old->getOperatorLoc(),
5036 Old->isArrow(),
5037 Qualifier,
5038 Old->getQualifierRange(),
5039 R,
5040 (Old->hasExplicitTemplateArgs()
5041 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005042}
5043
5044template<typename Derived>
5045Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005046TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005047 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005048}
5049
Mike Stump11289f42009-09-09 15:08:12 +00005050template<typename Derived>
5051Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005052TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 // FIXME: poor source location
5054 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5055 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5056 if (EncodedType.isNull())
5057 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 if (!getDerived().AlwaysRebuild() &&
5060 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005061 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005062
5063 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5064 EncodedType,
5065 E->getRParenLoc());
5066}
Mike Stump11289f42009-09-09 15:08:12 +00005067
Douglas Gregora16548e2009-08-11 05:31:07 +00005068template<typename Derived>
5069Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 // FIXME: Implement this!
5072 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005073 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005074}
5075
Mike Stump11289f42009-09-09 15:08:12 +00005076template<typename Derived>
5077Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005079 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
5081
Mike Stump11289f42009-09-09 15:08:12 +00005082template<typename Derived>
5083Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005084TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005085 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 = cast_or_null<ObjCProtocolDecl>(
5087 getDerived().TransformDecl(E->getProtocol()));
5088 if (!Protocol)
5089 return SemaRef.ExprError();
5090
5091 if (!getDerived().AlwaysRebuild() &&
5092 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005093 return SemaRef.Owned(E->Retain());
5094
Douglas Gregora16548e2009-08-11 05:31:07 +00005095 return getDerived().RebuildObjCProtocolExpr(Protocol,
5096 E->getAtLoc(),
5097 /*FIXME:*/E->getAtLoc(),
5098 /*FIXME:*/E->getAtLoc(),
5099 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101}
5102
Mike Stump11289f42009-09-09 15:08:12 +00005103template<typename Derived>
5104Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005105TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005106 // FIXME: Implement this!
5107 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005108 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005109}
5110
Mike Stump11289f42009-09-09 15:08:12 +00005111template<typename Derived>
5112Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005113TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 // FIXME: Implement this!
5115 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005116 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005117}
5118
Mike Stump11289f42009-09-09 15:08:12 +00005119template<typename Derived>
5120Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005121TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005122 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005123 // FIXME: Implement this!
5124 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005125 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005126}
5127
Mike Stump11289f42009-09-09 15:08:12 +00005128template<typename Derived>
5129Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005130TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 // FIXME: Implement this!
5132 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005133 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005134}
5135
Mike Stump11289f42009-09-09 15:08:12 +00005136template<typename Derived>
5137Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005138TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005139 // FIXME: Implement this!
5140 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005141 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005142}
5143
Mike Stump11289f42009-09-09 15:08:12 +00005144template<typename Derived>
5145Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005146TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005147 bool ArgumentChanged = false;
5148 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5149 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5150 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5151 if (SubExpr.isInvalid())
5152 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregora16548e2009-08-11 05:31:07 +00005154 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5155 SubExprs.push_back(SubExpr.takeAs<Expr>());
5156 }
Mike Stump11289f42009-09-09 15:08:12 +00005157
Douglas Gregora16548e2009-08-11 05:31:07 +00005158 if (!getDerived().AlwaysRebuild() &&
5159 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005160 return SemaRef.Owned(E->Retain());
5161
Douglas Gregora16548e2009-08-11 05:31:07 +00005162 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5163 move_arg(SubExprs),
5164 E->getRParenLoc());
5165}
5166
Mike Stump11289f42009-09-09 15:08:12 +00005167template<typename Derived>
5168Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005169TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005170 // FIXME: Implement this!
5171 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005172 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005173}
5174
Mike Stump11289f42009-09-09 15:08:12 +00005175template<typename Derived>
5176Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005177TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005178 // FIXME: Implement this!
5179 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005180 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005181}
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184// Type reconstruction
5185//===----------------------------------------------------------------------===//
5186
Mike Stump11289f42009-09-09 15:08:12 +00005187template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005188QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5189 SourceLocation Star) {
5190 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005191 getDerived().getBaseEntity());
5192}
5193
Mike Stump11289f42009-09-09 15:08:12 +00005194template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005195QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5196 SourceLocation Star) {
5197 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005198 getDerived().getBaseEntity());
5199}
5200
Mike Stump11289f42009-09-09 15:08:12 +00005201template<typename Derived>
5202QualType
John McCall70dd5f62009-10-30 00:06:24 +00005203TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5204 bool WrittenAsLValue,
5205 SourceLocation Sigil) {
5206 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5207 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005208}
5209
5210template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005211QualType
John McCall70dd5f62009-10-30 00:06:24 +00005212TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5213 QualType ClassType,
5214 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005215 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005216 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005217}
5218
5219template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005220QualType
John McCall70dd5f62009-10-30 00:06:24 +00005221TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5222 SourceLocation Sigil) {
5223 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005224 getDerived().getBaseEntity());
5225}
5226
5227template<typename Derived>
5228QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5230 ArrayType::ArraySizeModifier SizeMod,
5231 const llvm::APInt *Size,
5232 Expr *SizeExpr,
5233 unsigned IndexTypeQuals,
5234 SourceRange BracketsRange) {
5235 if (SizeExpr || !Size)
5236 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5237 IndexTypeQuals, BracketsRange,
5238 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005239
5240 QualType Types[] = {
5241 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5242 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5243 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005244 };
5245 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5246 QualType SizeType;
5247 for (unsigned I = 0; I != NumTypes; ++I)
5248 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5249 SizeType = Types[I];
5250 break;
5251 }
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005254 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005256 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005257}
Mike Stump11289f42009-09-09 15:08:12 +00005258
Douglas Gregord6ff3322009-08-04 16:50:30 +00005259template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005260QualType
5261TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005262 ArrayType::ArraySizeModifier SizeMod,
5263 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005264 unsigned IndexTypeQuals,
5265 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005266 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005267 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005268}
5269
5270template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005271QualType
Mike Stump11289f42009-09-09 15:08:12 +00005272TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005273 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005274 unsigned IndexTypeQuals,
5275 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005276 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005277 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005278}
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005281QualType
5282TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005283 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005284 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005285 unsigned IndexTypeQuals,
5286 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005287 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005288 SizeExpr.takeAs<Expr>(),
5289 IndexTypeQuals, BracketsRange);
5290}
5291
5292template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005293QualType
5294TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005295 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005296 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005297 unsigned IndexTypeQuals,
5298 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005299 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005300 SizeExpr.takeAs<Expr>(),
5301 IndexTypeQuals, BracketsRange);
5302}
5303
5304template<typename Derived>
5305QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5306 unsigned NumElements) {
5307 // FIXME: semantic checking!
5308 return SemaRef.Context.getVectorType(ElementType, NumElements);
5309}
Mike Stump11289f42009-09-09 15:08:12 +00005310
Douglas Gregord6ff3322009-08-04 16:50:30 +00005311template<typename Derived>
5312QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5313 unsigned NumElements,
5314 SourceLocation AttributeLoc) {
5315 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5316 NumElements, true);
5317 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005318 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005319 AttributeLoc);
5320 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5321 AttributeLoc);
5322}
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregord6ff3322009-08-04 16:50:30 +00005324template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005325QualType
5326TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005327 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005328 SourceLocation AttributeLoc) {
5329 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5330}
Mike Stump11289f42009-09-09 15:08:12 +00005331
Douglas Gregord6ff3322009-08-04 16:50:30 +00005332template<typename Derived>
5333QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005334 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005335 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005336 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005338 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005339 Quals,
5340 getDerived().getBaseLocation(),
5341 getDerived().getBaseEntity());
5342}
Mike Stump11289f42009-09-09 15:08:12 +00005343
Douglas Gregord6ff3322009-08-04 16:50:30 +00005344template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005345QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5346 return SemaRef.Context.getFunctionNoProtoType(T);
5347}
5348
5349template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005350QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5351 assert(D && "no decl found");
5352 if (D->isInvalidDecl()) return QualType();
5353
5354 TypeDecl *Ty;
5355 if (isa<UsingDecl>(D)) {
5356 UsingDecl *Using = cast<UsingDecl>(D);
5357 assert(Using->isTypeName() &&
5358 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5359
5360 // A valid resolved using typename decl points to exactly one type decl.
5361 assert(++Using->shadow_begin() == Using->shadow_end());
5362 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5363
5364 } else {
5365 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5366 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5367 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5368 }
5369
5370 return SemaRef.Context.getTypeDeclType(Ty);
5371}
5372
5373template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005374QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005375 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5376}
5377
5378template<typename Derived>
5379QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5380 return SemaRef.Context.getTypeOfType(Underlying);
5381}
5382
5383template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005384QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005385 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5386}
5387
5388template<typename Derived>
5389QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005390 TemplateName Template,
5391 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005392 const TemplateArgumentListInfo &TemplateArgs) {
5393 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregor1135c352009-08-06 05:28:30 +00005396template<typename Derived>
5397NestedNameSpecifier *
5398TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5399 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005400 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005401 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005402 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005403 CXXScopeSpec SS;
5404 // FIXME: The source location information is all wrong.
5405 SS.setRange(Range);
5406 SS.setScopeRep(Prefix);
5407 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005408 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005409 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005410 ObjectType,
5411 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005412 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005413}
5414
5415template<typename Derived>
5416NestedNameSpecifier *
5417TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5418 SourceRange Range,
5419 NamespaceDecl *NS) {
5420 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5421}
5422
5423template<typename Derived>
5424NestedNameSpecifier *
5425TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5426 SourceRange Range,
5427 bool TemplateKW,
5428 QualType T) {
5429 if (T->isDependentType() || T->isRecordType() ||
5430 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005431 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005432 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5433 T.getTypePtr());
5434 }
Mike Stump11289f42009-09-09 15:08:12 +00005435
Douglas Gregor1135c352009-08-06 05:28:30 +00005436 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5437 return 0;
5438}
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregor71dc5092009-08-06 06:41:21 +00005440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005441TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005442TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5443 bool TemplateKW,
5444 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005445 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005446 Template);
5447}
5448
5449template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005450TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005451TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005452 const IdentifierInfo &II,
5453 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005454 CXXScopeSpec SS;
5455 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005456 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005457 UnqualifiedId Name;
5458 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005459 return getSema().ActOnDependentTemplateName(
5460 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005461 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005462 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005463 ObjectType.getAsOpaquePtr(),
5464 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005465 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005466}
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005469TemplateName
5470TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5471 OverloadedOperatorKind Operator,
5472 QualType ObjectType) {
5473 CXXScopeSpec SS;
5474 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5475 SS.setScopeRep(Qualifier);
5476 UnqualifiedId Name;
5477 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5478 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5479 Operator, SymbolLocations);
5480 return getSema().ActOnDependentTemplateName(
5481 /*FIXME:*/getDerived().getBaseLocation(),
5482 SS,
5483 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005484 ObjectType.getAsOpaquePtr(),
5485 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005486 .template getAsVal<TemplateName>();
5487}
5488
5489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005490Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005491TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5492 SourceLocation OpLoc,
5493 ExprArg Callee,
5494 ExprArg First,
5495 ExprArg Second) {
5496 Expr *FirstExpr = (Expr *)First.get();
5497 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005498 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005500
Douglas Gregora16548e2009-08-11 05:31:07 +00005501 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005502 if (Op == OO_Subscript) {
5503 if (!FirstExpr->getType()->isOverloadableType() &&
5504 !SecondExpr->getType()->isOverloadableType())
5505 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005506 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005507 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005508 } else if (Op == OO_Arrow) {
5509 // -> is never a builtin operation.
5510 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005511 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (!FirstExpr->getType()->isOverloadableType()) {
5513 // The argument is not of overloadable type, so try to create a
5514 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005515 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005517
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5519 }
5520 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005521 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 !SecondExpr->getType()->isOverloadableType()) {
5523 // Neither of the arguments is an overloadable type, so try to
5524 // create a built-in binary operation.
5525 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005526 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5528 if (Result.isInvalid())
5529 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005530
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 First.release();
5532 Second.release();
5533 return move(Result);
5534 }
5535 }
Mike Stump11289f42009-09-09 15:08:12 +00005536
5537 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005538 // used during overload resolution.
5539 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005540
John McCalld14a8642009-11-21 08:51:07 +00005541 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5542 assert(ULE->requiresADL());
5543
5544 // FIXME: Do we have to check
5545 // IsAcceptableNonMemberOperatorCandidate for each of these?
5546 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5547 E = ULE->decls_end(); I != E; ++I)
5548 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5549 } else {
5550 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5551 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5552 }
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 // Add any functions found via argument-dependent lookup.
5555 Expr *Args[2] = { FirstExpr, SecondExpr };
5556 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005557 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005559 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5560 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005561
Douglas Gregora16548e2009-08-11 05:31:07 +00005562 // Create the overloaded operator invocation for unary operators.
5563 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005564 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005565 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5566 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5567 }
Mike Stump11289f42009-09-09 15:08:12 +00005568
Sebastian Redladba46e2009-10-29 20:17:01 +00005569 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005570 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5571 OpLoc,
5572 move(First),
5573 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005574
Douglas Gregora16548e2009-08-11 05:31:07 +00005575 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005576 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005578 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5580 if (Result.isInvalid())
5581 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 First.release();
5584 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005585 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005586}
Mike Stump11289f42009-09-09 15:08:12 +00005587
Douglas Gregord6ff3322009-08-04 16:50:30 +00005588} // end namespace clang
5589
5590#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H