blob: 11c19eb23ce1eddf2e859b5baa284bbc952b0c08 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
240 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000268 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000269 QualType ObjectType = QualType(),
270 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000271
Douglas Gregorf816bd72009-09-03 22:13:48 +0000272 /// \brief Transform the given declaration name.
273 ///
274 /// By default, transforms the types of conversion function, constructor,
275 /// and destructor names and then (if needed) rebuilds the declaration name.
276 /// Identifiers and selectors are returned unmodified. Sublcasses may
277 /// override this function to provide alternate behavior.
278 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000279 SourceLocation Loc,
280 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000281
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000283 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000284 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000285 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000286 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000287 TemplateName TransformTemplateName(TemplateName Name,
288 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000289
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 /// \brief Transform the given template argument.
291 ///
Mike Stump11289f42009-09-09 15:08:12 +0000292 /// By default, this operation transforms the type, expression, or
293 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000294 /// new template argument from the transformed result. Subclasses may
295 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000296 ///
297 /// Returns true if there was an error.
298 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
299 TemplateArgumentLoc &Output);
300
301 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
302 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
303 TemplateArgumentLoc &ArgLoc);
304
John McCallbcd03502009-12-07 02:54:59 +0000305 /// \brief Fakes up a TypeSourceInfo for a type.
306 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
307 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000308 getDerived().getBaseLocation());
309 }
Mike Stump11289f42009-09-09 15:08:12 +0000310
John McCall550e0c22009-10-21 00:40:46 +0000311#define ABSTRACT_TYPELOC(CLASS, PARENT)
312#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000313 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
314 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000315#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000316
Douglas Gregorfe17d252010-02-16 19:09:40 +0000317 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
318 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000319
Douglas Gregorc59e5612009-10-19 22:04:39 +0000320 QualType
321 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
322 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +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.
John Thompson22334602010-02-05 00:12:22 +0000431 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
432 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000433
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 /// \brief Build a new extended vector type given the element type and
435 /// number of elements.
436 ///
437 /// By default, performs semantic analysis when building the vector type.
438 /// Subclasses may override this routine to provide different behavior.
439 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
440 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000441
442 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 /// given the element type and number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000447 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000448 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000449 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Build a new function type.
452 ///
453 /// By default, performs semantic analysis when building the function type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000456 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000457 unsigned NumParamTypes,
458 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000459
John McCall550e0c22009-10-21 00:40:46 +0000460 /// \brief Build a new unprototyped function type.
461 QualType RebuildFunctionNoProtoType(QualType ResultType);
462
John McCallb96ec562009-12-04 22:46:56 +0000463 /// \brief Rebuild an unresolved typename type, given the decl that
464 /// the UnresolvedUsingTypenameDecl was transformed to.
465 QualType RebuildUnresolvedUsingType(Decl *D);
466
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467 /// \brief Build a new typedef type.
468 QualType RebuildTypedefType(TypedefDecl *Typedef) {
469 return SemaRef.Context.getTypeDeclType(Typedef);
470 }
471
472 /// \brief Build a new class/struct/union type.
473 QualType RebuildRecordType(RecordDecl *Record) {
474 return SemaRef.Context.getTypeDeclType(Record);
475 }
476
477 /// \brief Build a new Enum type.
478 QualType RebuildEnumType(EnumDecl *Enum) {
479 return SemaRef.Context.getTypeDeclType(Enum);
480 }
John McCallfcc33b02009-09-05 00:15:47 +0000481
482 /// \brief Build a new elaborated type.
483 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
484 return SemaRef.Context.getElaboratedType(T, Tag);
485 }
Mike Stump11289f42009-09-09 15:08:12 +0000486
487 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 ///
489 /// By default, performs semantic analysis when building the typeof type.
490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000491 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000492
Mike Stump11289f42009-09-09 15:08:12 +0000493 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000494 ///
495 /// By default, builds a new TypeOfType with the given underlying type.
496 QualType RebuildTypeOfType(QualType Underlying);
497
Mike Stump11289f42009-09-09 15:08:12 +0000498 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000499 ///
500 /// By default, performs semantic analysis when building the decltype type.
501 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000502 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000503
Douglas Gregord6ff3322009-08-04 16:50:30 +0000504 /// \brief Build a new template specialization type.
505 ///
506 /// By default, performs semantic analysis when building the template
507 /// specialization type. Subclasses may override this routine to provide
508 /// different behavior.
509 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000510 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000511 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000512
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// \brief Build a new qualified name type.
514 ///
Mike Stump11289f42009-09-09 15:08:12 +0000515 /// By default, builds a new QualifiedNameType type from the
516 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// this routine to provide different behavior.
518 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
519 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000520 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521
522 /// \brief Build a new typename type that refers to a template-id.
523 ///
524 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000525 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// different behavior.
527 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000528 if (NNS->isDependent()) {
529 CXXScopeSpec SS;
530 SS.setScopeRep(NNS);
531 if (!SemaRef.computeDeclContext(SS))
532 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000533 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000534 }
Mike Stump11289f42009-09-09 15:08:12 +0000535
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000537 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000538
539 /// \brief Build a new typename type that refers to an identifier.
540 ///
541 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000542 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000544 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000545 const IdentifierInfo *Id,
546 SourceRange SR) {
547 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000548 }
Mike Stump11289f42009-09-09 15:08:12 +0000549
Douglas Gregor1135c352009-08-06 05:28:30 +0000550 /// \brief Build a new nested-name-specifier given the prefix and an
551 /// identifier that names the next step in the nested-name-specifier.
552 ///
553 /// By default, performs semantic analysis when building the new
554 /// nested-name-specifier. Subclasses may override this routine to provide
555 /// different behavior.
556 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
557 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000558 IdentifierInfo &II,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000559 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000560 QualType ObjectType,
561 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000562
563 /// \brief Build a new nested-name-specifier given the prefix and the
564 /// namespace named in the next step in the nested-name-specifier.
565 ///
566 /// By default, performs semantic analysis when building the new
567 /// nested-name-specifier. Subclasses may override this routine to provide
568 /// different behavior.
569 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
570 SourceRange Range,
571 NamespaceDecl *NS);
572
573 /// \brief Build a new nested-name-specifier given the prefix and the
574 /// type named in the next step in the nested-name-specifier.
575 ///
576 /// By default, performs semantic analysis when building the new
577 /// nested-name-specifier. Subclasses may override this routine to provide
578 /// different behavior.
579 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
580 SourceRange Range,
581 bool TemplateKW,
Douglas Gregor90d554e2010-02-21 18:36:56 +0000582 QualType T,
583 bool MayBePseudoDestructor);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000584
585 /// \brief Build a new template name given a nested name specifier, a flag
586 /// indicating whether the "template" keyword was provided, and the template
587 /// that the template name refers to.
588 ///
589 /// By default, builds the new template name directly. Subclasses may override
590 /// this routine to provide different behavior.
591 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
592 bool TemplateKW,
593 TemplateDecl *Template);
594
Douglas Gregor71dc5092009-08-06 06:41:21 +0000595 /// \brief Build a new template name given a nested name specifier and the
596 /// name that is referred to as a template.
597 ///
598 /// By default, performs semantic analysis to determine whether the name can
599 /// be resolved to a specific template, then builds the appropriate kind of
600 /// template name. Subclasses may override this routine to provide different
601 /// behavior.
602 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000603 const IdentifierInfo &II,
604 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000605
Douglas Gregor71395fa2009-11-04 00:56:37 +0000606 /// \brief Build a new template name given a nested name specifier and the
607 /// overloaded operator name that is referred to as a template.
608 ///
609 /// By default, performs semantic analysis to determine whether the name can
610 /// be resolved to a specific template, then builds the appropriate kind of
611 /// template name. Subclasses may override this routine to provide different
612 /// behavior.
613 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
614 OverloadedOperatorKind Operator,
615 QualType ObjectType);
616
Douglas Gregorebe10102009-08-20 07:17:43 +0000617 /// \brief Build a new compound statement.
618 ///
619 /// By default, performs semantic analysis to build the new statement.
620 /// Subclasses may override this routine to provide different behavior.
621 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
622 MultiStmtArg Statements,
623 SourceLocation RBraceLoc,
624 bool IsStmtExpr) {
625 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
626 IsStmtExpr);
627 }
628
629 /// \brief Build a new case statement.
630 ///
631 /// By default, performs semantic analysis to build the new statement.
632 /// Subclasses may override this routine to provide different behavior.
633 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
634 ExprArg LHS,
635 SourceLocation EllipsisLoc,
636 ExprArg RHS,
637 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000638 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000639 ColonLoc);
640 }
Mike Stump11289f42009-09-09 15:08:12 +0000641
Douglas Gregorebe10102009-08-20 07:17:43 +0000642 /// \brief Attach the body to a new case statement.
643 ///
644 /// By default, performs semantic analysis to build the new statement.
645 /// Subclasses may override this routine to provide different behavior.
646 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
647 getSema().ActOnCaseStmtBody(S.get(), move(Body));
648 return move(S);
649 }
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregorebe10102009-08-20 07:17:43 +0000651 /// \brief Build a new default statement.
652 ///
653 /// By default, performs semantic analysis to build the new statement.
654 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000655 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 SourceLocation ColonLoc,
657 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000658 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000659 /*CurScope=*/0);
660 }
Mike Stump11289f42009-09-09 15:08:12 +0000661
Douglas Gregorebe10102009-08-20 07:17:43 +0000662 /// \brief Build a new label statement.
663 ///
664 /// By default, performs semantic analysis to build the new statement.
665 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000666 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000667 IdentifierInfo *Id,
668 SourceLocation ColonLoc,
669 StmtArg SubStmt) {
670 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
671 }
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 /// \brief Build a new "if" statement.
674 ///
675 /// By default, performs semantic analysis to build the new statement.
676 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000677 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000678 VarDecl *CondVar, StmtArg Then,
679 SourceLocation ElseLoc, StmtArg Else) {
680 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
681 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000682 }
Mike Stump11289f42009-09-09 15:08:12 +0000683
Douglas Gregorebe10102009-08-20 07:17:43 +0000684 /// \brief Start building a new switch statement.
685 ///
686 /// By default, performs semantic analysis to build the new statement.
687 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000688 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
689 VarDecl *CondVar) {
690 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000691 }
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregorebe10102009-08-20 07:17:43 +0000693 /// \brief Attach the body to the switch statement.
694 ///
695 /// By default, performs semantic analysis to build the new statement.
696 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000697 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000698 StmtArg Switch, StmtArg Body) {
699 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
700 move(Body));
701 }
702
703 /// \brief Build a new while statement.
704 ///
705 /// By default, performs semantic analysis to build the new statement.
706 /// Subclasses may override this routine to provide different behavior.
707 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
708 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000709 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000711 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
712 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000713 }
Mike Stump11289f42009-09-09 15:08:12 +0000714
Douglas Gregorebe10102009-08-20 07:17:43 +0000715 /// \brief Build a new do-while statement.
716 ///
717 /// By default, performs semantic analysis to build the new statement.
718 /// Subclasses may override this routine to provide different behavior.
719 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
720 SourceLocation WhileLoc,
721 SourceLocation LParenLoc,
722 ExprArg Cond,
723 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000724 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000725 move(Cond), RParenLoc);
726 }
727
728 /// \brief Build a new for statement.
729 ///
730 /// By default, performs semantic analysis to build the new statement.
731 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000732 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000734 StmtArg Init, Sema::FullExprArg Cond,
735 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000737 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
738 DeclPtrTy::make(CondVar),
739 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 }
Mike Stump11289f42009-09-09 15:08:12 +0000741
Douglas Gregorebe10102009-08-20 07:17:43 +0000742 /// \brief Build a new goto statement.
743 ///
744 /// By default, performs semantic analysis to build the new statement.
745 /// Subclasses may override this routine to provide different behavior.
746 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
747 SourceLocation LabelLoc,
748 LabelStmt *Label) {
749 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
750 }
751
752 /// \brief Build a new indirect goto statement.
753 ///
754 /// By default, performs semantic analysis to build the new statement.
755 /// Subclasses may override this routine to provide different behavior.
756 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
757 SourceLocation StarLoc,
758 ExprArg Target) {
759 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new return statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
766 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
767 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
770 }
Mike Stump11289f42009-09-09 15:08:12 +0000771
Douglas Gregorebe10102009-08-20 07:17:43 +0000772 /// \brief Build a new declaration statement.
773 ///
774 /// By default, performs semantic analysis to build the new statement.
775 /// Subclasses may override this routine to provide different behavior.
776 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000777 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 SourceLocation EndLoc) {
779 return getSema().Owned(
780 new (getSema().Context) DeclStmt(
781 DeclGroupRef::Create(getSema().Context,
782 Decls, NumDecls),
783 StartLoc, EndLoc));
784 }
Mike Stump11289f42009-09-09 15:08:12 +0000785
Anders Carlssonaaeef072010-01-24 05:50:09 +0000786 /// \brief Build a new inline asm statement.
787 ///
788 /// By default, performs semantic analysis to build the new statement.
789 /// Subclasses may override this routine to provide different behavior.
790 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
791 bool IsSimple,
792 bool IsVolatile,
793 unsigned NumOutputs,
794 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000795 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000796 MultiExprArg Constraints,
797 MultiExprArg Exprs,
798 ExprArg AsmString,
799 MultiExprArg Clobbers,
800 SourceLocation RParenLoc,
801 bool MSAsm) {
802 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
803 NumInputs, Names, move(Constraints),
804 move(Exprs), move(AsmString), move(Clobbers),
805 RParenLoc, MSAsm);
806 }
807
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 /// \brief Build a new C++ exception declaration.
809 ///
810 /// By default, performs semantic analysis to build the new decaration.
811 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000812 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000813 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 IdentifierInfo *Name,
815 SourceLocation Loc,
816 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000817 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 TypeRange);
819 }
820
821 /// \brief Build a new C++ catch statement.
822 ///
823 /// By default, performs semantic analysis to build the new statement.
824 /// Subclasses may override this routine to provide different behavior.
825 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
826 VarDecl *ExceptionDecl,
827 StmtArg Handler) {
828 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000829 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 Handler.takeAs<Stmt>()));
831 }
Mike Stump11289f42009-09-09 15:08:12 +0000832
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 /// \brief Build a new C++ try statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
838 StmtArg TryBlock,
839 MultiStmtArg Handlers) {
840 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
841 }
Mike Stump11289f42009-09-09 15:08:12 +0000842
Douglas Gregora16548e2009-08-11 05:31:07 +0000843 /// \brief Build a new expression that references a declaration.
844 ///
845 /// By default, performs semantic analysis to build the new expression.
846 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000847 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
848 LookupResult &R,
849 bool RequiresADL) {
850 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
851 }
852
853
854 /// \brief Build a new expression that references a declaration.
855 ///
856 /// By default, performs semantic analysis to build the new expression.
857 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000858 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
859 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000860 ValueDecl *VD, SourceLocation Loc,
861 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000862 CXXScopeSpec SS;
863 SS.setScopeRep(Qualifier);
864 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000865
866 // FIXME: loses template args.
867
868 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Douglas Gregora16548e2009-08-11 05:31:07 +0000871 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000873 /// By default, performs semantic analysis to build the new expression.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
876 SourceLocation RParen) {
877 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
878 }
879
Douglas Gregorad8a3362009-09-04 17:36:40 +0000880 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000881 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000882 /// By default, performs semantic analysis to build the new expression.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
885 SourceLocation OperatorLoc,
886 bool isArrow,
887 SourceLocation DestroyedTypeLoc,
888 QualType DestroyedType,
889 NestedNameSpecifier *Qualifier,
890 SourceRange QualifierRange) {
891 CXXScopeSpec SS;
892 if (Qualifier) {
893 SS.setRange(QualifierRange);
894 SS.setScopeRep(Qualifier);
895 }
896
John McCall2d74de92009-12-01 22:10:20 +0000897 QualType BaseType = ((Expr*) Base.get())->getType();
898
Mike Stump11289f42009-09-09 15:08:12 +0000899 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000900 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
901 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000902
John McCall2d74de92009-12-01 22:10:20 +0000903 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
904 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000905 SS, /*FIXME: FirstQualifier*/ 0,
906 Name, DestroyedTypeLoc,
907 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000908 }
909
Douglas Gregora16548e2009-08-11 05:31:07 +0000910 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000911 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000912 /// By default, performs semantic analysis to build the new expression.
913 /// Subclasses may override this routine to provide different behavior.
914 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
915 UnaryOperator::Opcode Opc,
916 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000917 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 }
Mike Stump11289f42009-09-09 15:08:12 +0000919
Douglas Gregora16548e2009-08-11 05:31:07 +0000920 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000921 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000922 /// By default, performs semantic analysis to build the new expression.
923 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000924 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000925 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000926 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000927 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 }
929
Mike Stump11289f42009-09-09 15:08:12 +0000930 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000931 /// argument.
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 RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
936 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000937 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000938 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
939 OpLoc, isSizeOf, R);
940 if (Result.isInvalid())
941 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000942
Douglas Gregora16548e2009-08-11 05:31:07 +0000943 SubExpr.release();
944 return move(Result);
945 }
Mike Stump11289f42009-09-09 15:08:12 +0000946
Douglas Gregora16548e2009-08-11 05:31:07 +0000947 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000948 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000949 /// By default, performs semantic analysis to build the new expression.
950 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000951 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000952 SourceLocation LBracketLoc,
953 ExprArg RHS,
954 SourceLocation RBracketLoc) {
955 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000956 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000957 RBracketLoc);
958 }
959
960 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000961 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000962 /// By default, performs semantic analysis to build the new expression.
963 /// Subclasses may override this routine to provide different behavior.
964 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
965 MultiExprArg Args,
966 SourceLocation *CommaLocs,
967 SourceLocation RParenLoc) {
968 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
969 move(Args), CommaLocs, RParenLoc);
970 }
971
972 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000973 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000974 /// By default, performs semantic analysis to build the new expression.
975 /// Subclasses may override this routine to provide different behavior.
976 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000977 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000978 NestedNameSpecifier *Qualifier,
979 SourceRange QualifierRange,
980 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000981 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000982 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000983 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000984 if (!Member->getDeclName()) {
985 // We have a reference to an unnamed field.
986 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000987
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000988 Expr *BaseExpr = Base.takeAs<Expr>();
989 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
990 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000991
Mike Stump11289f42009-09-09 15:08:12 +0000992 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000993 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000994 Member, MemberLoc,
995 cast<FieldDecl>(Member)->getType());
996 return getSema().Owned(ME);
997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000999 CXXScopeSpec SS;
1000 if (Qualifier) {
1001 SS.setRange(QualifierRange);
1002 SS.setScopeRep(Qualifier);
1003 }
1004
John McCall2d74de92009-12-01 22:10:20 +00001005 QualType BaseType = ((Expr*) Base.get())->getType();
1006
John McCall38836f02010-01-15 08:34:02 +00001007 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1008 Sema::LookupMemberName);
1009 R.addDecl(Member);
1010 R.resolveKind();
1011
John McCall2d74de92009-12-01 22:10:20 +00001012 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1013 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001014 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001015 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 }
Mike Stump11289f42009-09-09 15:08:12 +00001017
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001019 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001020 /// By default, performs semantic analysis to build the new expression.
1021 /// Subclasses may override this routine to provide different behavior.
1022 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1023 BinaryOperator::Opcode Opc,
1024 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001025 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1026 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 }
1028
1029 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001030 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001031 /// By default, performs semantic analysis to build the new expression.
1032 /// Subclasses may override this routine to provide different behavior.
1033 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1034 SourceLocation QuestionLoc,
1035 ExprArg LHS,
1036 SourceLocation ColonLoc,
1037 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001038 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 move(LHS), move(RHS));
1040 }
1041
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001043 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// By default, performs semantic analysis to build the new expression.
1045 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001046 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1047 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 SourceLocation RParenLoc,
1049 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001050 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1051 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 }
Mike Stump11289f42009-09-09 15:08:12 +00001053
Douglas Gregora16548e2009-08-11 05:31:07 +00001054 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001055 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 /// By default, performs semantic analysis to build the new expression.
1057 /// Subclasses may override this routine to provide different behavior.
1058 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001059 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001060 SourceLocation RParenLoc,
1061 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001062 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1063 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001064 }
Mike Stump11289f42009-09-09 15:08:12 +00001065
Douglas Gregora16548e2009-08-11 05:31:07 +00001066 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001067 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// By default, performs semantic analysis to build the new expression.
1069 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001070 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 SourceLocation OpLoc,
1072 SourceLocation AccessorLoc,
1073 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001074
John McCall10eae182009-11-30 22:42:35 +00001075 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001076 QualType BaseType = ((Expr*) Base.get())->getType();
1077 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001078 OpLoc, /*IsArrow*/ false,
1079 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001080 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001081 AccessorLoc,
1082 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001083 }
Mike Stump11289f42009-09-09 15:08:12 +00001084
Douglas Gregora16548e2009-08-11 05:31:07 +00001085 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001086 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001087 /// By default, performs semantic analysis to build the new expression.
1088 /// Subclasses may override this routine to provide different behavior.
1089 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1090 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001091 SourceLocation RBraceLoc,
1092 QualType ResultTy) {
1093 OwningExprResult Result
1094 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1095 if (Result.isInvalid() || ResultTy->isDependentType())
1096 return move(Result);
1097
1098 // Patch in the result type we were given, which may have been computed
1099 // when the initial InitListExpr was built.
1100 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1101 ILE->setType(ResultTy);
1102 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 }
Mike Stump11289f42009-09-09 15:08:12 +00001104
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001106 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// By default, performs semantic analysis to build the new expression.
1108 /// Subclasses may override this routine to provide different behavior.
1109 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1110 MultiExprArg ArrayExprs,
1111 SourceLocation EqualOrColonLoc,
1112 bool GNUSyntax,
1113 ExprArg Init) {
1114 OwningExprResult Result
1115 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1116 move(Init));
1117 if (Result.isInvalid())
1118 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001119
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 ArrayExprs.release();
1121 return move(Result);
1122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, builds the implicit value initialization without performing
1127 /// any semantic analysis. Subclasses may override this routine to provide
1128 /// different behavior.
1129 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1130 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1131 }
Mike Stump11289f42009-09-09 15:08:12 +00001132
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001134 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// By default, performs semantic analysis to build the new expression.
1136 /// Subclasses may override this routine to provide different behavior.
1137 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1138 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001139 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001140 RParenLoc);
1141 }
1142
1143 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001144 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001145 /// By default, performs semantic analysis to build the new expression.
1146 /// Subclasses may override this routine to provide different behavior.
1147 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1148 MultiExprArg SubExprs,
1149 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001150 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1151 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001155 ///
1156 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001157 /// rather than attempting to map the label statement itself.
1158 /// Subclasses may override this routine to provide different behavior.
1159 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1160 SourceLocation LabelLoc,
1161 LabelStmt *Label) {
1162 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001166 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001167 /// By default, performs semantic analysis to build the new expression.
1168 /// Subclasses may override this routine to provide different behavior.
1169 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1170 StmtArg SubStmt,
1171 SourceLocation RParenLoc) {
1172 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Douglas Gregora16548e2009-08-11 05:31:07 +00001175 /// \brief Build a new __builtin_types_compatible_p expression.
1176 ///
1177 /// By default, performs semantic analysis to build the new expression.
1178 /// Subclasses may override this routine to provide different behavior.
1179 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1180 QualType T1, QualType T2,
1181 SourceLocation RParenLoc) {
1182 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1183 T1.getAsOpaquePtr(),
1184 T2.getAsOpaquePtr(),
1185 RParenLoc);
1186 }
Mike Stump11289f42009-09-09 15:08:12 +00001187
Douglas Gregora16548e2009-08-11 05:31:07 +00001188 /// \brief Build a new __builtin_choose_expr expression.
1189 ///
1190 /// By default, performs semantic analysis to build the new expression.
1191 /// Subclasses may override this routine to provide different behavior.
1192 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1193 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1194 SourceLocation RParenLoc) {
1195 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1196 move(Cond), move(LHS), move(RHS),
1197 RParenLoc);
1198 }
Mike Stump11289f42009-09-09 15:08:12 +00001199
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 /// \brief Build a new overloaded operator call expression.
1201 ///
1202 /// By default, performs semantic analysis to build the new expression.
1203 /// The semantic analysis provides the behavior of template instantiation,
1204 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001205 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001206 /// argument-dependent lookup, etc. Subclasses may override this routine to
1207 /// provide different behavior.
1208 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1209 SourceLocation OpLoc,
1210 ExprArg Callee,
1211 ExprArg First,
1212 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001213
1214 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 /// reinterpret_cast.
1216 ///
1217 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001218 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 /// Subclasses may override this routine to provide different behavior.
1220 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1221 Stmt::StmtClass Class,
1222 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RAngleLoc,
1225 SourceLocation LParenLoc,
1226 ExprArg SubExpr,
1227 SourceLocation RParenLoc) {
1228 switch (Class) {
1229 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001230 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001231 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 move(SubExpr), RParenLoc);
1233
1234 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001235 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001236 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001240 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001241 RAngleLoc, LParenLoc,
1242 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001246 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001247 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001248 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001249
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 default:
1251 assert(false && "Invalid C++ named cast");
1252 break;
1253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 return getSema().ExprError();
1256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 /// \brief Build a new C++ static_cast expression.
1259 ///
1260 /// By default, performs semantic analysis to build the new expression.
1261 /// Subclasses may override this routine to provide different behavior.
1262 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1263 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001264 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001265 SourceLocation RAngleLoc,
1266 SourceLocation LParenLoc,
1267 ExprArg SubExpr,
1268 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001269 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1270 TInfo, move(SubExpr),
1271 SourceRange(LAngleLoc, RAngleLoc),
1272 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 }
1274
1275 /// \brief Build a new C++ dynamic_cast expression.
1276 ///
1277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
1279 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1280 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001281 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 SourceLocation RAngleLoc,
1283 SourceLocation LParenLoc,
1284 ExprArg SubExpr,
1285 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001286 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1287 TInfo, move(SubExpr),
1288 SourceRange(LAngleLoc, RAngleLoc),
1289 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 }
1291
1292 /// \brief Build a new C++ reinterpret_cast expression.
1293 ///
1294 /// By default, performs semantic analysis to build the new expression.
1295 /// Subclasses may override this routine to provide different behavior.
1296 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1297 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001298 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001299 SourceLocation RAngleLoc,
1300 SourceLocation LParenLoc,
1301 ExprArg SubExpr,
1302 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001303 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1304 TInfo, move(SubExpr),
1305 SourceRange(LAngleLoc, RAngleLoc),
1306 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
1308
1309 /// \brief Build a new C++ const_cast expression.
1310 ///
1311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1314 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001315 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 SourceLocation RAngleLoc,
1317 SourceLocation LParenLoc,
1318 ExprArg SubExpr,
1319 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001320 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1321 TInfo, move(SubExpr),
1322 SourceRange(LAngleLoc, RAngleLoc),
1323 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 }
Mike Stump11289f42009-09-09 15:08:12 +00001325
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// \brief Build a new C++ functional-style cast expression.
1327 ///
1328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001331 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001332 SourceLocation LParenLoc,
1333 ExprArg SubExpr,
1334 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001335 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001337 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001339 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001340 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 RParenLoc);
1342 }
Mike Stump11289f42009-09-09 15:08:12 +00001343
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// \brief Build a new C++ typeid(type) expression.
1345 ///
1346 /// By default, performs semantic analysis to build the new expression.
1347 /// Subclasses may override this routine to provide different behavior.
1348 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1349 SourceLocation LParenLoc,
1350 QualType T,
1351 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001352 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 T.getAsOpaquePtr(), RParenLoc);
1354 }
Mike Stump11289f42009-09-09 15:08:12 +00001355
Douglas Gregora16548e2009-08-11 05:31:07 +00001356 /// \brief Build a new C++ typeid(expr) expression.
1357 ///
1358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
1360 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1361 SourceLocation LParenLoc,
1362 ExprArg Operand,
1363 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001364 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1366 RParenLoc);
1367 if (Result.isInvalid())
1368 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001369
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1371 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001372 }
1373
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// \brief Build a new C++ "this" expression.
1375 ///
1376 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001377 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001378 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001379 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001380 QualType ThisType,
1381 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001383 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1384 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 }
1386
1387 /// \brief Build a new C++ throw expression.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
1391 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1392 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1393 }
1394
1395 /// \brief Build a new C++ default-argument expression.
1396 ///
1397 /// By default, builds a new default-argument expression, which does not
1398 /// require any semantic analysis. Subclasses may override this routine to
1399 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001400 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1401 ParmVarDecl *Param) {
1402 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1403 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 }
1405
1406 /// \brief Build a new C++ zero-initialization expression.
1407 ///
1408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001410 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 SourceLocation LParenLoc,
1412 QualType T,
1413 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001414 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1415 T.getAsOpaquePtr(), LParenLoc,
1416 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 0, RParenLoc);
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 /// \brief Build a new C++ "new" expression.
1421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001424 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 bool UseGlobal,
1426 SourceLocation PlacementLParen,
1427 MultiExprArg PlacementArgs,
1428 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001429 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 QualType AllocType,
1431 SourceLocation TypeLoc,
1432 SourceRange TypeRange,
1433 ExprArg ArraySize,
1434 SourceLocation ConstructorLParen,
1435 MultiExprArg ConstructorArgs,
1436 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001437 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 PlacementLParen,
1439 move(PlacementArgs),
1440 PlacementRParen,
1441 ParenTypeId,
1442 AllocType,
1443 TypeLoc,
1444 TypeRange,
1445 move(ArraySize),
1446 ConstructorLParen,
1447 move(ConstructorArgs),
1448 ConstructorRParen);
1449 }
Mike Stump11289f42009-09-09 15:08:12 +00001450
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// \brief Build a new C++ "delete" expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
1455 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1456 bool IsGlobalDelete,
1457 bool IsArrayForm,
1458 ExprArg Operand) {
1459 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1460 move(Operand));
1461 }
Mike Stump11289f42009-09-09 15:08:12 +00001462
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 /// \brief Build a new unary type trait expression.
1464 ///
1465 /// By default, performs semantic analysis to build the new expression.
1466 /// Subclasses may override this routine to provide different behavior.
1467 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1468 SourceLocation StartLoc,
1469 SourceLocation LParenLoc,
1470 QualType T,
1471 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001472 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 T.getAsOpaquePtr(), RParenLoc);
1474 }
1475
Mike Stump11289f42009-09-09 15:08:12 +00001476 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001477 /// expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001481 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 SourceRange QualifierRange,
1483 DeclarationName Name,
1484 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001485 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 CXXScopeSpec SS;
1487 SS.setRange(QualifierRange);
1488 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001489
1490 if (TemplateArgs)
1491 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1492 *TemplateArgs);
1493
1494 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
1496
1497 /// \brief Build a new template-id expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001501 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1502 LookupResult &R,
1503 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001504 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001505 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 }
1507
1508 /// \brief Build a new object-construction expression.
1509 ///
1510 /// By default, performs semantic analysis to build the new expression.
1511 /// Subclasses may override this routine to provide different behavior.
1512 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001513 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 CXXConstructorDecl *Constructor,
1515 bool IsElidable,
1516 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001517 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1518 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1519 ConvertedArgs))
1520 return getSema().ExprError();
1521
1522 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1523 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 }
1525
1526 /// \brief Build a new object-construction expression.
1527 ///
1528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1531 QualType T,
1532 SourceLocation LParenLoc,
1533 MultiExprArg Args,
1534 SourceLocation *Commas,
1535 SourceLocation RParenLoc) {
1536 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1537 T.getAsOpaquePtr(),
1538 LParenLoc,
1539 move(Args),
1540 Commas,
1541 RParenLoc);
1542 }
1543
1544 /// \brief Build a new object-construction expression.
1545 ///
1546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
1548 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1549 QualType T,
1550 SourceLocation LParenLoc,
1551 MultiExprArg Args,
1552 SourceLocation *Commas,
1553 SourceLocation RParenLoc) {
1554 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1555 /*FIXME*/LParenLoc),
1556 T.getAsOpaquePtr(),
1557 LParenLoc,
1558 move(Args),
1559 Commas,
1560 RParenLoc);
1561 }
Mike Stump11289f42009-09-09 15:08:12 +00001562
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// \brief Build a new member reference expression.
1564 ///
1565 /// By default, performs semantic analysis to build the new expression.
1566 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001567 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001568 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 bool IsArrow,
1570 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001571 NestedNameSpecifier *Qualifier,
1572 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001573 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001575 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001576 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001578 SS.setRange(QualifierRange);
1579 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001580
John McCall2d74de92009-12-01 22:10:20 +00001581 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1582 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001583 SS, FirstQualifierInScope,
1584 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001585 }
1586
John McCall10eae182009-11-30 22:42:35 +00001587 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001591 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001592 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001593 SourceLocation OperatorLoc,
1594 bool IsArrow,
1595 NestedNameSpecifier *Qualifier,
1596 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001597 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001598 LookupResult &R,
1599 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001600 CXXScopeSpec SS;
1601 SS.setRange(QualifierRange);
1602 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001603
John McCall2d74de92009-12-01 22:10:20 +00001604 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1605 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001606 SS, FirstQualifierInScope,
1607 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001608 }
Mike Stump11289f42009-09-09 15:08:12 +00001609
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 /// \brief Build a new Objective-C @encode expression.
1611 ///
1612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
1614 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1615 QualType T,
1616 SourceLocation RParenLoc) {
1617 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1618 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001619 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001620
1621 /// \brief Build a new Objective-C protocol expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1626 SourceLocation AtLoc,
1627 SourceLocation ProtoLoc,
1628 SourceLocation LParenLoc,
1629 SourceLocation RParenLoc) {
1630 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1631 Protocol->getIdentifier(),
1632 AtLoc,
1633 ProtoLoc,
1634 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001635 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new shuffle vector expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
1642 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1643 MultiExprArg SubExprs,
1644 SourceLocation RParenLoc) {
1645 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001646 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1648 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1649 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1650 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001651
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 // Build a reference to the __builtin_shufflevector builtin
1653 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001654 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001656 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001658
1659 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 unsigned NumSubExprs = SubExprs.size();
1661 Expr **Subs = (Expr **)SubExprs.release();
1662 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1663 Subs, NumSubExprs,
1664 Builtin->getResultType(),
1665 RParenLoc);
1666 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001667
Douglas Gregora16548e2009-08-11 05:31:07 +00001668 // Type-check the __builtin_shufflevector expression.
1669 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1670 if (Result.isInvalid())
1671 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001674 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001675 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001676};
Douglas Gregora16548e2009-08-11 05:31:07 +00001677
Douglas Gregorebe10102009-08-20 07:17:43 +00001678template<typename Derived>
1679Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1680 if (!S)
1681 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001682
Douglas Gregorebe10102009-08-20 07:17:43 +00001683 switch (S->getStmtClass()) {
1684 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001685
Douglas Gregorebe10102009-08-20 07:17:43 +00001686 // Transform individual statement nodes
1687#define STMT(Node, Parent) \
1688 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1689#define EXPR(Node, Parent)
1690#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001691
Douglas Gregorebe10102009-08-20 07:17:43 +00001692 // Transform expressions by calling TransformExpr.
1693#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001694#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001695#define EXPR(Node, Parent) case Stmt::Node##Class:
1696#include "clang/AST/StmtNodes.def"
1697 {
1698 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1699 if (E.isInvalid())
1700 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001701
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001702 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001703 }
Mike Stump11289f42009-09-09 15:08:12 +00001704 }
1705
Douglas Gregorebe10102009-08-20 07:17:43 +00001706 return SemaRef.Owned(S->Retain());
1707}
Mike Stump11289f42009-09-09 15:08:12 +00001708
1709
Douglas Gregore922c772009-08-04 22:27:00 +00001710template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001711Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 if (!E)
1713 return SemaRef.Owned(E);
1714
1715 switch (E->getStmtClass()) {
1716 case Stmt::NoStmtClass: break;
1717#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001718#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001719#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001720 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001721#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001722 }
1723
Douglas Gregora16548e2009-08-11 05:31:07 +00001724 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001725}
1726
1727template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001728NestedNameSpecifier *
1729TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001730 SourceRange Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001731 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001732 QualType ObjectType,
1733 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001734 if (!NNS)
1735 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregorebe10102009-08-20 07:17:43 +00001737 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001738 NestedNameSpecifier *Prefix = NNS->getPrefix();
1739 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001740 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001741 false,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001742 ObjectType,
1743 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001744 if (!Prefix)
1745 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001746
1747 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001748 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001749 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001750 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 switch (NNS->getKind()) {
1754 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001755 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001756 "Identifier nested-name-specifier with no prefix or object type");
1757 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1758 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001760
1761 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001762 *NNS->getAsIdentifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001763 MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001764 ObjectType,
1765 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001766
Douglas Gregor1135c352009-08-06 05:28:30 +00001767 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001768 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001769 = cast_or_null<NamespaceDecl>(
1770 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001771 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001772 Prefix == NNS->getPrefix() &&
1773 NS == NNS->getAsNamespace())
1774 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001775
Douglas Gregor1135c352009-08-06 05:28:30 +00001776 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1777 }
Mike Stump11289f42009-09-09 15:08:12 +00001778
Douglas Gregor1135c352009-08-06 05:28:30 +00001779 case NestedNameSpecifier::Global:
1780 // There is no meaningful transformation that one could perform on the
1781 // global scope.
1782 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001783
Douglas Gregor1135c352009-08-06 05:28:30 +00001784 case NestedNameSpecifier::TypeSpecWithTemplate:
1785 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001786 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001787 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1788 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001789 if (T.isNull())
1790 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001791
Douglas Gregor1135c352009-08-06 05:28:30 +00001792 if (!getDerived().AlwaysRebuild() &&
1793 Prefix == NNS->getPrefix() &&
1794 T == QualType(NNS->getAsType(), 0))
1795 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001796
1797 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1798 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor90d554e2010-02-21 18:36:56 +00001799 T,
1800 MayBePseudoDestructor);
Douglas Gregor1135c352009-08-06 05:28:30 +00001801 }
1802 }
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregor1135c352009-08-06 05:28:30 +00001804 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001805 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001806}
1807
1808template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001809DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001810TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001811 SourceLocation Loc,
1812 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001813 if (!Name)
1814 return Name;
1815
1816 switch (Name.getNameKind()) {
1817 case DeclarationName::Identifier:
1818 case DeclarationName::ObjCZeroArgSelector:
1819 case DeclarationName::ObjCOneArgSelector:
1820 case DeclarationName::ObjCMultiArgSelector:
1821 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001822 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001823 case DeclarationName::CXXUsingDirective:
1824 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001825
Douglas Gregorf816bd72009-09-03 22:13:48 +00001826 case DeclarationName::CXXConstructorName:
1827 case DeclarationName::CXXDestructorName:
1828 case DeclarationName::CXXConversionFunctionName: {
1829 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001830 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1831 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001832 if (T.isNull())
1833 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001834
Douglas Gregorf816bd72009-09-03 22:13:48 +00001835 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001836 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001837 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001838 }
Mike Stump11289f42009-09-09 15:08:12 +00001839 }
1840
Douglas Gregorf816bd72009-09-03 22:13:48 +00001841 return DeclarationName();
1842}
1843
1844template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001845TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001846TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1847 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001848 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001849 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001851 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001852 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00001853 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001854 if (!NNS)
1855 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001856
Douglas Gregor71dc5092009-08-06 06:41:21 +00001857 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001858 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1860 if (!TransTemplate)
1861 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001862
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 if (!getDerived().AlwaysRebuild() &&
1864 NNS == QTN->getQualifier() &&
1865 TransTemplate == Template)
1866 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001867
Douglas Gregor71dc5092009-08-06 06:41:21 +00001868 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1869 TransTemplate);
1870 }
Mike Stump11289f42009-09-09 15:08:12 +00001871
John McCalle66edc12009-11-24 19:00:30 +00001872 // These should be getting filtered out before they make it into the AST.
1873 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 }
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor71dc5092009-08-06 06:41:21 +00001876 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001877 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001878 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001879 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
Douglas Gregor90d554e2010-02-21 18:36:56 +00001880 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00001881 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001882 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001883 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001884
Douglas Gregor71dc5092009-08-06 06:41:21 +00001885 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001886 NNS == DTN->getQualifier() &&
1887 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001888 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001889
Douglas Gregor71395fa2009-11-04 00:56:37 +00001890 if (DTN->isIdentifier())
1891 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1892 ObjectType);
1893
1894 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1895 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001896 }
Mike Stump11289f42009-09-09 15:08:12 +00001897
Douglas Gregor71dc5092009-08-06 06:41:21 +00001898 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001899 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001900 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1901 if (!TransTemplate)
1902 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001903
Douglas Gregor71dc5092009-08-06 06:41:21 +00001904 if (!getDerived().AlwaysRebuild() &&
1905 TransTemplate == Template)
1906 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001907
Douglas Gregor71dc5092009-08-06 06:41:21 +00001908 return TemplateName(TransTemplate);
1909 }
Mike Stump11289f42009-09-09 15:08:12 +00001910
John McCalle66edc12009-11-24 19:00:30 +00001911 // These should be getting filtered out before they reach the AST.
1912 assert(false && "overloaded function decl survived to here");
1913 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001914}
1915
1916template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001917void TreeTransform<Derived>::InventTemplateArgumentLoc(
1918 const TemplateArgument &Arg,
1919 TemplateArgumentLoc &Output) {
1920 SourceLocation Loc = getDerived().getBaseLocation();
1921 switch (Arg.getKind()) {
1922 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001923 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001924 break;
1925
1926 case TemplateArgument::Type:
1927 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001928 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001929
1930 break;
1931
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001932 case TemplateArgument::Template:
1933 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1934 break;
1935
John McCall0ad16662009-10-29 08:12:44 +00001936 case TemplateArgument::Expression:
1937 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1938 break;
1939
1940 case TemplateArgument::Declaration:
1941 case TemplateArgument::Integral:
1942 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001943 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001944 break;
1945 }
1946}
1947
1948template<typename Derived>
1949bool TreeTransform<Derived>::TransformTemplateArgument(
1950 const TemplateArgumentLoc &Input,
1951 TemplateArgumentLoc &Output) {
1952 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001953 switch (Arg.getKind()) {
1954 case TemplateArgument::Null:
1955 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001956 Output = Input;
1957 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregore922c772009-08-04 22:27:00 +00001959 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001960 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001961 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001962 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001963
1964 DI = getDerived().TransformType(DI);
1965 if (!DI) return true;
1966
1967 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1968 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001969 }
Mike Stump11289f42009-09-09 15:08:12 +00001970
Douglas Gregore922c772009-08-04 22:27:00 +00001971 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001972 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001973 DeclarationName Name;
1974 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1975 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001976 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001977 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001978 if (!D) return true;
1979
John McCall0d07eb32009-10-29 18:45:58 +00001980 Expr *SourceExpr = Input.getSourceDeclExpression();
1981 if (SourceExpr) {
1982 EnterExpressionEvaluationContext Unevaluated(getSema(),
1983 Action::Unevaluated);
1984 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1985 if (E.isInvalid())
1986 SourceExpr = NULL;
1987 else {
1988 SourceExpr = E.takeAs<Expr>();
1989 SourceExpr->Retain();
1990 }
1991 }
1992
1993 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001994 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001995 }
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001997 case TemplateArgument::Template: {
1998 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1999 TemplateName Template
2000 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2001 if (Template.isNull())
2002 return true;
2003
2004 Output = TemplateArgumentLoc(TemplateArgument(Template),
2005 Input.getTemplateQualifierRange(),
2006 Input.getTemplateNameLoc());
2007 return false;
2008 }
2009
Douglas Gregore922c772009-08-04 22:27:00 +00002010 case TemplateArgument::Expression: {
2011 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002012 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002013 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002014
John McCall0ad16662009-10-29 08:12:44 +00002015 Expr *InputExpr = Input.getSourceExpression();
2016 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2017
2018 Sema::OwningExprResult E
2019 = getDerived().TransformExpr(InputExpr);
2020 if (E.isInvalid()) return true;
2021
2022 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002023 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002024 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2025 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002026 }
Mike Stump11289f42009-09-09 15:08:12 +00002027
Douglas Gregore922c772009-08-04 22:27:00 +00002028 case TemplateArgument::Pack: {
2029 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2030 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002031 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002032 AEnd = Arg.pack_end();
2033 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002034
John McCall0ad16662009-10-29 08:12:44 +00002035 // FIXME: preserve source information here when we start
2036 // caring about parameter packs.
2037
John McCall0d07eb32009-10-29 18:45:58 +00002038 TemplateArgumentLoc InputArg;
2039 TemplateArgumentLoc OutputArg;
2040 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2041 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002042 return true;
2043
John McCall0d07eb32009-10-29 18:45:58 +00002044 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002045 }
2046 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002047 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002048 true);
John McCall0d07eb32009-10-29 18:45:58 +00002049 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002050 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002051 }
2052 }
Mike Stump11289f42009-09-09 15:08:12 +00002053
Douglas Gregore922c772009-08-04 22:27:00 +00002054 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002055 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002056}
2057
Douglas Gregord6ff3322009-08-04 16:50:30 +00002058//===----------------------------------------------------------------------===//
2059// Type transformation
2060//===----------------------------------------------------------------------===//
2061
2062template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002063QualType TreeTransform<Derived>::TransformType(QualType T,
2064 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002065 if (getDerived().AlreadyTransformed(T))
2066 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002067
John McCall550e0c22009-10-21 00:40:46 +00002068 // Temporary workaround. All of these transformations should
2069 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002070 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002071 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002072
Douglas Gregorfe17d252010-02-16 19:09:40 +00002073 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002074
John McCall550e0c22009-10-21 00:40:46 +00002075 if (!NewDI)
2076 return QualType();
2077
2078 return NewDI->getType();
2079}
2080
2081template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002082TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2083 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002084 if (getDerived().AlreadyTransformed(DI->getType()))
2085 return DI;
2086
2087 TypeLocBuilder TLB;
2088
2089 TypeLoc TL = DI->getTypeLoc();
2090 TLB.reserve(TL.getFullDataSize());
2091
Douglas Gregorfe17d252010-02-16 19:09:40 +00002092 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002093 if (Result.isNull())
2094 return 0;
2095
John McCallbcd03502009-12-07 02:54:59 +00002096 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002097}
2098
2099template<typename Derived>
2100QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002101TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2102 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002103 switch (T.getTypeLocClass()) {
2104#define ABSTRACT_TYPELOC(CLASS, PARENT)
2105#define TYPELOC(CLASS, PARENT) \
2106 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002107 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2108 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002109#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002110 }
Mike Stump11289f42009-09-09 15:08:12 +00002111
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002112 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002113 return QualType();
2114}
2115
2116/// FIXME: By default, this routine adds type qualifiers only to types
2117/// that can have qualifiers, and silently suppresses those qualifiers
2118/// that are not permitted (e.g., qualifiers on reference or function
2119/// types). This is the right thing for template instantiation, but
2120/// probably not for other clients.
2121template<typename Derived>
2122QualType
2123TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002124 QualifiedTypeLoc T,
2125 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002126 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002127
Douglas Gregorfe17d252010-02-16 19:09:40 +00002128 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2129 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002130 if (Result.isNull())
2131 return QualType();
2132
2133 // Silently suppress qualifiers if the result type can't be qualified.
2134 // FIXME: this is the right thing for template instantiation, but
2135 // probably not for other clients.
2136 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002137 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002138
John McCall550e0c22009-10-21 00:40:46 +00002139 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2140
2141 TLB.push<QualifiedTypeLoc>(Result);
2142
2143 // No location information to preserve.
2144
2145 return Result;
2146}
2147
2148template <class TyLoc> static inline
2149QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2150 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2151 NewT.setNameLoc(T.getNameLoc());
2152 return T.getType();
2153}
2154
2155// Ugly metaprogramming macros because I couldn't be bothered to make
2156// the equivalent template version work.
2157#define TransformPointerLikeType(TypeClass) do { \
2158 QualType PointeeType \
2159 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2160 if (PointeeType.isNull()) \
2161 return QualType(); \
2162 \
2163 QualType Result = TL.getType(); \
2164 if (getDerived().AlwaysRebuild() || \
2165 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002166 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2167 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002168 if (Result.isNull()) \
2169 return QualType(); \
2170 } \
2171 \
2172 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2173 NewT.setSigilLoc(TL.getSigilLoc()); \
2174 \
2175 return Result; \
2176} while(0)
2177
John McCall550e0c22009-10-21 00:40:46 +00002178template<typename Derived>
2179QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002180 BuiltinTypeLoc T,
2181 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002182 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2183 NewT.setBuiltinLoc(T.getBuiltinLoc());
2184 if (T.needsExtraLocalData())
2185 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2186 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002187}
Mike Stump11289f42009-09-09 15:08:12 +00002188
Douglas Gregord6ff3322009-08-04 16:50:30 +00002189template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002190QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002191 ComplexTypeLoc T,
2192 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002193 // FIXME: recurse?
2194 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002195}
Mike Stump11289f42009-09-09 15:08:12 +00002196
Douglas Gregord6ff3322009-08-04 16:50:30 +00002197template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002198QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002199 PointerTypeLoc TL,
2200 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002201 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002202}
Mike Stump11289f42009-09-09 15:08:12 +00002203
2204template<typename Derived>
2205QualType
John McCall550e0c22009-10-21 00:40:46 +00002206TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002207 BlockPointerTypeLoc TL,
2208 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002209 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002210}
2211
John McCall70dd5f62009-10-30 00:06:24 +00002212/// Transforms a reference type. Note that somewhat paradoxically we
2213/// don't care whether the type itself is an l-value type or an r-value
2214/// type; we only care if the type was *written* as an l-value type
2215/// or an r-value type.
2216template<typename Derived>
2217QualType
2218TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002219 ReferenceTypeLoc TL,
2220 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002221 const ReferenceType *T = TL.getTypePtr();
2222
2223 // Note that this works with the pointee-as-written.
2224 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2225 if (PointeeType.isNull())
2226 return QualType();
2227
2228 QualType Result = TL.getType();
2229 if (getDerived().AlwaysRebuild() ||
2230 PointeeType != T->getPointeeTypeAsWritten()) {
2231 Result = getDerived().RebuildReferenceType(PointeeType,
2232 T->isSpelledAsLValue(),
2233 TL.getSigilLoc());
2234 if (Result.isNull())
2235 return QualType();
2236 }
2237
2238 // r-value references can be rebuilt as l-value references.
2239 ReferenceTypeLoc NewTL;
2240 if (isa<LValueReferenceType>(Result))
2241 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2242 else
2243 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2244 NewTL.setSigilLoc(TL.getSigilLoc());
2245
2246 return Result;
2247}
2248
Mike Stump11289f42009-09-09 15:08:12 +00002249template<typename Derived>
2250QualType
John McCall550e0c22009-10-21 00:40:46 +00002251TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002252 LValueReferenceTypeLoc TL,
2253 QualType ObjectType) {
2254 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002255}
2256
Mike Stump11289f42009-09-09 15:08:12 +00002257template<typename Derived>
2258QualType
John McCall550e0c22009-10-21 00:40:46 +00002259TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002260 RValueReferenceTypeLoc TL,
2261 QualType ObjectType) {
2262 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002263}
Mike Stump11289f42009-09-09 15:08:12 +00002264
Douglas Gregord6ff3322009-08-04 16:50:30 +00002265template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002266QualType
John McCall550e0c22009-10-21 00:40:46 +00002267TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002268 MemberPointerTypeLoc TL,
2269 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002270 MemberPointerType *T = TL.getTypePtr();
2271
2272 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002273 if (PointeeType.isNull())
2274 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002275
John McCall550e0c22009-10-21 00:40:46 +00002276 // TODO: preserve source information for this.
2277 QualType ClassType
2278 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002279 if (ClassType.isNull())
2280 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002281
John McCall550e0c22009-10-21 00:40:46 +00002282 QualType Result = TL.getType();
2283 if (getDerived().AlwaysRebuild() ||
2284 PointeeType != T->getPointeeType() ||
2285 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002286 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2287 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002288 if (Result.isNull())
2289 return QualType();
2290 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002291
John McCall550e0c22009-10-21 00:40:46 +00002292 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2293 NewTL.setSigilLoc(TL.getSigilLoc());
2294
2295 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002296}
2297
Mike Stump11289f42009-09-09 15:08:12 +00002298template<typename Derived>
2299QualType
John McCall550e0c22009-10-21 00:40:46 +00002300TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002301 ConstantArrayTypeLoc TL,
2302 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002303 ConstantArrayType *T = TL.getTypePtr();
2304 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002305 if (ElementType.isNull())
2306 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002307
John McCall550e0c22009-10-21 00:40:46 +00002308 QualType Result = TL.getType();
2309 if (getDerived().AlwaysRebuild() ||
2310 ElementType != T->getElementType()) {
2311 Result = getDerived().RebuildConstantArrayType(ElementType,
2312 T->getSizeModifier(),
2313 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002314 T->getIndexTypeCVRQualifiers(),
2315 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002316 if (Result.isNull())
2317 return QualType();
2318 }
2319
2320 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2321 NewTL.setLBracketLoc(TL.getLBracketLoc());
2322 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002323
John McCall550e0c22009-10-21 00:40:46 +00002324 Expr *Size = TL.getSizeExpr();
2325 if (Size) {
2326 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2327 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2328 }
2329 NewTL.setSizeExpr(Size);
2330
2331 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002332}
Mike Stump11289f42009-09-09 15:08:12 +00002333
Douglas Gregord6ff3322009-08-04 16:50:30 +00002334template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002335QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002336 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002337 IncompleteArrayTypeLoc TL,
2338 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002339 IncompleteArrayType *T = TL.getTypePtr();
2340 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002341 if (ElementType.isNull())
2342 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002343
John McCall550e0c22009-10-21 00:40:46 +00002344 QualType Result = TL.getType();
2345 if (getDerived().AlwaysRebuild() ||
2346 ElementType != T->getElementType()) {
2347 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002348 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002349 T->getIndexTypeCVRQualifiers(),
2350 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002351 if (Result.isNull())
2352 return QualType();
2353 }
2354
2355 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2356 NewTL.setLBracketLoc(TL.getLBracketLoc());
2357 NewTL.setRBracketLoc(TL.getRBracketLoc());
2358 NewTL.setSizeExpr(0);
2359
2360 return Result;
2361}
2362
2363template<typename Derived>
2364QualType
2365TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002366 VariableArrayTypeLoc TL,
2367 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002368 VariableArrayType *T = TL.getTypePtr();
2369 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2370 if (ElementType.isNull())
2371 return QualType();
2372
2373 // Array bounds are not potentially evaluated contexts
2374 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2375
2376 Sema::OwningExprResult SizeResult
2377 = getDerived().TransformExpr(T->getSizeExpr());
2378 if (SizeResult.isInvalid())
2379 return QualType();
2380
2381 Expr *Size = static_cast<Expr*>(SizeResult.get());
2382
2383 QualType Result = TL.getType();
2384 if (getDerived().AlwaysRebuild() ||
2385 ElementType != T->getElementType() ||
2386 Size != T->getSizeExpr()) {
2387 Result = getDerived().RebuildVariableArrayType(ElementType,
2388 T->getSizeModifier(),
2389 move(SizeResult),
2390 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002391 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002392 if (Result.isNull())
2393 return QualType();
2394 }
2395 else SizeResult.take();
2396
2397 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2398 NewTL.setLBracketLoc(TL.getLBracketLoc());
2399 NewTL.setRBracketLoc(TL.getRBracketLoc());
2400 NewTL.setSizeExpr(Size);
2401
2402 return Result;
2403}
2404
2405template<typename Derived>
2406QualType
2407TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002408 DependentSizedArrayTypeLoc TL,
2409 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002410 DependentSizedArrayType *T = TL.getTypePtr();
2411 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2412 if (ElementType.isNull())
2413 return QualType();
2414
2415 // Array bounds are not potentially evaluated contexts
2416 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2417
2418 Sema::OwningExprResult SizeResult
2419 = getDerived().TransformExpr(T->getSizeExpr());
2420 if (SizeResult.isInvalid())
2421 return QualType();
2422
2423 Expr *Size = static_cast<Expr*>(SizeResult.get());
2424
2425 QualType Result = TL.getType();
2426 if (getDerived().AlwaysRebuild() ||
2427 ElementType != T->getElementType() ||
2428 Size != T->getSizeExpr()) {
2429 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2430 T->getSizeModifier(),
2431 move(SizeResult),
2432 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002433 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002434 if (Result.isNull())
2435 return QualType();
2436 }
2437 else SizeResult.take();
2438
2439 // We might have any sort of array type now, but fortunately they
2440 // all have the same location layout.
2441 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2442 NewTL.setLBracketLoc(TL.getLBracketLoc());
2443 NewTL.setRBracketLoc(TL.getRBracketLoc());
2444 NewTL.setSizeExpr(Size);
2445
2446 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002447}
Mike Stump11289f42009-09-09 15:08:12 +00002448
2449template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002450QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002451 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002452 DependentSizedExtVectorTypeLoc TL,
2453 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002454 DependentSizedExtVectorType *T = TL.getTypePtr();
2455
2456 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002457 QualType ElementType = getDerived().TransformType(T->getElementType());
2458 if (ElementType.isNull())
2459 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002460
Douglas Gregore922c772009-08-04 22:27:00 +00002461 // Vector sizes are not potentially evaluated contexts
2462 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2463
Douglas Gregord6ff3322009-08-04 16:50:30 +00002464 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2465 if (Size.isInvalid())
2466 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002467
John McCall550e0c22009-10-21 00:40:46 +00002468 QualType Result = TL.getType();
2469 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002470 ElementType != T->getElementType() ||
2471 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002472 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002473 move(Size),
2474 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002475 if (Result.isNull())
2476 return QualType();
2477 }
2478 else Size.take();
2479
2480 // Result might be dependent or not.
2481 if (isa<DependentSizedExtVectorType>(Result)) {
2482 DependentSizedExtVectorTypeLoc NewTL
2483 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2484 NewTL.setNameLoc(TL.getNameLoc());
2485 } else {
2486 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2487 NewTL.setNameLoc(TL.getNameLoc());
2488 }
2489
2490 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002491}
Mike Stump11289f42009-09-09 15:08:12 +00002492
2493template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002494QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002495 VectorTypeLoc TL,
2496 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002497 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002498 QualType ElementType = getDerived().TransformType(T->getElementType());
2499 if (ElementType.isNull())
2500 return QualType();
2501
John McCall550e0c22009-10-21 00:40:46 +00002502 QualType Result = TL.getType();
2503 if (getDerived().AlwaysRebuild() ||
2504 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002505 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2506 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002507 if (Result.isNull())
2508 return QualType();
2509 }
2510
2511 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2512 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002513
John McCall550e0c22009-10-21 00:40:46 +00002514 return Result;
2515}
2516
2517template<typename Derived>
2518QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002519 ExtVectorTypeLoc TL,
2520 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002521 VectorType *T = TL.getTypePtr();
2522 QualType ElementType = getDerived().TransformType(T->getElementType());
2523 if (ElementType.isNull())
2524 return QualType();
2525
2526 QualType Result = TL.getType();
2527 if (getDerived().AlwaysRebuild() ||
2528 ElementType != T->getElementType()) {
2529 Result = getDerived().RebuildExtVectorType(ElementType,
2530 T->getNumElements(),
2531 /*FIXME*/ SourceLocation());
2532 if (Result.isNull())
2533 return QualType();
2534 }
2535
2536 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2537 NewTL.setNameLoc(TL.getNameLoc());
2538
2539 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540}
Mike Stump11289f42009-09-09 15:08:12 +00002541
2542template<typename Derived>
2543QualType
John McCall550e0c22009-10-21 00:40:46 +00002544TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002545 FunctionProtoTypeLoc TL,
2546 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002547 FunctionProtoType *T = TL.getTypePtr();
2548 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002549 if (ResultType.isNull())
2550 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002551
John McCall550e0c22009-10-21 00:40:46 +00002552 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002553 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002554 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2555 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2556 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002557
John McCall550e0c22009-10-21 00:40:46 +00002558 QualType NewType;
2559 ParmVarDecl *NewParm;
2560
2561 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002562 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002563 assert(OldDI->getType() == T->getArgType(i));
2564
John McCallbcd03502009-12-07 02:54:59 +00002565 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002566 if (!NewDI)
2567 return QualType();
2568
2569 if (NewDI == OldDI)
2570 NewParm = OldParm;
2571 else
2572 NewParm = ParmVarDecl::Create(SemaRef.Context,
2573 OldParm->getDeclContext(),
2574 OldParm->getLocation(),
2575 OldParm->getIdentifier(),
2576 NewDI->getType(),
2577 NewDI,
2578 OldParm->getStorageClass(),
2579 /* DefArg */ NULL);
2580 NewType = NewParm->getType();
2581
2582 // Deal with the possibility that we don't have a parameter
2583 // declaration for this parameter.
2584 } else {
2585 NewParm = 0;
2586
2587 QualType OldType = T->getArgType(i);
2588 NewType = getDerived().TransformType(OldType);
2589 if (NewType.isNull())
2590 return QualType();
2591 }
2592
2593 ParamTypes.push_back(NewType);
2594 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595 }
Mike Stump11289f42009-09-09 15:08:12 +00002596
John McCall550e0c22009-10-21 00:40:46 +00002597 QualType Result = TL.getType();
2598 if (getDerived().AlwaysRebuild() ||
2599 ResultType != T->getResultType() ||
2600 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2601 Result = getDerived().RebuildFunctionProtoType(ResultType,
2602 ParamTypes.data(),
2603 ParamTypes.size(),
2604 T->isVariadic(),
2605 T->getTypeQuals());
2606 if (Result.isNull())
2607 return QualType();
2608 }
Mike Stump11289f42009-09-09 15:08:12 +00002609
John McCall550e0c22009-10-21 00:40:46 +00002610 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2611 NewTL.setLParenLoc(TL.getLParenLoc());
2612 NewTL.setRParenLoc(TL.getRParenLoc());
2613 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2614 NewTL.setArg(i, ParamDecls[i]);
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>
2620QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002621 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002622 FunctionNoProtoTypeLoc TL,
2623 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002624 FunctionNoProtoType *T = TL.getTypePtr();
2625 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2626 if (ResultType.isNull())
2627 return QualType();
2628
2629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 ResultType != T->getResultType())
2632 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2633
2634 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2635 NewTL.setLParenLoc(TL.getLParenLoc());
2636 NewTL.setRParenLoc(TL.getRParenLoc());
2637
2638 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002639}
Mike Stump11289f42009-09-09 15:08:12 +00002640
John McCallb96ec562009-12-04 22:46:56 +00002641template<typename Derived> QualType
2642TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002643 UnresolvedUsingTypeLoc TL,
2644 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002645 UnresolvedUsingType *T = TL.getTypePtr();
2646 Decl *D = getDerived().TransformDecl(T->getDecl());
2647 if (!D)
2648 return QualType();
2649
2650 QualType Result = TL.getType();
2651 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2652 Result = getDerived().RebuildUnresolvedUsingType(D);
2653 if (Result.isNull())
2654 return QualType();
2655 }
2656
2657 // We might get an arbitrary type spec type back. We should at
2658 // least always get a type spec type, though.
2659 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2660 NewTL.setNameLoc(TL.getNameLoc());
2661
2662 return Result;
2663}
2664
Douglas Gregord6ff3322009-08-04 16:50:30 +00002665template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002666QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002667 TypedefTypeLoc TL,
2668 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002669 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002670 TypedefDecl *Typedef
2671 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2672 if (!Typedef)
2673 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002674
John McCall550e0c22009-10-21 00:40:46 +00002675 QualType Result = TL.getType();
2676 if (getDerived().AlwaysRebuild() ||
2677 Typedef != T->getDecl()) {
2678 Result = getDerived().RebuildTypedefType(Typedef);
2679 if (Result.isNull())
2680 return QualType();
2681 }
Mike Stump11289f42009-09-09 15:08:12 +00002682
John McCall550e0c22009-10-21 00:40:46 +00002683 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2684 NewTL.setNameLoc(TL.getNameLoc());
2685
2686 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687}
Mike Stump11289f42009-09-09 15:08:12 +00002688
Douglas Gregord6ff3322009-08-04 16:50:30 +00002689template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002690QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002691 TypeOfExprTypeLoc TL,
2692 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002693 // typeof expressions are not potentially evaluated contexts
2694 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002695
John McCalle8595032010-01-13 20:03:27 +00002696 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002697 if (E.isInvalid())
2698 return QualType();
2699
John McCall550e0c22009-10-21 00:40:46 +00002700 QualType Result = TL.getType();
2701 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002702 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002703 Result = getDerived().RebuildTypeOfExprType(move(E));
2704 if (Result.isNull())
2705 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002706 }
John McCall550e0c22009-10-21 00:40:46 +00002707 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002708
John McCall550e0c22009-10-21 00:40:46 +00002709 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002710 NewTL.setTypeofLoc(TL.getTypeofLoc());
2711 NewTL.setLParenLoc(TL.getLParenLoc());
2712 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002713
2714 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002715}
Mike Stump11289f42009-09-09 15:08:12 +00002716
2717template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002718QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002719 TypeOfTypeLoc TL,
2720 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002721 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2722 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2723 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002724 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002725
John McCall550e0c22009-10-21 00:40:46 +00002726 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002727 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2728 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002729 if (Result.isNull())
2730 return QualType();
2731 }
Mike Stump11289f42009-09-09 15:08:12 +00002732
John McCall550e0c22009-10-21 00:40:46 +00002733 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002734 NewTL.setTypeofLoc(TL.getTypeofLoc());
2735 NewTL.setLParenLoc(TL.getLParenLoc());
2736 NewTL.setRParenLoc(TL.getRParenLoc());
2737 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002738
2739 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002740}
Mike Stump11289f42009-09-09 15:08:12 +00002741
2742template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002743QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002744 DecltypeTypeLoc TL,
2745 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002746 DecltypeType *T = TL.getTypePtr();
2747
Douglas Gregore922c772009-08-04 22:27:00 +00002748 // decltype expressions are not potentially evaluated contexts
2749 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002750
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2752 if (E.isInvalid())
2753 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002754
John McCall550e0c22009-10-21 00:40:46 +00002755 QualType Result = TL.getType();
2756 if (getDerived().AlwaysRebuild() ||
2757 E.get() != T->getUnderlyingExpr()) {
2758 Result = getDerived().RebuildDecltypeType(move(E));
2759 if (Result.isNull())
2760 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002761 }
John McCall550e0c22009-10-21 00:40:46 +00002762 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002763
John McCall550e0c22009-10-21 00:40:46 +00002764 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2765 NewTL.setNameLoc(TL.getNameLoc());
2766
2767 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002768}
2769
2770template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002771QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002772 RecordTypeLoc TL,
2773 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002774 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002775 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002776 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777 if (!Record)
2778 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002779
John McCall550e0c22009-10-21 00:40:46 +00002780 QualType Result = TL.getType();
2781 if (getDerived().AlwaysRebuild() ||
2782 Record != T->getDecl()) {
2783 Result = getDerived().RebuildRecordType(Record);
2784 if (Result.isNull())
2785 return QualType();
2786 }
Mike Stump11289f42009-09-09 15:08:12 +00002787
John McCall550e0c22009-10-21 00:40:46 +00002788 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2789 NewTL.setNameLoc(TL.getNameLoc());
2790
2791 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002792}
Mike Stump11289f42009-09-09 15:08:12 +00002793
2794template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002795QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002796 EnumTypeLoc TL,
2797 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002798 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002800 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002801 if (!Enum)
2802 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002803
John McCall550e0c22009-10-21 00:40:46 +00002804 QualType Result = TL.getType();
2805 if (getDerived().AlwaysRebuild() ||
2806 Enum != T->getDecl()) {
2807 Result = getDerived().RebuildEnumType(Enum);
2808 if (Result.isNull())
2809 return QualType();
2810 }
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
2814
2815 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002816}
John McCallfcc33b02009-09-05 00:15:47 +00002817
2818template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002819QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002820 ElaboratedTypeLoc TL,
2821 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002822 ElaboratedType *T = TL.getTypePtr();
2823
2824 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002825 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2826 if (Underlying.isNull())
2827 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002828
John McCall550e0c22009-10-21 00:40:46 +00002829 QualType Result = TL.getType();
2830 if (getDerived().AlwaysRebuild() ||
2831 Underlying != T->getUnderlyingType()) {
2832 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2833 if (Result.isNull())
2834 return QualType();
2835 }
Mike Stump11289f42009-09-09 15:08:12 +00002836
John McCall550e0c22009-10-21 00:40:46 +00002837 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2838 NewTL.setNameLoc(TL.getNameLoc());
2839
2840 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002841}
Mike Stump11289f42009-09-09 15:08:12 +00002842
2843
Douglas Gregord6ff3322009-08-04 16:50:30 +00002844template<typename Derived>
2845QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002846 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002847 TemplateTypeParmTypeLoc TL,
2848 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002849 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002850}
2851
Mike Stump11289f42009-09-09 15:08:12 +00002852template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002853QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002854 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002855 SubstTemplateTypeParmTypeLoc TL,
2856 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002857 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002858}
2859
2860template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002861QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2862 const TemplateSpecializationType *TST,
2863 QualType ObjectType) {
2864 // FIXME: this entire method is a temporary workaround; callers
2865 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002866
John McCall0ad16662009-10-29 08:12:44 +00002867 // Fake up a TemplateSpecializationTypeLoc.
2868 TypeLocBuilder TLB;
2869 TemplateSpecializationTypeLoc TL
2870 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2871
John McCall0d07eb32009-10-29 18:45:58 +00002872 SourceLocation BaseLoc = getDerived().getBaseLocation();
2873
2874 TL.setTemplateNameLoc(BaseLoc);
2875 TL.setLAngleLoc(BaseLoc);
2876 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002877 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2878 const TemplateArgument &TA = TST->getArg(i);
2879 TemplateArgumentLoc TAL;
2880 getDerived().InventTemplateArgumentLoc(TA, TAL);
2881 TL.setArgLocInfo(i, TAL.getLocInfo());
2882 }
2883
2884 TypeLocBuilder IgnoredTLB;
2885 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002886}
2887
2888template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002889QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002890 TypeLocBuilder &TLB,
2891 TemplateSpecializationTypeLoc TL,
2892 QualType ObjectType) {
2893 const TemplateSpecializationType *T = TL.getTypePtr();
2894
Mike Stump11289f42009-09-09 15:08:12 +00002895 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002896 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002897 if (Template.isNull())
2898 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002899
John McCall6b51f282009-11-23 01:53:49 +00002900 TemplateArgumentListInfo NewTemplateArgs;
2901 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2902 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2903
2904 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2905 TemplateArgumentLoc Loc;
2906 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002907 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002908 NewTemplateArgs.addArgument(Loc);
2909 }
Mike Stump11289f42009-09-09 15:08:12 +00002910
John McCall0ad16662009-10-29 08:12:44 +00002911 // FIXME: maybe don't rebuild if all the template arguments are the same.
2912
2913 QualType Result =
2914 getDerived().RebuildTemplateSpecializationType(Template,
2915 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002916 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002917
2918 if (!Result.isNull()) {
2919 TemplateSpecializationTypeLoc NewTL
2920 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2921 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2922 NewTL.setLAngleLoc(TL.getLAngleLoc());
2923 NewTL.setRAngleLoc(TL.getRAngleLoc());
2924 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2925 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002926 }
Mike Stump11289f42009-09-09 15:08:12 +00002927
John McCall0ad16662009-10-29 08:12:44 +00002928 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002929}
Mike Stump11289f42009-09-09 15:08:12 +00002930
2931template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002932QualType
2933TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002934 QualifiedNameTypeLoc TL,
2935 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002936 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002937 NestedNameSpecifier *NNS
2938 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002939 SourceRange(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00002940 false,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002941 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002942 if (!NNS)
2943 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002944
Douglas Gregord6ff3322009-08-04 16:50:30 +00002945 QualType Named = getDerived().TransformType(T->getNamedType());
2946 if (Named.isNull())
2947 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002948
John McCall550e0c22009-10-21 00:40:46 +00002949 QualType Result = TL.getType();
2950 if (getDerived().AlwaysRebuild() ||
2951 NNS != T->getQualifier() ||
2952 Named != T->getNamedType()) {
2953 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2954 if (Result.isNull())
2955 return QualType();
2956 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957
John McCall550e0c22009-10-21 00:40:46 +00002958 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2959 NewTL.setNameLoc(TL.getNameLoc());
2960
2961 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002962}
Mike Stump11289f42009-09-09 15:08:12 +00002963
2964template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002965QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002966 TypenameTypeLoc TL,
2967 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002968 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002969
2970 /* FIXME: preserve source information better than this */
2971 SourceRange SR(TL.getNameLoc());
2972
Douglas Gregord6ff3322009-08-04 16:50:30 +00002973 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00002974 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregor90d554e2010-02-21 18:36:56 +00002975 false, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002976 if (!NNS)
2977 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCall550e0c22009-10-21 00:40:46 +00002979 QualType Result;
2980
Douglas Gregord6ff3322009-08-04 16:50:30 +00002981 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002982 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002983 = getDerived().TransformType(QualType(TemplateId, 0));
2984 if (NewTemplateId.isNull())
2985 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987 if (!getDerived().AlwaysRebuild() &&
2988 NNS == T->getQualifier() &&
2989 NewTemplateId == QualType(TemplateId, 0))
2990 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002991
John McCall550e0c22009-10-21 00:40:46 +00002992 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2993 } else {
John McCall0ad16662009-10-29 08:12:44 +00002994 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 }
John McCall550e0c22009-10-21 00:40:46 +00002996 if (Result.isNull())
2997 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002998
John McCall550e0c22009-10-21 00:40:46 +00002999 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
3000 NewTL.setNameLoc(TL.getNameLoc());
3001
3002 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003003}
Mike Stump11289f42009-09-09 15:08:12 +00003004
Douglas Gregord6ff3322009-08-04 16:50:30 +00003005template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003006QualType
3007TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003008 ObjCInterfaceTypeLoc TL,
3009 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003010 assert(false && "TransformObjCInterfaceType unimplemented");
3011 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012}
Mike Stump11289f42009-09-09 15:08:12 +00003013
3014template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003015QualType
3016TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003017 ObjCObjectPointerTypeLoc TL,
3018 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00003019 assert(false && "TransformObjCObjectPointerType unimplemented");
3020 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003021}
3022
Douglas Gregord6ff3322009-08-04 16:50:30 +00003023//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003024// Statement transformation
3025//===----------------------------------------------------------------------===//
3026template<typename Derived>
3027Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003028TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3029 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003030}
3031
3032template<typename Derived>
3033Sema::OwningStmtResult
3034TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3035 return getDerived().TransformCompoundStmt(S, false);
3036}
3037
3038template<typename Derived>
3039Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003040TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003041 bool IsStmtExpr) {
3042 bool SubStmtChanged = false;
3043 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3044 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3045 B != BEnd; ++B) {
3046 OwningStmtResult Result = getDerived().TransformStmt(*B);
3047 if (Result.isInvalid())
3048 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003049
Douglas Gregorebe10102009-08-20 07:17:43 +00003050 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3051 Statements.push_back(Result.takeAs<Stmt>());
3052 }
Mike Stump11289f42009-09-09 15:08:12 +00003053
Douglas Gregorebe10102009-08-20 07:17:43 +00003054 if (!getDerived().AlwaysRebuild() &&
3055 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003056 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003057
3058 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3059 move_arg(Statements),
3060 S->getRBracLoc(),
3061 IsStmtExpr);
3062}
Mike Stump11289f42009-09-09 15:08:12 +00003063
Douglas Gregorebe10102009-08-20 07:17:43 +00003064template<typename Derived>
3065Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003066TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003067 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3068 {
3069 // The case value expressions are not potentially evaluated.
3070 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003071
Eli Friedman06577382009-11-19 03:14:00 +00003072 // Transform the left-hand case value.
3073 LHS = getDerived().TransformExpr(S->getLHS());
3074 if (LHS.isInvalid())
3075 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003076
Eli Friedman06577382009-11-19 03:14:00 +00003077 // Transform the right-hand case value (for the GNU case-range extension).
3078 RHS = getDerived().TransformExpr(S->getRHS());
3079 if (RHS.isInvalid())
3080 return SemaRef.StmtError();
3081 }
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregorebe10102009-08-20 07:17:43 +00003083 // Build the case statement.
3084 // Case statements are always rebuilt so that they will attached to their
3085 // transformed switch statement.
3086 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3087 move(LHS),
3088 S->getEllipsisLoc(),
3089 move(RHS),
3090 S->getColonLoc());
3091 if (Case.isInvalid())
3092 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003093
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 // Transform the statement following the case
3095 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3096 if (SubStmt.isInvalid())
3097 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003098
Douglas Gregorebe10102009-08-20 07:17:43 +00003099 // Attach the body to the case statement
3100 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3101}
3102
3103template<typename Derived>
3104Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003105TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003106 // Transform the statement following the default case
3107 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3108 if (SubStmt.isInvalid())
3109 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003110
Douglas Gregorebe10102009-08-20 07:17:43 +00003111 // Default statements are always rebuilt
3112 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3113 move(SubStmt));
3114}
Mike Stump11289f42009-09-09 15:08:12 +00003115
Douglas Gregorebe10102009-08-20 07:17:43 +00003116template<typename Derived>
3117Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003118TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003119 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3120 if (SubStmt.isInvalid())
3121 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003122
Douglas Gregorebe10102009-08-20 07:17:43 +00003123 // FIXME: Pass the real colon location in.
3124 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3125 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3126 move(SubStmt));
3127}
Mike Stump11289f42009-09-09 15:08:12 +00003128
Douglas Gregorebe10102009-08-20 07:17:43 +00003129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003130Sema::OwningStmtResult
3131TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003132 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003133 OwningExprResult Cond(SemaRef);
3134 VarDecl *ConditionVar = 0;
3135 if (S->getConditionVariable()) {
3136 ConditionVar
3137 = cast_or_null<VarDecl>(
3138 getDerived().TransformDefinition(S->getConditionVariable()));
3139 if (!ConditionVar)
3140 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003141 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003142 Cond = getDerived().TransformExpr(S->getCond());
3143
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003144 if (Cond.isInvalid())
3145 return SemaRef.StmtError();
3146 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003147
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003148 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregorebe10102009-08-20 07:17:43 +00003150 // Transform the "then" branch.
3151 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3152 if (Then.isInvalid())
3153 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003154
Douglas Gregorebe10102009-08-20 07:17:43 +00003155 // Transform the "else" branch.
3156 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3157 if (Else.isInvalid())
3158 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003159
Douglas Gregorebe10102009-08-20 07:17:43 +00003160 if (!getDerived().AlwaysRebuild() &&
3161 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003162 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003163 Then.get() == S->getThen() &&
3164 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003165 return SemaRef.Owned(S->Retain());
3166
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003167 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3168 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003169 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003170}
3171
3172template<typename Derived>
3173Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003174TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003175 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003176 OwningExprResult Cond(SemaRef);
3177 VarDecl *ConditionVar = 0;
3178 if (S->getConditionVariable()) {
3179 ConditionVar
3180 = cast_or_null<VarDecl>(
3181 getDerived().TransformDefinition(S->getConditionVariable()));
3182 if (!ConditionVar)
3183 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003184 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003185 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003186
3187 if (Cond.isInvalid())
3188 return SemaRef.StmtError();
3189 }
Mike Stump11289f42009-09-09 15:08:12 +00003190
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003191 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003192
Douglas Gregorebe10102009-08-20 07:17:43 +00003193 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003194 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3195 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003196 if (Switch.isInvalid())
3197 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003198
Douglas Gregorebe10102009-08-20 07:17:43 +00003199 // Transform the body of the switch statement.
3200 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3201 if (Body.isInvalid())
3202 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregorebe10102009-08-20 07:17:43 +00003204 // Complete the switch statement.
3205 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3206 move(Body));
3207}
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregorebe10102009-08-20 07:17:43 +00003209template<typename Derived>
3210Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003211TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003212 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003213 OwningExprResult Cond(SemaRef);
3214 VarDecl *ConditionVar = 0;
3215 if (S->getConditionVariable()) {
3216 ConditionVar
3217 = cast_or_null<VarDecl>(
3218 getDerived().TransformDefinition(S->getConditionVariable()));
3219 if (!ConditionVar)
3220 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003221 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003222 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003223
3224 if (Cond.isInvalid())
3225 return SemaRef.StmtError();
3226 }
Mike Stump11289f42009-09-09 15:08:12 +00003227
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003228 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003229
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 // Transform the body
3231 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3232 if (Body.isInvalid())
3233 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 if (!getDerived().AlwaysRebuild() &&
3236 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003237 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003238 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003239 return SemaRef.Owned(S->Retain());
3240
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003241 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3242 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003243}
Mike Stump11289f42009-09-09 15:08:12 +00003244
Douglas Gregorebe10102009-08-20 07:17:43 +00003245template<typename Derived>
3246Sema::OwningStmtResult
3247TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3248 // Transform the condition
3249 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3250 if (Cond.isInvalid())
3251 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003252
Douglas Gregorebe10102009-08-20 07:17:43 +00003253 // Transform the body
3254 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3255 if (Body.isInvalid())
3256 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003257
Douglas Gregorebe10102009-08-20 07:17:43 +00003258 if (!getDerived().AlwaysRebuild() &&
3259 Cond.get() == S->getCond() &&
3260 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003261 return SemaRef.Owned(S->Retain());
3262
Douglas Gregorebe10102009-08-20 07:17:43 +00003263 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3264 /*FIXME:*/S->getWhileLoc(), move(Cond),
3265 S->getRParenLoc());
3266}
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>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 // Transform the initialization statement
3272 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3273 if (Init.isInvalid())
3274 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003277 OwningExprResult Cond(SemaRef);
3278 VarDecl *ConditionVar = 0;
3279 if (S->getConditionVariable()) {
3280 ConditionVar
3281 = cast_or_null<VarDecl>(
3282 getDerived().TransformDefinition(S->getConditionVariable()));
3283 if (!ConditionVar)
3284 return SemaRef.StmtError();
3285 } else {
3286 Cond = getDerived().TransformExpr(S->getCond());
3287
3288 if (Cond.isInvalid())
3289 return SemaRef.StmtError();
3290 }
Mike Stump11289f42009-09-09 15:08:12 +00003291
Douglas Gregorebe10102009-08-20 07:17:43 +00003292 // Transform the increment
3293 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3294 if (Inc.isInvalid())
3295 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003296
Douglas Gregorebe10102009-08-20 07:17:43 +00003297 // Transform the body
3298 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3299 if (Body.isInvalid())
3300 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003301
Douglas Gregorebe10102009-08-20 07:17:43 +00003302 if (!getDerived().AlwaysRebuild() &&
3303 Init.get() == S->getInit() &&
3304 Cond.get() == S->getCond() &&
3305 Inc.get() == S->getInc() &&
3306 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003307 return SemaRef.Owned(S->Retain());
3308
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003310 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003311 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003312 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003313 S->getRParenLoc(), move(Body));
3314}
3315
3316template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003317Sema::OwningStmtResult
3318TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003319 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003320 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003321 S->getLabel());
3322}
3323
3324template<typename Derived>
3325Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003326TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003327 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3328 if (Target.isInvalid())
3329 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003330
Douglas Gregorebe10102009-08-20 07:17:43 +00003331 if (!getDerived().AlwaysRebuild() &&
3332 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003333 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003334
3335 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3336 move(Target));
3337}
3338
3339template<typename Derived>
3340Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003341TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3342 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003343}
Mike Stump11289f42009-09-09 15:08:12 +00003344
Douglas Gregorebe10102009-08-20 07:17:43 +00003345template<typename Derived>
3346Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003347TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3348 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003349}
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregorebe10102009-08-20 07:17:43 +00003351template<typename Derived>
3352Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003353TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003354 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3355 if (Result.isInvalid())
3356 return SemaRef.StmtError();
3357
Mike Stump11289f42009-09-09 15:08:12 +00003358 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003359 // to tell whether the return type of the function has changed.
3360 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3361}
Mike Stump11289f42009-09-09 15:08:12 +00003362
Douglas Gregorebe10102009-08-20 07:17:43 +00003363template<typename Derived>
3364Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003365TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003366 bool DeclChanged = false;
3367 llvm::SmallVector<Decl *, 4> Decls;
3368 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3369 D != DEnd; ++D) {
3370 Decl *Transformed = getDerived().TransformDefinition(*D);
3371 if (!Transformed)
3372 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003373
Douglas Gregorebe10102009-08-20 07:17:43 +00003374 if (Transformed != *D)
3375 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003376
Douglas Gregorebe10102009-08-20 07:17:43 +00003377 Decls.push_back(Transformed);
3378 }
Mike Stump11289f42009-09-09 15:08:12 +00003379
Douglas Gregorebe10102009-08-20 07:17:43 +00003380 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003381 return SemaRef.Owned(S->Retain());
3382
3383 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003384 S->getStartLoc(), S->getEndLoc());
3385}
Mike Stump11289f42009-09-09 15:08:12 +00003386
Douglas Gregorebe10102009-08-20 07:17:43 +00003387template<typename Derived>
3388Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003389TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003390 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003391 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003392}
3393
3394template<typename Derived>
3395Sema::OwningStmtResult
3396TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003397
3398 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3399 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003400 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003401
Anders Carlssonaaeef072010-01-24 05:50:09 +00003402 OwningExprResult AsmString(SemaRef);
3403 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3404
3405 bool ExprsChanged = false;
3406
3407 // Go through the outputs.
3408 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003409 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003410
Anders Carlssonaaeef072010-01-24 05:50:09 +00003411 // No need to transform the constraint literal.
3412 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3413
3414 // Transform the output expr.
3415 Expr *OutputExpr = S->getOutputExpr(I);
3416 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3417 if (Result.isInvalid())
3418 return SemaRef.StmtError();
3419
3420 ExprsChanged |= Result.get() != OutputExpr;
3421
3422 Exprs.push_back(Result.takeAs<Expr>());
3423 }
3424
3425 // Go through the inputs.
3426 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003427 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003428
Anders Carlssonaaeef072010-01-24 05:50:09 +00003429 // No need to transform the constraint literal.
3430 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3431
3432 // Transform the input expr.
3433 Expr *InputExpr = S->getInputExpr(I);
3434 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3435 if (Result.isInvalid())
3436 return SemaRef.StmtError();
3437
3438 ExprsChanged |= Result.get() != InputExpr;
3439
3440 Exprs.push_back(Result.takeAs<Expr>());
3441 }
3442
3443 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3444 return SemaRef.Owned(S->Retain());
3445
3446 // Go through the clobbers.
3447 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3448 Clobbers.push_back(S->getClobber(I)->Retain());
3449
3450 // No need to transform the asm string literal.
3451 AsmString = SemaRef.Owned(S->getAsmString());
3452
3453 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3454 S->isSimple(),
3455 S->isVolatile(),
3456 S->getNumOutputs(),
3457 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003458 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003459 move_arg(Constraints),
3460 move_arg(Exprs),
3461 move(AsmString),
3462 move_arg(Clobbers),
3463 S->getRParenLoc(),
3464 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003465}
3466
3467
3468template<typename Derived>
3469Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003470TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003471 // FIXME: Implement this
3472 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003473 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003474}
Mike Stump11289f42009-09-09 15:08:12 +00003475
Douglas Gregorebe10102009-08-20 07:17:43 +00003476template<typename Derived>
3477Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003478TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003479 // FIXME: Implement this
3480 assert(false && "Cannot transform an Objective-C @catch statement");
3481 return SemaRef.Owned(S->Retain());
3482}
Mike Stump11289f42009-09-09 15:08:12 +00003483
Douglas Gregorebe10102009-08-20 07:17:43 +00003484template<typename Derived>
3485Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003486TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003487 // FIXME: Implement this
3488 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003489 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003490}
Mike Stump11289f42009-09-09 15:08:12 +00003491
Douglas Gregorebe10102009-08-20 07:17:43 +00003492template<typename Derived>
3493Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003494TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003495 // FIXME: Implement this
3496 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003497 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003498}
Mike Stump11289f42009-09-09 15:08:12 +00003499
Douglas Gregorebe10102009-08-20 07:17:43 +00003500template<typename Derived>
3501Sema::OwningStmtResult
3502TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003503 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003504 // FIXME: Implement this
3505 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003506 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003507}
3508
3509template<typename Derived>
3510Sema::OwningStmtResult
3511TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003512 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003513 // FIXME: Implement this
3514 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003515 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003516}
3517
3518
3519template<typename Derived>
3520Sema::OwningStmtResult
3521TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3522 // Transform the exception declaration, if any.
3523 VarDecl *Var = 0;
3524 if (S->getExceptionDecl()) {
3525 VarDecl *ExceptionDecl = S->getExceptionDecl();
3526 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3527 ExceptionDecl->getDeclName());
3528
3529 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3530 if (T.isNull())
3531 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003532
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3534 T,
John McCallbcd03502009-12-07 02:54:59 +00003535 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003536 ExceptionDecl->getIdentifier(),
3537 ExceptionDecl->getLocation(),
3538 /*FIXME: Inaccurate*/
3539 SourceRange(ExceptionDecl->getLocation()));
3540 if (!Var || Var->isInvalidDecl()) {
3541 if (Var)
3542 Var->Destroy(SemaRef.Context);
3543 return SemaRef.StmtError();
3544 }
3545 }
Mike Stump11289f42009-09-09 15:08:12 +00003546
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 // Transform the actual exception handler.
3548 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3549 if (Handler.isInvalid()) {
3550 if (Var)
3551 Var->Destroy(SemaRef.Context);
3552 return SemaRef.StmtError();
3553 }
Mike Stump11289f42009-09-09 15:08:12 +00003554
Douglas Gregorebe10102009-08-20 07:17:43 +00003555 if (!getDerived().AlwaysRebuild() &&
3556 !Var &&
3557 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003558 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003559
3560 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3561 Var,
3562 move(Handler));
3563}
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregorebe10102009-08-20 07:17:43 +00003565template<typename Derived>
3566Sema::OwningStmtResult
3567TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3568 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003569 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003570 = getDerived().TransformCompoundStmt(S->getTryBlock());
3571 if (TryBlock.isInvalid())
3572 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 // Transform the handlers.
3575 bool HandlerChanged = false;
3576 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3577 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003578 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3580 if (Handler.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3584 Handlers.push_back(Handler.takeAs<Stmt>());
3585 }
Mike Stump11289f42009-09-09 15:08:12 +00003586
Douglas Gregorebe10102009-08-20 07:17:43 +00003587 if (!getDerived().AlwaysRebuild() &&
3588 TryBlock.get() == S->getTryBlock() &&
3589 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003590 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003591
3592 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003593 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003594}
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregorebe10102009-08-20 07:17:43 +00003596//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003597// Expression transformation
3598//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003599template<typename Derived>
3600Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003601TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003602 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003603}
Mike Stump11289f42009-09-09 15:08:12 +00003604
3605template<typename Derived>
3606Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003607TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003608 NestedNameSpecifier *Qualifier = 0;
3609 if (E->getQualifier()) {
3610 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00003611 E->getQualifierRange(),
3612 false);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003613 if (!Qualifier)
3614 return SemaRef.ExprError();
3615 }
John McCallce546572009-12-08 09:08:17 +00003616
3617 ValueDecl *ND
3618 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003619 if (!ND)
3620 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003621
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003622 if (!getDerived().AlwaysRebuild() &&
3623 Qualifier == E->getQualifier() &&
3624 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003625 !E->hasExplicitTemplateArgumentList()) {
3626
3627 // Mark it referenced in the new context regardless.
3628 // FIXME: this is a bit instantiation-specific.
3629 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3630
Mike Stump11289f42009-09-09 15:08:12 +00003631 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003632 }
John McCallce546572009-12-08 09:08:17 +00003633
3634 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3635 if (E->hasExplicitTemplateArgumentList()) {
3636 TemplateArgs = &TransArgs;
3637 TransArgs.setLAngleLoc(E->getLAngleLoc());
3638 TransArgs.setRAngleLoc(E->getRAngleLoc());
3639 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3640 TemplateArgumentLoc Loc;
3641 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3642 return SemaRef.ExprError();
3643 TransArgs.addArgument(Loc);
3644 }
3645 }
3646
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003647 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003648 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003649}
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregora16548e2009-08-11 05:31:07 +00003651template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003652Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003653TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003654 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003655}
Mike Stump11289f42009-09-09 15:08:12 +00003656
Douglas Gregora16548e2009-08-11 05:31:07 +00003657template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003658Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003659TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003660 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003661}
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregora16548e2009-08-11 05:31:07 +00003663template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003664Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003665TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003666 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003667}
Mike Stump11289f42009-09-09 15:08:12 +00003668
Douglas Gregora16548e2009-08-11 05:31:07 +00003669template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003670Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003671TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003672 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003673}
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregora16548e2009-08-11 05:31:07 +00003675template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003676Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003677TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003678 return SemaRef.Owned(E->Retain());
3679}
3680
3681template<typename Derived>
3682Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003683TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003684 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3685 if (SubExpr.isInvalid())
3686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003687
Douglas Gregora16548e2009-08-11 05:31:07 +00003688 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003689 return SemaRef.Owned(E->Retain());
3690
3691 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003692 E->getRParen());
3693}
3694
Mike Stump11289f42009-09-09 15:08:12 +00003695template<typename Derived>
3696Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003697TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3698 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003699 if (SubExpr.isInvalid())
3700 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003701
Douglas Gregora16548e2009-08-11 05:31:07 +00003702 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003703 return SemaRef.Owned(E->Retain());
3704
Douglas Gregora16548e2009-08-11 05:31:07 +00003705 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3706 E->getOpcode(),
3707 move(SubExpr));
3708}
Mike Stump11289f42009-09-09 15:08:12 +00003709
Douglas Gregora16548e2009-08-11 05:31:07 +00003710template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003711Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003712TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003713 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003714 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003715
John McCallbcd03502009-12-07 02:54:59 +00003716 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003717 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003718 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003719
John McCall4c98fd82009-11-04 07:28:41 +00003720 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003721 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003722
John McCall4c98fd82009-11-04 07:28:41 +00003723 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003724 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003725 E->getSourceRange());
3726 }
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregora16548e2009-08-11 05:31:07 +00003728 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003729 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 // C++0x [expr.sizeof]p1:
3731 // The operand is either an expression, which is an unevaluated operand
3732 // [...]
3733 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregora16548e2009-08-11 05:31:07 +00003735 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3736 if (SubExpr.isInvalid())
3737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003738
Douglas Gregora16548e2009-08-11 05:31:07 +00003739 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3740 return SemaRef.Owned(E->Retain());
3741 }
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3744 E->isSizeOf(),
3745 E->getSourceRange());
3746}
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregora16548e2009-08-11 05:31:07 +00003748template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003749Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003750TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003751 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3752 if (LHS.isInvalid())
3753 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003754
Douglas Gregora16548e2009-08-11 05:31:07 +00003755 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3756 if (RHS.isInvalid())
3757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003758
3759
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 if (!getDerived().AlwaysRebuild() &&
3761 LHS.get() == E->getLHS() &&
3762 RHS.get() == E->getRHS())
3763 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3766 /*FIXME:*/E->getLHS()->getLocStart(),
3767 move(RHS),
3768 E->getRBracketLoc());
3769}
Mike Stump11289f42009-09-09 15:08:12 +00003770
3771template<typename Derived>
3772Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003773TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003774 // Transform the callee.
3775 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3776 if (Callee.isInvalid())
3777 return SemaRef.ExprError();
3778
3779 // Transform arguments.
3780 bool ArgChanged = false;
3781 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3782 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3783 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3784 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3785 if (Arg.isInvalid())
3786 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregora16548e2009-08-11 05:31:07 +00003788 // FIXME: Wrong source location information for the ','.
3789 FakeCommaLocs.push_back(
3790 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003791
3792 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 Args.push_back(Arg.takeAs<Expr>());
3794 }
Mike Stump11289f42009-09-09 15:08:12 +00003795
Douglas Gregora16548e2009-08-11 05:31:07 +00003796 if (!getDerived().AlwaysRebuild() &&
3797 Callee.get() == E->getCallee() &&
3798 !ArgChanged)
3799 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003800
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003802 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003803 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3804 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3805 move_arg(Args),
3806 FakeCommaLocs.data(),
3807 E->getRParenLoc());
3808}
Mike Stump11289f42009-09-09 15:08:12 +00003809
3810template<typename Derived>
3811Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003812TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003813 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3814 if (Base.isInvalid())
3815 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003816
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003817 NestedNameSpecifier *Qualifier = 0;
3818 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003819 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003820 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00003821 E->getQualifierRange(),
3822 false);
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003823 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003824 return SemaRef.ExprError();
3825 }
Mike Stump11289f42009-09-09 15:08:12 +00003826
Eli Friedman2cfcef62009-12-04 06:40:45 +00003827 ValueDecl *Member
3828 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 if (!Member)
3830 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregora16548e2009-08-11 05:31:07 +00003832 if (!getDerived().AlwaysRebuild() &&
3833 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003834 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003835 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003836 !E->hasExplicitTemplateArgumentList()) {
3837
3838 // Mark it referenced in the new context regardless.
3839 // FIXME: this is a bit instantiation-specific.
3840 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003841 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003842 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003843
John McCall6b51f282009-11-23 01:53:49 +00003844 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003845 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003846 TransArgs.setLAngleLoc(E->getLAngleLoc());
3847 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003848 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003849 TemplateArgumentLoc Loc;
3850 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003851 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003852 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003853 }
3854 }
3855
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 // FIXME: Bogus source location for the operator
3857 SourceLocation FakeOperatorLoc
3858 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3859
John McCall38836f02010-01-15 08:34:02 +00003860 // FIXME: to do this check properly, we will need to preserve the
3861 // first-qualifier-in-scope here, just in case we had a dependent
3862 // base (and therefore couldn't do the check) and a
3863 // nested-name-qualifier (and therefore could do the lookup).
3864 NamedDecl *FirstQualifierInScope = 0;
3865
Douglas Gregora16548e2009-08-11 05:31:07 +00003866 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3867 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003868 Qualifier,
3869 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003870 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003871 Member,
John McCall6b51f282009-11-23 01:53:49 +00003872 (E->hasExplicitTemplateArgumentList()
3873 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003874 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003875}
Mike Stump11289f42009-09-09 15:08:12 +00003876
Douglas Gregora16548e2009-08-11 05:31:07 +00003877template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003878Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003879TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003880 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3881 if (LHS.isInvalid())
3882 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003883
Douglas Gregora16548e2009-08-11 05:31:07 +00003884 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3885 if (RHS.isInvalid())
3886 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003887
Douglas Gregora16548e2009-08-11 05:31:07 +00003888 if (!getDerived().AlwaysRebuild() &&
3889 LHS.get() == E->getLHS() &&
3890 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003891 return SemaRef.Owned(E->Retain());
3892
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3894 move(LHS), move(RHS));
3895}
3896
Mike Stump11289f42009-09-09 15:08:12 +00003897template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003898Sema::OwningExprResult
3899TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003900 CompoundAssignOperator *E) {
3901 return getDerived().TransformBinaryOperator(E);
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>
Mike Stump11289f42009-09-09 15:08:12 +00003905Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003906TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3908 if (Cond.isInvalid())
3909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003910
Douglas Gregora16548e2009-08-11 05:31:07 +00003911 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3912 if (LHS.isInvalid())
3913 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003914
Douglas Gregora16548e2009-08-11 05:31:07 +00003915 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3916 if (RHS.isInvalid())
3917 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003918
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 if (!getDerived().AlwaysRebuild() &&
3920 Cond.get() == E->getCond() &&
3921 LHS.get() == E->getLHS() &&
3922 RHS.get() == E->getRHS())
3923 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003924
3925 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003926 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003927 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003928 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 move(RHS));
3930}
Mike Stump11289f42009-09-09 15:08:12 +00003931
3932template<typename Derived>
3933Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003934TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003935 // Implicit casts are eliminated during transformation, since they
3936 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003937 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003938}
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregora16548e2009-08-11 05:31:07 +00003940template<typename Derived>
3941Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003942TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003943 TypeSourceInfo *OldT;
3944 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003945 {
3946 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003947 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3949 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003950
John McCall97513962010-01-15 18:39:57 +00003951 OldT = E->getTypeInfoAsWritten();
3952 NewT = getDerived().TransformType(OldT);
3953 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 return SemaRef.ExprError();
3955 }
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregor6131b442009-12-12 18:16:41 +00003957 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003958 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 if (SubExpr.isInvalid())
3960 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003961
Douglas Gregora16548e2009-08-11 05:31:07 +00003962 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003963 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003965 return SemaRef.Owned(E->Retain());
3966
John McCall97513962010-01-15 18:39:57 +00003967 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3968 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003969 E->getRParenLoc(),
3970 move(SubExpr));
3971}
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003974Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003975TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003976 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3977 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3978 if (!NewT)
3979 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3982 if (Init.isInvalid())
3983 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003984
Douglas Gregora16548e2009-08-11 05:31:07 +00003985 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003986 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003987 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003988 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003989
John McCall5d7aa7f2010-01-19 22:33:45 +00003990 // Note: the expression type doesn't necessarily match the
3991 // type-as-written, but that's okay, because it should always be
3992 // derivable from the initializer.
3993
John McCalle15bbff2010-01-18 19:35:47 +00003994 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 /*FIXME:*/E->getInitializer()->getLocEnd(),
3996 move(Init));
3997}
Mike Stump11289f42009-09-09 15:08:12 +00003998
Douglas Gregora16548e2009-08-11 05:31:07 +00003999template<typename Derived>
4000Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004001TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004002 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4003 if (Base.isInvalid())
4004 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 if (!getDerived().AlwaysRebuild() &&
4007 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004008 return SemaRef.Owned(E->Retain());
4009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004011 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004012 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4013 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4014 E->getAccessorLoc(),
4015 E->getAccessor());
4016}
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregora16548e2009-08-11 05:31:07 +00004018template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004020TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004021 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregora16548e2009-08-11 05:31:07 +00004023 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4024 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4025 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4026 if (Init.isInvalid())
4027 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregora16548e2009-08-11 05:31:07 +00004029 InitChanged = InitChanged || Init.get() != E->getInit(I);
4030 Inits.push_back(Init.takeAs<Expr>());
4031 }
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004034 return SemaRef.Owned(E->Retain());
4035
Douglas Gregora16548e2009-08-11 05:31:07 +00004036 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004037 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004038}
Mike Stump11289f42009-09-09 15:08:12 +00004039
Douglas Gregora16548e2009-08-11 05:31:07 +00004040template<typename Derived>
4041Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004042TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregorebe10102009-08-20 07:17:43 +00004045 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4047 if (Init.isInvalid())
4048 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregorebe10102009-08-20 07:17:43 +00004050 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004051 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4052 bool ExprChanged = false;
4053 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4054 DEnd = E->designators_end();
4055 D != DEnd; ++D) {
4056 if (D->isFieldDesignator()) {
4057 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4058 D->getDotLoc(),
4059 D->getFieldLoc()));
4060 continue;
4061 }
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregora16548e2009-08-11 05:31:07 +00004063 if (D->isArrayDesignator()) {
4064 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4065 if (Index.isInvalid())
4066 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004067
4068 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004069 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004070
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4072 ArrayExprs.push_back(Index.release());
4073 continue;
4074 }
Mike Stump11289f42009-09-09 15:08:12 +00004075
Douglas Gregora16548e2009-08-11 05:31:07 +00004076 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004077 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004078 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4079 if (Start.isInvalid())
4080 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004081
Douglas Gregora16548e2009-08-11 05:31:07 +00004082 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4083 if (End.isInvalid())
4084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004085
4086 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 End.get(),
4088 D->getLBracketLoc(),
4089 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004090
Douglas Gregora16548e2009-08-11 05:31:07 +00004091 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4092 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004093
Douglas Gregora16548e2009-08-11 05:31:07 +00004094 ArrayExprs.push_back(Start.release());
4095 ArrayExprs.push_back(End.release());
4096 }
Mike Stump11289f42009-09-09 15:08:12 +00004097
Douglas Gregora16548e2009-08-11 05:31:07 +00004098 if (!getDerived().AlwaysRebuild() &&
4099 Init.get() == E->getInit() &&
4100 !ExprChanged)
4101 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4104 E->getEqualOrColonLoc(),
4105 E->usesGNUSyntax(), move(Init));
4106}
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004109Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004110TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004111 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004112 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4113
4114 // FIXME: Will we ever have proper type location here? Will we actually
4115 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004116 QualType T = getDerived().TransformType(E->getType());
4117 if (T.isNull())
4118 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004119
Douglas Gregora16548e2009-08-11 05:31:07 +00004120 if (!getDerived().AlwaysRebuild() &&
4121 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004122 return SemaRef.Owned(E->Retain());
4123
Douglas Gregora16548e2009-08-11 05:31:07 +00004124 return getDerived().RebuildImplicitValueInitExpr(T);
4125}
Mike Stump11289f42009-09-09 15:08:12 +00004126
Douglas Gregora16548e2009-08-11 05:31:07 +00004127template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004128Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004129TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004130 // FIXME: Do we want the type as written?
4131 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 {
4134 // FIXME: Source location isn't quite accurate.
4135 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4136 T = getDerived().TransformType(E->getType());
4137 if (T.isNull())
4138 return SemaRef.ExprError();
4139 }
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregora16548e2009-08-11 05:31:07 +00004141 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4142 if (SubExpr.isInvalid())
4143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregora16548e2009-08-11 05:31:07 +00004145 if (!getDerived().AlwaysRebuild() &&
4146 T == E->getType() &&
4147 SubExpr.get() == E->getSubExpr())
4148 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4151 T, E->getRParenLoc());
4152}
4153
4154template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004155Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004156TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004157 bool ArgumentChanged = false;
4158 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4159 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4160 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4161 if (Init.isInvalid())
4162 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4165 Inits.push_back(Init.takeAs<Expr>());
4166 }
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4169 move_arg(Inits),
4170 E->getRParenLoc());
4171}
Mike Stump11289f42009-09-09 15:08:12 +00004172
Douglas Gregora16548e2009-08-11 05:31:07 +00004173/// \brief Transform an address-of-label expression.
4174///
4175/// By default, the transformation of an address-of-label expression always
4176/// rebuilds the expression, so that the label identifier can be resolved to
4177/// the corresponding label statement by semantic analysis.
4178template<typename Derived>
4179Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004180TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4182 E->getLabel());
4183}
Mike Stump11289f42009-09-09 15:08:12 +00004184
4185template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004187TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004188 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4190 if (SubStmt.isInvalid())
4191 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004192
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 if (!getDerived().AlwaysRebuild() &&
4194 SubStmt.get() == E->getSubStmt())
4195 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004196
4197 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 move(SubStmt),
4199 E->getRParenLoc());
4200}
Mike Stump11289f42009-09-09 15:08:12 +00004201
Douglas Gregora16548e2009-08-11 05:31:07 +00004202template<typename Derived>
4203Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004204TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 QualType T1, T2;
4206 {
4207 // FIXME: Source location isn't quite accurate.
4208 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004209
Douglas Gregora16548e2009-08-11 05:31:07 +00004210 T1 = getDerived().TransformType(E->getArgType1());
4211 if (T1.isNull())
4212 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregora16548e2009-08-11 05:31:07 +00004214 T2 = getDerived().TransformType(E->getArgType2());
4215 if (T2.isNull())
4216 return SemaRef.ExprError();
4217 }
4218
4219 if (!getDerived().AlwaysRebuild() &&
4220 T1 == E->getArgType1() &&
4221 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004222 return SemaRef.Owned(E->Retain());
4223
Douglas Gregora16548e2009-08-11 05:31:07 +00004224 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4225 T1, T2, E->getRParenLoc());
4226}
Mike Stump11289f42009-09-09 15:08:12 +00004227
Douglas Gregora16548e2009-08-11 05:31:07 +00004228template<typename Derived>
4229Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004230TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004231 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4232 if (Cond.isInvalid())
4233 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004234
Douglas Gregora16548e2009-08-11 05:31:07 +00004235 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4236 if (LHS.isInvalid())
4237 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004238
Douglas Gregora16548e2009-08-11 05:31:07 +00004239 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4240 if (RHS.isInvalid())
4241 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004242
Douglas Gregora16548e2009-08-11 05:31:07 +00004243 if (!getDerived().AlwaysRebuild() &&
4244 Cond.get() == E->getCond() &&
4245 LHS.get() == E->getLHS() &&
4246 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004247 return SemaRef.Owned(E->Retain());
4248
Douglas Gregora16548e2009-08-11 05:31:07 +00004249 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4250 move(Cond), move(LHS), move(RHS),
4251 E->getRParenLoc());
4252}
Mike Stump11289f42009-09-09 15:08:12 +00004253
Douglas Gregora16548e2009-08-11 05:31:07 +00004254template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004255Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004256TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004257 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004258}
4259
4260template<typename Derived>
4261Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004262TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004263 switch (E->getOperator()) {
4264 case OO_New:
4265 case OO_Delete:
4266 case OO_Array_New:
4267 case OO_Array_Delete:
4268 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4269 return SemaRef.ExprError();
4270
4271 case OO_Call: {
4272 // This is a call to an object's operator().
4273 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4274
4275 // Transform the object itself.
4276 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4277 if (Object.isInvalid())
4278 return SemaRef.ExprError();
4279
4280 // FIXME: Poor location information
4281 SourceLocation FakeLParenLoc
4282 = SemaRef.PP.getLocForEndOfToken(
4283 static_cast<Expr *>(Object.get())->getLocEnd());
4284
4285 // Transform the call arguments.
4286 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4287 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4288 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004289 if (getDerived().DropCallArgument(E->getArg(I)))
4290 break;
4291
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004292 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4293 if (Arg.isInvalid())
4294 return SemaRef.ExprError();
4295
4296 // FIXME: Poor source location information.
4297 SourceLocation FakeCommaLoc
4298 = SemaRef.PP.getLocForEndOfToken(
4299 static_cast<Expr *>(Arg.get())->getLocEnd());
4300 FakeCommaLocs.push_back(FakeCommaLoc);
4301 Args.push_back(Arg.release());
4302 }
4303
4304 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4305 move_arg(Args),
4306 FakeCommaLocs.data(),
4307 E->getLocEnd());
4308 }
4309
4310#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4311 case OO_##Name:
4312#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4313#include "clang/Basic/OperatorKinds.def"
4314 case OO_Subscript:
4315 // Handled below.
4316 break;
4317
4318 case OO_Conditional:
4319 llvm_unreachable("conditional operator is not actually overloadable");
4320 return SemaRef.ExprError();
4321
4322 case OO_None:
4323 case NUM_OVERLOADED_OPERATORS:
4324 llvm_unreachable("not an overloaded operator?");
4325 return SemaRef.ExprError();
4326 }
4327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4329 if (Callee.isInvalid())
4330 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004331
John McCall47f29ea2009-12-08 09:21:05 +00004332 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 if (First.isInvalid())
4334 return SemaRef.ExprError();
4335
4336 OwningExprResult Second(SemaRef);
4337 if (E->getNumArgs() == 2) {
4338 Second = getDerived().TransformExpr(E->getArg(1));
4339 if (Second.isInvalid())
4340 return SemaRef.ExprError();
4341 }
Mike Stump11289f42009-09-09 15:08:12 +00004342
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 if (!getDerived().AlwaysRebuild() &&
4344 Callee.get() == E->getCallee() &&
4345 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004346 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4347 return SemaRef.Owned(E->Retain());
4348
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4350 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004351 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004352 move(First),
4353 move(Second));
4354}
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356template<typename Derived>
4357Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004358TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4359 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004360}
Mike Stump11289f42009-09-09 15:08:12 +00004361
Douglas Gregora16548e2009-08-11 05:31:07 +00004362template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004363Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004364TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004365 TypeSourceInfo *OldT;
4366 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 {
4368 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004369 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4371 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004372
John McCall97513962010-01-15 18:39:57 +00004373 OldT = E->getTypeInfoAsWritten();
4374 NewT = getDerived().TransformType(OldT);
4375 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 return SemaRef.ExprError();
4377 }
Mike Stump11289f42009-09-09 15:08:12 +00004378
Douglas Gregor6131b442009-12-12 18:16:41 +00004379 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004380 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (SubExpr.isInvalid())
4382 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004385 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004386 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004387 return SemaRef.Owned(E->Retain());
4388
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004390 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004391 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4392 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4393 SourceLocation FakeRParenLoc
4394 = SemaRef.PP.getLocForEndOfToken(
4395 E->getSubExpr()->getSourceRange().getEnd());
4396 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004397 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004399 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 FakeRAngleLoc,
4401 FakeRAngleLoc,
4402 move(SubExpr),
4403 FakeRParenLoc);
4404}
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406template<typename Derived>
4407Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004408TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4409 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004410}
Mike Stump11289f42009-09-09 15:08:12 +00004411
4412template<typename Derived>
4413Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004414TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4415 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004416}
4417
Douglas Gregora16548e2009-08-11 05:31:07 +00004418template<typename Derived>
4419Sema::OwningExprResult
4420TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004421 CXXReinterpretCastExpr *E) {
4422 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004423}
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425template<typename Derived>
4426Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004427TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4428 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004429}
Mike Stump11289f42009-09-09 15:08:12 +00004430
Douglas Gregora16548e2009-08-11 05:31:07 +00004431template<typename Derived>
4432Sema::OwningExprResult
4433TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004434 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004435 TypeSourceInfo *OldT;
4436 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 {
4438 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004439
John McCall97513962010-01-15 18:39:57 +00004440 OldT = E->getTypeInfoAsWritten();
4441 NewT = getDerived().TransformType(OldT);
4442 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 return SemaRef.ExprError();
4444 }
Mike Stump11289f42009-09-09 15:08:12 +00004445
Douglas Gregor6131b442009-12-12 18:16:41 +00004446 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004447 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (SubExpr.isInvalid())
4449 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004452 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004454 return SemaRef.Owned(E->Retain());
4455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 // FIXME: The end of the type's source range is wrong
4457 return getDerived().RebuildCXXFunctionalCastExpr(
4458 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004459 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 /*FIXME:*/E->getSubExpr()->getLocStart(),
4461 move(SubExpr),
4462 E->getRParenLoc());
4463}
Mike Stump11289f42009-09-09 15:08:12 +00004464
Douglas Gregora16548e2009-08-11 05:31:07 +00004465template<typename Derived>
4466Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004467TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004468 if (E->isTypeOperand()) {
4469 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 QualType T = getDerived().TransformType(E->getTypeOperand());
4472 if (T.isNull())
4473 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 if (!getDerived().AlwaysRebuild() &&
4476 T == E->getTypeOperand())
4477 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4480 /*FIXME:*/E->getLocStart(),
4481 T,
4482 E->getLocEnd());
4483 }
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485 // We don't know whether the expression is potentially evaluated until
4486 // after we perform semantic analysis, so the expression is potentially
4487 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004488 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4492 if (SubExpr.isInvalid())
4493 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 if (!getDerived().AlwaysRebuild() &&
4496 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004497 return SemaRef.Owned(E->Retain());
4498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4500 /*FIXME:*/E->getLocStart(),
4501 move(SubExpr),
4502 E->getLocEnd());
4503}
4504
4505template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004506Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004507TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004508 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511template<typename Derived>
4512Sema::OwningExprResult
4513TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004514 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004515 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004516}
Mike Stump11289f42009-09-09 15:08:12 +00004517
Douglas Gregora16548e2009-08-11 05:31:07 +00004518template<typename Derived>
4519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004520TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004521 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregora16548e2009-08-11 05:31:07 +00004523 QualType T = getDerived().TransformType(E->getType());
4524 if (T.isNull())
4525 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004526
Douglas Gregora16548e2009-08-11 05:31:07 +00004527 if (!getDerived().AlwaysRebuild() &&
4528 T == E->getType())
4529 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004530
Douglas Gregorb15af892010-01-07 23:12:05 +00004531 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004532}
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534template<typename Derived>
4535Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004536TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4538 if (SubExpr.isInvalid())
4539 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 if (!getDerived().AlwaysRebuild() &&
4542 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004543 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004544
4545 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4546}
Mike Stump11289f42009-09-09 15:08:12 +00004547
Douglas Gregora16548e2009-08-11 05:31:07 +00004548template<typename Derived>
4549Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004550TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004551 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004552 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4553 if (!Param)
4554 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004555
Chandler Carruth794da4c2010-02-08 06:42:49 +00004556 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 Param == E->getParam())
4558 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004559
Douglas Gregor033f6752009-12-23 23:03:06 +00004560 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004561}
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregora16548e2009-08-11 05:31:07 +00004563template<typename Derived>
4564Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004565TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4567
4568 QualType T = getDerived().TransformType(E->getType());
4569 if (T.isNull())
4570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 if (!getDerived().AlwaysRebuild() &&
4573 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004574 return SemaRef.Owned(E->Retain());
4575
4576 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004577 /*FIXME:*/E->getTypeBeginLoc(),
4578 T,
4579 E->getRParenLoc());
4580}
Mike Stump11289f42009-09-09 15:08:12 +00004581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582template<typename Derived>
4583Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004584TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 // Transform the type that we're allocating
4586 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4587 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4588 if (AllocType.isNull())
4589 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 // Transform the size of the array we're allocating (if any).
4592 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4593 if (ArraySize.isInvalid())
4594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 // Transform the placement arguments (if any).
4597 bool ArgumentChanged = false;
4598 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4599 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4600 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4601 if (Arg.isInvalid())
4602 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4605 PlacementArgs.push_back(Arg.take());
4606 }
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregorebe10102009-08-20 07:17:43 +00004608 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4610 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4611 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4612 if (Arg.isInvalid())
4613 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4616 ConstructorArgs.push_back(Arg.take());
4617 }
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 if (!getDerived().AlwaysRebuild() &&
4620 AllocType == E->getAllocatedType() &&
4621 ArraySize.get() == E->getArraySize() &&
4622 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004623 return SemaRef.Owned(E->Retain());
4624
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004625 if (!ArraySize.get()) {
4626 // If no array size was specified, but the new expression was
4627 // instantiated with an array type (e.g., "new T" where T is
4628 // instantiated with "int[4]"), extract the outer bound from the
4629 // array type as our array size. We do this with constant and
4630 // dependently-sized array types.
4631 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4632 if (!ArrayT) {
4633 // Do nothing
4634 } else if (const ConstantArrayType *ConsArrayT
4635 = dyn_cast<ConstantArrayType>(ArrayT)) {
4636 ArraySize
4637 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4638 ConsArrayT->getSize(),
4639 SemaRef.Context.getSizeType(),
4640 /*FIXME:*/E->getLocStart()));
4641 AllocType = ConsArrayT->getElementType();
4642 } else if (const DependentSizedArrayType *DepArrayT
4643 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4644 if (DepArrayT->getSizeExpr()) {
4645 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4646 AllocType = DepArrayT->getElementType();
4647 }
4648 }
4649 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4651 E->isGlobalNew(),
4652 /*FIXME:*/E->getLocStart(),
4653 move_arg(PlacementArgs),
4654 /*FIXME:*/E->getLocStart(),
4655 E->isParenTypeId(),
4656 AllocType,
4657 /*FIXME:*/E->getLocStart(),
4658 /*FIXME:*/SourceRange(),
4659 move(ArraySize),
4660 /*FIXME:*/E->getLocStart(),
4661 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004662 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004663}
Mike Stump11289f42009-09-09 15:08:12 +00004664
Douglas Gregora16548e2009-08-11 05:31:07 +00004665template<typename Derived>
4666Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004667TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004668 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4669 if (Operand.isInvalid())
4670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregora16548e2009-08-11 05:31:07 +00004672 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004673 Operand.get() == E->getArgument())
4674 return SemaRef.Owned(E->Retain());
4675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4677 E->isGlobalDelete(),
4678 E->isArrayForm(),
4679 move(Operand));
4680}
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682template<typename Derived>
4683Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004684TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004685 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004686 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4687 if (Base.isInvalid())
4688 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregorad8a3362009-09-04 17:36:40 +00004690 NestedNameSpecifier *Qualifier
4691 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004692 E->getQualifierRange(),
4693 true);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004694 if (E->getQualifier() && !Qualifier)
4695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregorad8a3362009-09-04 17:36:40 +00004697 QualType DestroyedType;
4698 {
4699 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4700 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4701 if (DestroyedType.isNull())
4702 return SemaRef.ExprError();
4703 }
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregorad8a3362009-09-04 17:36:40 +00004705 if (!getDerived().AlwaysRebuild() &&
4706 Base.get() == E->getBase() &&
4707 Qualifier == E->getQualifier() &&
4708 DestroyedType == E->getDestroyedType())
4709 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregorad8a3362009-09-04 17:36:40 +00004711 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4712 E->getOperatorLoc(),
4713 E->isArrow(),
4714 E->getDestroyedTypeLoc(),
4715 DestroyedType,
4716 Qualifier,
4717 E->getQualifierRange());
4718}
Mike Stump11289f42009-09-09 15:08:12 +00004719
Douglas Gregorad8a3362009-09-04 17:36:40 +00004720template<typename Derived>
4721Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004722TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004723 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004724 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4725
4726 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4727 Sema::LookupOrdinaryName);
4728
4729 // Transform all the decls.
4730 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4731 E = Old->decls_end(); I != E; ++I) {
4732 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004733 if (!InstD) {
4734 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4735 // This can happen because of dependent hiding.
4736 if (isa<UsingShadowDecl>(*I))
4737 continue;
4738 else
4739 return SemaRef.ExprError();
4740 }
John McCalle66edc12009-11-24 19:00:30 +00004741
4742 // Expand using declarations.
4743 if (isa<UsingDecl>(InstD)) {
4744 UsingDecl *UD = cast<UsingDecl>(InstD);
4745 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4746 E = UD->shadow_end(); I != E; ++I)
4747 R.addDecl(*I);
4748 continue;
4749 }
4750
4751 R.addDecl(InstD);
4752 }
4753
4754 // Resolve a kind, but don't do any further analysis. If it's
4755 // ambiguous, the callee needs to deal with it.
4756 R.resolveKind();
4757
4758 // Rebuild the nested-name qualifier, if present.
4759 CXXScopeSpec SS;
4760 NestedNameSpecifier *Qualifier = 0;
4761 if (Old->getQualifier()) {
4762 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004763 Old->getQualifierRange(),
4764 false);
John McCalle66edc12009-11-24 19:00:30 +00004765 if (!Qualifier)
4766 return SemaRef.ExprError();
4767
4768 SS.setScopeRep(Qualifier);
4769 SS.setRange(Old->getQualifierRange());
4770 }
4771
4772 // If we have no template arguments, it's a normal declaration name.
4773 if (!Old->hasExplicitTemplateArgs())
4774 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4775
4776 // If we have template arguments, rebuild them, then rebuild the
4777 // templateid expression.
4778 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4779 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4780 TemplateArgumentLoc Loc;
4781 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4782 return SemaRef.ExprError();
4783 TransArgs.addArgument(Loc);
4784 }
4785
4786 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4787 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004788}
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790template<typename Derived>
4791Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004792TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004793 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 QualType T = getDerived().TransformType(E->getQueriedType());
4796 if (T.isNull())
4797 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 if (!getDerived().AlwaysRebuild() &&
4800 T == E->getQueriedType())
4801 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 // FIXME: Bad location information
4804 SourceLocation FakeLParenLoc
4805 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004806
4807 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004808 E->getLocStart(),
4809 /*FIXME:*/FakeLParenLoc,
4810 T,
4811 E->getLocEnd());
4812}
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814template<typename Derived>
4815Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004816TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004817 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004819 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004820 E->getQualifierRange(),
4821 false);
Douglas Gregora16548e2009-08-11 05:31:07 +00004822 if (!NNS)
4823 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004824
4825 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004826 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4827 if (!Name)
4828 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004829
John McCalle66edc12009-11-24 19:00:30 +00004830 if (!E->hasExplicitTemplateArgs()) {
4831 if (!getDerived().AlwaysRebuild() &&
4832 NNS == E->getQualifier() &&
4833 Name == E->getDeclName())
4834 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004835
John McCalle66edc12009-11-24 19:00:30 +00004836 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4837 E->getQualifierRange(),
4838 Name, E->getLocation(),
4839 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004840 }
John McCall6b51f282009-11-23 01:53:49 +00004841
4842 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004844 TemplateArgumentLoc Loc;
4845 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004846 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004847 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004848 }
4849
John McCalle66edc12009-11-24 19:00:30 +00004850 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4851 E->getQualifierRange(),
4852 Name, E->getLocation(),
4853 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004854}
4855
4856template<typename Derived>
4857Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004858TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004859 // CXXConstructExprs are always implicit, so when we have a
4860 // 1-argument construction we just transform that argument.
4861 if (E->getNumArgs() == 1 ||
4862 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4863 return getDerived().TransformExpr(E->getArg(0));
4864
Douglas Gregora16548e2009-08-11 05:31:07 +00004865 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4866
4867 QualType T = getDerived().TransformType(E->getType());
4868 if (T.isNull())
4869 return SemaRef.ExprError();
4870
4871 CXXConstructorDecl *Constructor
4872 = cast_or_null<CXXConstructorDecl>(
4873 getDerived().TransformDecl(E->getConstructor()));
4874 if (!Constructor)
4875 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregora16548e2009-08-11 05:31:07 +00004877 bool ArgumentChanged = false;
4878 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004879 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004880 ArgEnd = E->arg_end();
4881 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004882 if (getDerived().DropCallArgument(*Arg)) {
4883 ArgumentChanged = true;
4884 break;
4885 }
4886
Douglas Gregora16548e2009-08-11 05:31:07 +00004887 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4888 if (TransArg.isInvalid())
4889 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004890
Douglas Gregora16548e2009-08-11 05:31:07 +00004891 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4892 Args.push_back(TransArg.takeAs<Expr>());
4893 }
4894
4895 if (!getDerived().AlwaysRebuild() &&
4896 T == E->getType() &&
4897 Constructor == E->getConstructor() &&
4898 !ArgumentChanged)
4899 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004900
Douglas Gregordb121ba2009-12-14 16:27:04 +00004901 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4902 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 move_arg(Args));
4904}
Mike Stump11289f42009-09-09 15:08:12 +00004905
Douglas Gregora16548e2009-08-11 05:31:07 +00004906/// \brief Transform a C++ temporary-binding expression.
4907///
Douglas Gregor363b1512009-12-24 18:51:59 +00004908/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4909/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004910template<typename Derived>
4911Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004912TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004913 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004914}
Mike Stump11289f42009-09-09 15:08:12 +00004915
Anders Carlssonba6c4372010-01-29 02:39:32 +00004916/// \brief Transform a C++ reference-binding expression.
4917///
4918/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4919/// transform the subexpression and return that.
4920template<typename Derived>
4921Sema::OwningExprResult
4922TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4923 return getDerived().TransformExpr(E->getSubExpr());
4924}
4925
Mike Stump11289f42009-09-09 15:08:12 +00004926/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004927/// be destroyed after the expression is evaluated.
4928///
Douglas Gregor363b1512009-12-24 18:51:59 +00004929/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4930/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004931template<typename Derived>
4932Sema::OwningExprResult
4933TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00004934 CXXExprWithTemporaries *E) {
4935 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004936}
Mike Stump11289f42009-09-09 15:08:12 +00004937
Douglas Gregora16548e2009-08-11 05:31:07 +00004938template<typename Derived>
4939Sema::OwningExprResult
4940TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004941 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004942 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4943 QualType T = getDerived().TransformType(E->getType());
4944 if (T.isNull())
4945 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregora16548e2009-08-11 05:31:07 +00004947 CXXConstructorDecl *Constructor
4948 = cast_or_null<CXXConstructorDecl>(
4949 getDerived().TransformDecl(E->getConstructor()));
4950 if (!Constructor)
4951 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004952
Douglas Gregora16548e2009-08-11 05:31:07 +00004953 bool ArgumentChanged = false;
4954 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4955 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004956 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004957 ArgEnd = E->arg_end();
4958 Arg != ArgEnd; ++Arg) {
4959 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4960 if (TransArg.isInvalid())
4961 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4964 Args.push_back((Expr *)TransArg.release());
4965 }
Mike Stump11289f42009-09-09 15:08:12 +00004966
Douglas Gregora16548e2009-08-11 05:31:07 +00004967 if (!getDerived().AlwaysRebuild() &&
4968 T == E->getType() &&
4969 Constructor == E->getConstructor() &&
4970 !ArgumentChanged)
4971 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973 // FIXME: Bogus location information
4974 SourceLocation CommaLoc;
4975 if (Args.size() > 1) {
4976 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004977 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004978 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4979 }
4980 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4981 T,
4982 /*FIXME:*/E->getTypeBeginLoc(),
4983 move_arg(Args),
4984 &CommaLoc,
4985 E->getLocEnd());
4986}
Mike Stump11289f42009-09-09 15:08:12 +00004987
Douglas Gregora16548e2009-08-11 05:31:07 +00004988template<typename Derived>
4989Sema::OwningExprResult
4990TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004991 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004992 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4993 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4994 if (T.isNull())
4995 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 bool ArgumentChanged = false;
4998 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4999 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5000 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5001 ArgEnd = E->arg_end();
5002 Arg != ArgEnd; ++Arg) {
5003 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5004 if (TransArg.isInvalid())
5005 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005006
Douglas Gregora16548e2009-08-11 05:31:07 +00005007 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5008 FakeCommaLocs.push_back(
5009 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5010 Args.push_back(TransArg.takeAs<Expr>());
5011 }
Mike Stump11289f42009-09-09 15:08:12 +00005012
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 if (!getDerived().AlwaysRebuild() &&
5014 T == E->getTypeAsWritten() &&
5015 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005016 return SemaRef.Owned(E->Retain());
5017
Douglas Gregora16548e2009-08-11 05:31:07 +00005018 // FIXME: we're faking the locations of the commas
5019 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5020 T,
5021 E->getLParenLoc(),
5022 move_arg(Args),
5023 FakeCommaLocs.data(),
5024 E->getRParenLoc());
5025}
Mike Stump11289f42009-09-09 15:08:12 +00005026
Douglas Gregora16548e2009-08-11 05:31:07 +00005027template<typename Derived>
5028Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005029TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005030 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005032 OwningExprResult Base(SemaRef, (Expr*) 0);
5033 Expr *OldBase;
5034 QualType BaseType;
5035 QualType ObjectType;
5036 if (!E->isImplicitAccess()) {
5037 OldBase = E->getBase();
5038 Base = getDerived().TransformExpr(OldBase);
5039 if (Base.isInvalid())
5040 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005041
John McCall2d74de92009-12-01 22:10:20 +00005042 // Start the member reference and compute the object's type.
5043 Sema::TypeTy *ObjectTy = 0;
5044 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5045 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005046 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00005047 ObjectTy);
5048 if (Base.isInvalid())
5049 return SemaRef.ExprError();
5050
5051 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5052 BaseType = ((Expr*) Base.get())->getType();
5053 } else {
5054 OldBase = 0;
5055 BaseType = getDerived().TransformType(E->getBaseType());
5056 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5057 }
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005059 // Transform the first part of the nested-name-specifier that qualifies
5060 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005061 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005062 = getDerived().TransformFirstQualifierInScope(
5063 E->getFirstQualifierFoundInScope(),
5064 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005065
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005066 NestedNameSpecifier *Qualifier = 0;
5067 if (E->getQualifier()) {
Douglas Gregor90d554e2010-02-21 18:36:56 +00005068 bool MayBePseudoDestructor
5069 = E->getMember().getNameKind() == DeclarationName::CXXDestructorName;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005070 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5071 E->getQualifierRange(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005072 MayBePseudoDestructor,
John McCall2d74de92009-12-01 22:10:20 +00005073 ObjectType,
5074 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005075 if (!Qualifier)
5076 return SemaRef.ExprError();
5077 }
Mike Stump11289f42009-09-09 15:08:12 +00005078
5079 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005080 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005081 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005082 if (!Name)
5083 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005084
John McCall2d74de92009-12-01 22:10:20 +00005085 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005086 // This is a reference to a member without an explicitly-specified
5087 // template argument list. Optimize for this common case.
5088 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005089 Base.get() == OldBase &&
5090 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005091 Qualifier == E->getQualifier() &&
5092 Name == E->getMember() &&
5093 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005094 return SemaRef.Owned(E->Retain());
5095
John McCall8cd78132009-11-19 22:55:06 +00005096 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005097 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005098 E->isArrow(),
5099 E->getOperatorLoc(),
5100 Qualifier,
5101 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005102 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005103 Name,
5104 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005105 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005106 }
5107
John McCall6b51f282009-11-23 01:53:49 +00005108 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005109 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005110 TemplateArgumentLoc Loc;
5111 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005112 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005113 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005114 }
Mike Stump11289f42009-09-09 15:08:12 +00005115
John McCall8cd78132009-11-19 22:55:06 +00005116 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005117 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005118 E->isArrow(),
5119 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005120 Qualifier,
5121 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005122 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005123 Name,
5124 E->getMemberLoc(),
5125 &TransArgs);
5126}
5127
5128template<typename Derived>
5129Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005130TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005131 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005132 OwningExprResult Base(SemaRef, (Expr*) 0);
5133 QualType BaseType;
5134 if (!Old->isImplicitAccess()) {
5135 Base = getDerived().TransformExpr(Old->getBase());
5136 if (Base.isInvalid())
5137 return SemaRef.ExprError();
5138 BaseType = ((Expr*) Base.get())->getType();
5139 } else {
5140 BaseType = getDerived().TransformType(Old->getBaseType());
5141 }
John McCall10eae182009-11-30 22:42:35 +00005142
5143 NestedNameSpecifier *Qualifier = 0;
5144 if (Old->getQualifier()) {
5145 Qualifier
5146 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005147 Old->getQualifierRange(),
5148 false);
John McCall10eae182009-11-30 22:42:35 +00005149 if (Qualifier == 0)
5150 return SemaRef.ExprError();
5151 }
5152
5153 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5154 Sema::LookupOrdinaryName);
5155
5156 // Transform all the decls.
5157 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5158 E = Old->decls_end(); I != E; ++I) {
5159 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005160 if (!InstD) {
5161 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5162 // This can happen because of dependent hiding.
5163 if (isa<UsingShadowDecl>(*I))
5164 continue;
5165 else
5166 return SemaRef.ExprError();
5167 }
John McCall10eae182009-11-30 22:42:35 +00005168
5169 // Expand using declarations.
5170 if (isa<UsingDecl>(InstD)) {
5171 UsingDecl *UD = cast<UsingDecl>(InstD);
5172 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5173 E = UD->shadow_end(); I != E; ++I)
5174 R.addDecl(*I);
5175 continue;
5176 }
5177
5178 R.addDecl(InstD);
5179 }
5180
5181 R.resolveKind();
5182
5183 TemplateArgumentListInfo TransArgs;
5184 if (Old->hasExplicitTemplateArgs()) {
5185 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5186 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5187 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5188 TemplateArgumentLoc Loc;
5189 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5190 Loc))
5191 return SemaRef.ExprError();
5192 TransArgs.addArgument(Loc);
5193 }
5194 }
John McCall38836f02010-01-15 08:34:02 +00005195
5196 // FIXME: to do this check properly, we will need to preserve the
5197 // first-qualifier-in-scope here, just in case we had a dependent
5198 // base (and therefore couldn't do the check) and a
5199 // nested-name-qualifier (and therefore could do the lookup).
5200 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005201
5202 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005203 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005204 Old->getOperatorLoc(),
5205 Old->isArrow(),
5206 Qualifier,
5207 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005208 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005209 R,
5210 (Old->hasExplicitTemplateArgs()
5211 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005212}
5213
5214template<typename Derived>
5215Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005216TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005217 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005218}
5219
Mike Stump11289f42009-09-09 15:08:12 +00005220template<typename Derived>
5221Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005222TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005223 // FIXME: poor source location
5224 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5225 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5226 if (EncodedType.isNull())
5227 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005228
Douglas Gregora16548e2009-08-11 05:31:07 +00005229 if (!getDerived().AlwaysRebuild() &&
5230 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005231 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005232
5233 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5234 EncodedType,
5235 E->getRParenLoc());
5236}
Mike Stump11289f42009-09-09 15:08:12 +00005237
Douglas Gregora16548e2009-08-11 05:31:07 +00005238template<typename Derived>
5239Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005240TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005241 // FIXME: Implement this!
5242 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005243 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005244}
5245
Mike Stump11289f42009-09-09 15:08:12 +00005246template<typename Derived>
5247Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005248TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005249 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005250}
5251
Mike Stump11289f42009-09-09 15:08:12 +00005252template<typename Derived>
5253Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005254TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005255 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 = cast_or_null<ObjCProtocolDecl>(
5257 getDerived().TransformDecl(E->getProtocol()));
5258 if (!Protocol)
5259 return SemaRef.ExprError();
5260
5261 if (!getDerived().AlwaysRebuild() &&
5262 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005263 return SemaRef.Owned(E->Retain());
5264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 return getDerived().RebuildObjCProtocolExpr(Protocol,
5266 E->getAtLoc(),
5267 /*FIXME:*/E->getAtLoc(),
5268 /*FIXME:*/E->getAtLoc(),
5269 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005270
Douglas Gregora16548e2009-08-11 05:31:07 +00005271}
5272
Mike Stump11289f42009-09-09 15:08:12 +00005273template<typename Derived>
5274Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005275TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 // FIXME: Implement this!
5277 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005278 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005279}
5280
Mike Stump11289f42009-09-09 15:08:12 +00005281template<typename Derived>
5282Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005283TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005284 // FIXME: Implement this!
5285 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005286 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005287}
5288
Mike Stump11289f42009-09-09 15:08:12 +00005289template<typename Derived>
5290Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005291TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005292 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 // FIXME: Implement this!
5294 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005295 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005296}
5297
Mike Stump11289f42009-09-09 15:08:12 +00005298template<typename Derived>
5299Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005300TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005301 // FIXME: Implement this!
5302 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005303 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005304}
5305
Mike Stump11289f42009-09-09 15:08:12 +00005306template<typename Derived>
5307Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005308TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005309 // FIXME: Implement this!
5310 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005311 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005312}
5313
Mike Stump11289f42009-09-09 15:08:12 +00005314template<typename Derived>
5315Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005316TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005317 bool ArgumentChanged = false;
5318 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5319 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5320 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5321 if (SubExpr.isInvalid())
5322 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregora16548e2009-08-11 05:31:07 +00005324 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5325 SubExprs.push_back(SubExpr.takeAs<Expr>());
5326 }
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregora16548e2009-08-11 05:31:07 +00005328 if (!getDerived().AlwaysRebuild() &&
5329 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005330 return SemaRef.Owned(E->Retain());
5331
Douglas Gregora16548e2009-08-11 05:31:07 +00005332 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5333 move_arg(SubExprs),
5334 E->getRParenLoc());
5335}
5336
Mike Stump11289f42009-09-09 15:08:12 +00005337template<typename Derived>
5338Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005339TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005340 // FIXME: Implement this!
5341 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005342 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005343}
5344
Mike Stump11289f42009-09-09 15:08:12 +00005345template<typename Derived>
5346Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005347TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 // FIXME: Implement this!
5349 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005350 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005351}
Mike Stump11289f42009-09-09 15:08:12 +00005352
Douglas Gregora16548e2009-08-11 05:31:07 +00005353//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005354// Type reconstruction
5355//===----------------------------------------------------------------------===//
5356
Mike Stump11289f42009-09-09 15:08:12 +00005357template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005358QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5359 SourceLocation Star) {
5360 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005361 getDerived().getBaseEntity());
5362}
5363
Mike Stump11289f42009-09-09 15:08:12 +00005364template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005365QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5366 SourceLocation Star) {
5367 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005368 getDerived().getBaseEntity());
5369}
5370
Mike Stump11289f42009-09-09 15:08:12 +00005371template<typename Derived>
5372QualType
John McCall70dd5f62009-10-30 00:06:24 +00005373TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5374 bool WrittenAsLValue,
5375 SourceLocation Sigil) {
5376 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5377 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005378}
5379
5380template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005381QualType
John McCall70dd5f62009-10-30 00:06:24 +00005382TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5383 QualType ClassType,
5384 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005385 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005386 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005387}
5388
5389template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005390QualType
John McCall70dd5f62009-10-30 00:06:24 +00005391TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5392 SourceLocation Sigil) {
5393 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005394 getDerived().getBaseEntity());
5395}
5396
5397template<typename Derived>
5398QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005399TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5400 ArrayType::ArraySizeModifier SizeMod,
5401 const llvm::APInt *Size,
5402 Expr *SizeExpr,
5403 unsigned IndexTypeQuals,
5404 SourceRange BracketsRange) {
5405 if (SizeExpr || !Size)
5406 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5407 IndexTypeQuals, BracketsRange,
5408 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005409
5410 QualType Types[] = {
5411 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5412 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5413 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005414 };
5415 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5416 QualType SizeType;
5417 for (unsigned I = 0; I != NumTypes; ++I)
5418 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5419 SizeType = Types[I];
5420 break;
5421 }
Mike Stump11289f42009-09-09 15:08:12 +00005422
Douglas Gregord6ff3322009-08-04 16:50:30 +00005423 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005424 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005425 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005426 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005427}
Mike Stump11289f42009-09-09 15:08:12 +00005428
Douglas Gregord6ff3322009-08-04 16:50:30 +00005429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005430QualType
5431TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005432 ArrayType::ArraySizeModifier SizeMod,
5433 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005434 unsigned IndexTypeQuals,
5435 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005436 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005437 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005438}
5439
5440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005441QualType
Mike Stump11289f42009-09-09 15:08:12 +00005442TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005444 unsigned IndexTypeQuals,
5445 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005446 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005447 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005448}
Mike Stump11289f42009-09-09 15:08:12 +00005449
Douglas Gregord6ff3322009-08-04 16:50:30 +00005450template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005451QualType
5452TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005453 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005455 unsigned IndexTypeQuals,
5456 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005457 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005458 SizeExpr.takeAs<Expr>(),
5459 IndexTypeQuals, BracketsRange);
5460}
5461
5462template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005463QualType
5464TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005465 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005466 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005467 unsigned IndexTypeQuals,
5468 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005469 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005470 SizeExpr.takeAs<Expr>(),
5471 IndexTypeQuals, BracketsRange);
5472}
5473
5474template<typename Derived>
5475QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005476 unsigned NumElements,
5477 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005478 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005479 return SemaRef.Context.getVectorType(ElementType, NumElements,
5480 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005481}
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregord6ff3322009-08-04 16:50:30 +00005483template<typename Derived>
5484QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5485 unsigned NumElements,
5486 SourceLocation AttributeLoc) {
5487 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5488 NumElements, true);
5489 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005490 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005491 AttributeLoc);
5492 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5493 AttributeLoc);
5494}
Mike Stump11289f42009-09-09 15:08:12 +00005495
Douglas Gregord6ff3322009-08-04 16:50:30 +00005496template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005497QualType
5498TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005500 SourceLocation AttributeLoc) {
5501 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5502}
Mike Stump11289f42009-09-09 15:08:12 +00005503
Douglas Gregord6ff3322009-08-04 16:50:30 +00005504template<typename Derived>
5505QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005506 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005507 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005508 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005509 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005510 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005511 Quals,
5512 getDerived().getBaseLocation(),
5513 getDerived().getBaseEntity());
5514}
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregord6ff3322009-08-04 16:50:30 +00005516template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005517QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5518 return SemaRef.Context.getFunctionNoProtoType(T);
5519}
5520
5521template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005522QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5523 assert(D && "no decl found");
5524 if (D->isInvalidDecl()) return QualType();
5525
5526 TypeDecl *Ty;
5527 if (isa<UsingDecl>(D)) {
5528 UsingDecl *Using = cast<UsingDecl>(D);
5529 assert(Using->isTypeName() &&
5530 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5531
5532 // A valid resolved using typename decl points to exactly one type decl.
5533 assert(++Using->shadow_begin() == Using->shadow_end());
5534 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5535
5536 } else {
5537 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5538 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5539 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5540 }
5541
5542 return SemaRef.Context.getTypeDeclType(Ty);
5543}
5544
5545template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005546QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005547 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5548}
5549
5550template<typename Derived>
5551QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5552 return SemaRef.Context.getTypeOfType(Underlying);
5553}
5554
5555template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005556QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005557 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5558}
5559
5560template<typename Derived>
5561QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005562 TemplateName Template,
5563 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005564 const TemplateArgumentListInfo &TemplateArgs) {
5565 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005566}
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregor1135c352009-08-06 05:28:30 +00005568template<typename Derived>
5569NestedNameSpecifier *
5570TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5571 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005572 IdentifierInfo &II,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005573 bool MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005574 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005575 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005576 CXXScopeSpec SS;
5577 // FIXME: The source location information is all wrong.
5578 SS.setRange(Range);
5579 SS.setScopeRep(Prefix);
5580 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005581 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005582 Range.getEnd(), II,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005583 MayBePseudoDestructor,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005584 ObjectType,
5585 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005586 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005587}
5588
5589template<typename Derived>
5590NestedNameSpecifier *
5591TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5592 SourceRange Range,
5593 NamespaceDecl *NS) {
5594 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5595}
5596
5597template<typename Derived>
5598NestedNameSpecifier *
5599TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5600 SourceRange Range,
5601 bool TemplateKW,
Douglas Gregor90d554e2010-02-21 18:36:56 +00005602 QualType T,
5603 bool MayBePseudoDestructor) {
5604 if (MayBePseudoDestructor || T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005605 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005606 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005607 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5608 T.getTypePtr());
5609 }
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregor1135c352009-08-06 05:28:30 +00005611 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5612 return 0;
5613}
Mike Stump11289f42009-09-09 15:08:12 +00005614
Douglas Gregor71dc5092009-08-06 06:41:21 +00005615template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005616TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005617TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5618 bool TemplateKW,
5619 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005620 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005621 Template);
5622}
5623
5624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005625TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005626TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005627 const IdentifierInfo &II,
5628 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005629 CXXScopeSpec SS;
5630 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005631 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005632 UnqualifiedId Name;
5633 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005634 return getSema().ActOnDependentTemplateName(
5635 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005636 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005637 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005638 ObjectType.getAsOpaquePtr(),
5639 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005640 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005641}
Mike Stump11289f42009-09-09 15:08:12 +00005642
Douglas Gregora16548e2009-08-11 05:31:07 +00005643template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005644TemplateName
5645TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5646 OverloadedOperatorKind Operator,
5647 QualType ObjectType) {
5648 CXXScopeSpec SS;
5649 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5650 SS.setScopeRep(Qualifier);
5651 UnqualifiedId Name;
5652 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5653 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5654 Operator, SymbolLocations);
5655 return getSema().ActOnDependentTemplateName(
5656 /*FIXME:*/getDerived().getBaseLocation(),
5657 SS,
5658 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005659 ObjectType.getAsOpaquePtr(),
5660 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005661 .template getAsVal<TemplateName>();
5662}
5663
5664template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005665Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005666TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5667 SourceLocation OpLoc,
5668 ExprArg Callee,
5669 ExprArg First,
5670 ExprArg Second) {
5671 Expr *FirstExpr = (Expr *)First.get();
5672 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005673 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005675
Douglas Gregora16548e2009-08-11 05:31:07 +00005676 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005677 if (Op == OO_Subscript) {
5678 if (!FirstExpr->getType()->isOverloadableType() &&
5679 !SecondExpr->getType()->isOverloadableType())
5680 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005681 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005682 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005683 } else if (Op == OO_Arrow) {
5684 // -> is never a builtin operation.
5685 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005686 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 if (!FirstExpr->getType()->isOverloadableType()) {
5688 // The argument is not of overloadable type, so try to create a
5689 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005690 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005692
Douglas Gregora16548e2009-08-11 05:31:07 +00005693 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5694 }
5695 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005696 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 !SecondExpr->getType()->isOverloadableType()) {
5698 // Neither of the arguments is an overloadable type, so try to
5699 // create a built-in binary operation.
5700 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005701 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005702 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5703 if (Result.isInvalid())
5704 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 First.release();
5707 Second.release();
5708 return move(Result);
5709 }
5710 }
Mike Stump11289f42009-09-09 15:08:12 +00005711
5712 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005713 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005714 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005715
John McCalld14a8642009-11-21 08:51:07 +00005716 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5717 assert(ULE->requiresADL());
5718
5719 // FIXME: Do we have to check
5720 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005721 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005722 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005723 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005724 }
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 // Add any functions found via argument-dependent lookup.
5727 Expr *Args[2] = { FirstExpr, SecondExpr };
5728 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 // Create the overloaded operator invocation for unary operators.
5731 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005732 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005733 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5734 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5735 }
Mike Stump11289f42009-09-09 15:08:12 +00005736
Sebastian Redladba46e2009-10-29 20:17:01 +00005737 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005738 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5739 OpLoc,
5740 move(First),
5741 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005742
Douglas Gregora16548e2009-08-11 05:31:07 +00005743 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005744 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005745 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005746 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005747 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5748 if (Result.isInvalid())
5749 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005750
Douglas Gregora16548e2009-08-11 05:31:07 +00005751 First.release();
5752 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005753 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005754}
Mike Stump11289f42009-09-09 15:08:12 +00005755
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756} // end namespace clang
5757
5758#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H