blob: 95ec5a431363c8667eb01f02ed89cb5fd776f833 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
240 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
246 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000247
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000248 /// \brief Transform the given declaration, which was the first part of a
249 /// nested-name-specifier in a member access expression.
250 ///
251 /// This specific declaration transformation only applies to the first
252 /// identifier in a nested-name-specifier of a member access expression, e.g.,
253 /// the \c T in \c x->T::member
254 ///
255 /// By default, invokes TransformDecl() to transform the declaration.
256 /// Subclasses may override this function to provide alternate behavior.
257 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
258 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
259 }
260
Douglas Gregord6ff3322009-08-04 16:50:30 +0000261 /// \brief Transform the given nested-name-specifier.
262 ///
Mike Stump11289f42009-09-09 15:08:12 +0000263 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000264 /// nested-name-specifier. Subclasses may override this function to provide
265 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000266 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000267 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000268 QualType ObjectType = QualType(),
269 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000270
Douglas Gregorf816bd72009-09-03 22:13:48 +0000271 /// \brief Transform the given declaration name.
272 ///
273 /// By default, transforms the types of conversion function, constructor,
274 /// and destructor names and then (if needed) rebuilds the declaration name.
275 /// Identifiers and selectors are returned unmodified. Sublcasses may
276 /// override this function to provide alternate behavior.
277 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000278 SourceLocation Loc,
279 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000280
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000282 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000283 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000284 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000286 TemplateName TransformTemplateName(TemplateName Name,
287 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000288
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 /// \brief Transform the given template argument.
290 ///
Mike Stump11289f42009-09-09 15:08:12 +0000291 /// By default, this operation transforms the type, expression, or
292 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000293 /// new template argument from the transformed result. Subclasses may
294 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000295 ///
296 /// Returns true if there was an error.
297 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
298 TemplateArgumentLoc &Output);
299
300 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
301 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
302 TemplateArgumentLoc &ArgLoc);
303
John McCallbcd03502009-12-07 02:54:59 +0000304 /// \brief Fakes up a TypeSourceInfo for a type.
305 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
306 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000307 getDerived().getBaseLocation());
308 }
Mike Stump11289f42009-09-09 15:08:12 +0000309
John McCall550e0c22009-10-21 00:40:46 +0000310#define ABSTRACT_TYPELOC(CLASS, PARENT)
311#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000312 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
313 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000314#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000315
Douglas Gregorfe17d252010-02-16 19:09:40 +0000316 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
317 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000318
Douglas Gregorc59e5612009-10-19 22:04:39 +0000319 QualType
320 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
321 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000322
Douglas Gregorebe10102009-08-20 07:17:43 +0000323 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000324
Douglas Gregorebe10102009-08-20 07:17:43 +0000325#define STMT(Node, Parent) \
326 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000327#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000328 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000329#define ABSTRACT_EXPR(Node, Parent)
330#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000331
Douglas Gregord6ff3322009-08-04 16:50:30 +0000332 /// \brief Build a new pointer type given its pointee type.
333 ///
334 /// By default, performs semantic analysis when building the pointer type.
335 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000336 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000337
338 /// \brief Build a new block pointer type given its pointee type.
339 ///
Mike Stump11289f42009-09-09 15:08:12 +0000340 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000341 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000342 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000343
John McCall70dd5f62009-10-30 00:06:24 +0000344 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000345 ///
John McCall70dd5f62009-10-30 00:06:24 +0000346 /// By default, performs semantic analysis when building the
347 /// reference type. Subclasses may override this routine to provide
348 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000349 ///
John McCall70dd5f62009-10-30 00:06:24 +0000350 /// \param LValue whether the type was written with an lvalue sigil
351 /// or an rvalue sigil.
352 QualType RebuildReferenceType(QualType ReferentType,
353 bool LValue,
354 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000355
Douglas Gregord6ff3322009-08-04 16:50:30 +0000356 /// \brief Build a new member pointer type given the pointee type and the
357 /// class type it refers into.
358 ///
359 /// By default, performs semantic analysis when building the member pointer
360 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000361 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
362 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000363
John McCall550e0c22009-10-21 00:40:46 +0000364 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000365 QualType RebuildObjCObjectPointerType(QualType PointeeType,
366 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000367
Douglas Gregord6ff3322009-08-04 16:50:30 +0000368 /// \brief Build a new array type given the element type, size
369 /// modifier, size of the array (if known), size expression, and index type
370 /// qualifiers.
371 ///
372 /// By default, performs semantic analysis when building the array type.
373 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000374 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000375 QualType RebuildArrayType(QualType ElementType,
376 ArrayType::ArraySizeModifier SizeMod,
377 const llvm::APInt *Size,
378 Expr *SizeExpr,
379 unsigned IndexTypeQuals,
380 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new constant array type given the element type, size
383 /// modifier, (known) size of the array, and index type qualifiers.
384 ///
385 /// By default, performs semantic analysis when building the array type.
386 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000387 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000388 ArrayType::ArraySizeModifier SizeMod,
389 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000390 unsigned IndexTypeQuals,
391 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000392
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393 /// \brief Build a new incomplete array type given the element type, size
394 /// modifier, and index type qualifiers.
395 ///
396 /// By default, performs semantic analysis when building the array type.
397 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000398 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000400 unsigned IndexTypeQuals,
401 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402
Mike Stump11289f42009-09-09 15:08:12 +0000403 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404 /// size modifier, size expression, and index type qualifiers.
405 ///
406 /// By default, performs semantic analysis when building the array type.
407 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000408 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000409 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000410 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 unsigned IndexTypeQuals,
412 SourceRange BracketsRange);
413
Mike Stump11289f42009-09-09 15:08:12 +0000414 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000415 /// size modifier, size expression, and index type qualifiers.
416 ///
417 /// By default, performs semantic analysis when building the array type.
418 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000419 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000420 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000421 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 unsigned IndexTypeQuals,
423 SourceRange BracketsRange);
424
425 /// \brief Build a new vector type given the element type and
426 /// number of elements.
427 ///
428 /// By default, performs semantic analysis when building the vector type.
429 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000430 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
431 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000432
Douglas Gregord6ff3322009-08-04 16:50:30 +0000433 /// \brief Build a new extended vector type given the element type and
434 /// number of elements.
435 ///
436 /// By default, performs semantic analysis when building the vector type.
437 /// Subclasses may override this routine to provide different behavior.
438 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
439 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000440
441 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000442 /// given the element type and number of elements.
443 ///
444 /// By default, performs semantic analysis when building the vector type.
445 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000446 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000447 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000448 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000449
Douglas Gregord6ff3322009-08-04 16:50:30 +0000450 /// \brief Build a new function type.
451 ///
452 /// By default, performs semantic analysis when building the function type.
453 /// Subclasses may override this routine to provide different behavior.
454 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000455 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 unsigned NumParamTypes,
457 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000458
John McCall550e0c22009-10-21 00:40:46 +0000459 /// \brief Build a new unprototyped function type.
460 QualType RebuildFunctionNoProtoType(QualType ResultType);
461
John McCallb96ec562009-12-04 22:46:56 +0000462 /// \brief Rebuild an unresolved typename type, given the decl that
463 /// the UnresolvedUsingTypenameDecl was transformed to.
464 QualType RebuildUnresolvedUsingType(Decl *D);
465
Douglas Gregord6ff3322009-08-04 16:50:30 +0000466 /// \brief Build a new typedef type.
467 QualType RebuildTypedefType(TypedefDecl *Typedef) {
468 return SemaRef.Context.getTypeDeclType(Typedef);
469 }
470
471 /// \brief Build a new class/struct/union type.
472 QualType RebuildRecordType(RecordDecl *Record) {
473 return SemaRef.Context.getTypeDeclType(Record);
474 }
475
476 /// \brief Build a new Enum type.
477 QualType RebuildEnumType(EnumDecl *Enum) {
478 return SemaRef.Context.getTypeDeclType(Enum);
479 }
John McCallfcc33b02009-09-05 00:15:47 +0000480
481 /// \brief Build a new elaborated type.
482 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
483 return SemaRef.Context.getElaboratedType(T, Tag);
484 }
Mike Stump11289f42009-09-09 15:08:12 +0000485
486 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000487 ///
488 /// By default, performs semantic analysis when building the typeof type.
489 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000490 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000491
Mike Stump11289f42009-09-09 15:08:12 +0000492 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 ///
494 /// By default, builds a new TypeOfType with the given underlying type.
495 QualType RebuildTypeOfType(QualType Underlying);
496
Mike Stump11289f42009-09-09 15:08:12 +0000497 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 ///
499 /// By default, performs semantic analysis when building the decltype type.
500 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000501 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregord6ff3322009-08-04 16:50:30 +0000503 /// \brief Build a new template specialization type.
504 ///
505 /// By default, performs semantic analysis when building the template
506 /// specialization type. Subclasses may override this routine to provide
507 /// different behavior.
508 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000509 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000510 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new qualified name type.
513 ///
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// By default, builds a new QualifiedNameType type from the
515 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516 /// this routine to provide different behavior.
517 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
518 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000519 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520
521 /// \brief Build a new typename type that refers to a template-id.
522 ///
523 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000524 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000525 /// different behavior.
526 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000527 if (NNS->isDependent()) {
528 CXXScopeSpec SS;
529 SS.setScopeRep(NNS);
530 if (!SemaRef.computeDeclContext(SS))
531 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000532 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000533 }
Mike Stump11289f42009-09-09 15:08:12 +0000534
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000536 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
538 /// \brief Build a new typename type that refers to an identifier.
539 ///
540 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000541 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000542 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000543 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000544 const IdentifierInfo *Id,
545 SourceRange SR) {
546 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000547 }
Mike Stump11289f42009-09-09 15:08:12 +0000548
Douglas Gregor1135c352009-08-06 05:28:30 +0000549 /// \brief Build a new nested-name-specifier given the prefix and an
550 /// identifier that names the next step in the nested-name-specifier.
551 ///
552 /// By default, performs semantic analysis when building the new
553 /// nested-name-specifier. Subclasses may override this routine to provide
554 /// different behavior.
555 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
556 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000557 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000558 QualType ObjectType,
559 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000560
561 /// \brief Build a new nested-name-specifier given the prefix and the
562 /// namespace named in the next step in the nested-name-specifier.
563 ///
564 /// By default, performs semantic analysis when building the new
565 /// nested-name-specifier. Subclasses may override this routine to provide
566 /// different behavior.
567 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
568 SourceRange Range,
569 NamespaceDecl *NS);
570
571 /// \brief Build a new nested-name-specifier given the prefix and the
572 /// type named in the next step in the nested-name-specifier.
573 ///
574 /// By default, performs semantic analysis when building the new
575 /// nested-name-specifier. Subclasses may override this routine to provide
576 /// different behavior.
577 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
578 SourceRange Range,
579 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000580 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000581
582 /// \brief Build a new template name given a nested name specifier, a flag
583 /// indicating whether the "template" keyword was provided, and the template
584 /// that the template name refers to.
585 ///
586 /// By default, builds the new template name directly. Subclasses may override
587 /// this routine to provide different behavior.
588 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
589 bool TemplateKW,
590 TemplateDecl *Template);
591
Douglas Gregor71dc5092009-08-06 06:41:21 +0000592 /// \brief Build a new template name given a nested name specifier and the
593 /// name that is referred to as a template.
594 ///
595 /// By default, performs semantic analysis to determine whether the name can
596 /// be resolved to a specific template, then builds the appropriate kind of
597 /// template name. Subclasses may override this routine to provide different
598 /// behavior.
599 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000600 const IdentifierInfo &II,
601 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000602
Douglas Gregor71395fa2009-11-04 00:56:37 +0000603 /// \brief Build a new template name given a nested name specifier and the
604 /// overloaded operator name that is referred to as a template.
605 ///
606 /// By default, performs semantic analysis to determine whether the name can
607 /// be resolved to a specific template, then builds the appropriate kind of
608 /// template name. Subclasses may override this routine to provide different
609 /// behavior.
610 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
611 OverloadedOperatorKind Operator,
612 QualType ObjectType);
613
Douglas Gregorebe10102009-08-20 07:17:43 +0000614 /// \brief Build a new compound statement.
615 ///
616 /// By default, performs semantic analysis to build the new statement.
617 /// Subclasses may override this routine to provide different behavior.
618 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
619 MultiStmtArg Statements,
620 SourceLocation RBraceLoc,
621 bool IsStmtExpr) {
622 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
623 IsStmtExpr);
624 }
625
626 /// \brief Build a new case statement.
627 ///
628 /// By default, performs semantic analysis to build the new statement.
629 /// Subclasses may override this routine to provide different behavior.
630 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
631 ExprArg LHS,
632 SourceLocation EllipsisLoc,
633 ExprArg RHS,
634 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000635 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000636 ColonLoc);
637 }
Mike Stump11289f42009-09-09 15:08:12 +0000638
Douglas Gregorebe10102009-08-20 07:17:43 +0000639 /// \brief Attach the body to a new case statement.
640 ///
641 /// By default, performs semantic analysis to build the new statement.
642 /// Subclasses may override this routine to provide different behavior.
643 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
644 getSema().ActOnCaseStmtBody(S.get(), move(Body));
645 return move(S);
646 }
Mike Stump11289f42009-09-09 15:08:12 +0000647
Douglas Gregorebe10102009-08-20 07:17:43 +0000648 /// \brief Build a new default statement.
649 ///
650 /// By default, performs semantic analysis to build the new statement.
651 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000652 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000653 SourceLocation ColonLoc,
654 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000655 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /*CurScope=*/0);
657 }
Mike Stump11289f42009-09-09 15:08:12 +0000658
Douglas Gregorebe10102009-08-20 07:17:43 +0000659 /// \brief Build a new label statement.
660 ///
661 /// By default, performs semantic analysis to build the new statement.
662 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000663 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000664 IdentifierInfo *Id,
665 SourceLocation ColonLoc,
666 StmtArg SubStmt) {
667 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
668 }
Mike Stump11289f42009-09-09 15:08:12 +0000669
Douglas Gregorebe10102009-08-20 07:17:43 +0000670 /// \brief Build a new "if" statement.
671 ///
672 /// By default, performs semantic analysis to build the new statement.
673 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000674 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000675 VarDecl *CondVar, StmtArg Then,
676 SourceLocation ElseLoc, StmtArg Else) {
677 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
678 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000679 }
Mike Stump11289f42009-09-09 15:08:12 +0000680
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 /// \brief Start building a new switch statement.
682 ///
683 /// By default, performs semantic analysis to build the new statement.
684 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000685 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
686 VarDecl *CondVar) {
687 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000688 }
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregorebe10102009-08-20 07:17:43 +0000690 /// \brief Attach the body to the switch statement.
691 ///
692 /// By default, performs semantic analysis to build the new statement.
693 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000694 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000695 StmtArg Switch, StmtArg Body) {
696 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
697 move(Body));
698 }
699
700 /// \brief Build a new while statement.
701 ///
702 /// By default, performs semantic analysis to build the new statement.
703 /// Subclasses may override this routine to provide different behavior.
704 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
705 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000706 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000707 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000708 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
709 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000710 }
Mike Stump11289f42009-09-09 15:08:12 +0000711
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 /// \brief Build a new do-while statement.
713 ///
714 /// By default, performs semantic analysis to build the new statement.
715 /// Subclasses may override this routine to provide different behavior.
716 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
717 SourceLocation WhileLoc,
718 SourceLocation LParenLoc,
719 ExprArg Cond,
720 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000721 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000722 move(Cond), RParenLoc);
723 }
724
725 /// \brief Build a new for statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000730 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000731 StmtArg Init, Sema::FullExprArg Cond,
732 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000733 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000734 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
735 DeclPtrTy::make(CondVar),
736 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 }
Mike Stump11289f42009-09-09 15:08:12 +0000738
Douglas Gregorebe10102009-08-20 07:17:43 +0000739 /// \brief Build a new goto statement.
740 ///
741 /// By default, performs semantic analysis to build the new statement.
742 /// Subclasses may override this routine to provide different behavior.
743 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
744 SourceLocation LabelLoc,
745 LabelStmt *Label) {
746 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
747 }
748
749 /// \brief Build a new indirect goto statement.
750 ///
751 /// By default, performs semantic analysis to build the new statement.
752 /// Subclasses may override this routine to provide different behavior.
753 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
754 SourceLocation StarLoc,
755 ExprArg Target) {
756 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
757 }
Mike Stump11289f42009-09-09 15:08:12 +0000758
Douglas Gregorebe10102009-08-20 07:17:43 +0000759 /// \brief Build a new return statement.
760 ///
761 /// By default, performs semantic analysis to build the new statement.
762 /// Subclasses may override this routine to provide different behavior.
763 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
764 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000765
Douglas Gregorebe10102009-08-20 07:17:43 +0000766 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Build a new declaration statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
773 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000774 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 SourceLocation EndLoc) {
776 return getSema().Owned(
777 new (getSema().Context) DeclStmt(
778 DeclGroupRef::Create(getSema().Context,
779 Decls, NumDecls),
780 StartLoc, EndLoc));
781 }
Mike Stump11289f42009-09-09 15:08:12 +0000782
Anders Carlssonaaeef072010-01-24 05:50:09 +0000783 /// \brief Build a new inline asm statement.
784 ///
785 /// By default, performs semantic analysis to build the new statement.
786 /// Subclasses may override this routine to provide different behavior.
787 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
788 bool IsSimple,
789 bool IsVolatile,
790 unsigned NumOutputs,
791 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000792 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000793 MultiExprArg Constraints,
794 MultiExprArg Exprs,
795 ExprArg AsmString,
796 MultiExprArg Clobbers,
797 SourceLocation RParenLoc,
798 bool MSAsm) {
799 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
800 NumInputs, Names, move(Constraints),
801 move(Exprs), move(AsmString), move(Clobbers),
802 RParenLoc, MSAsm);
803 }
804
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 /// \brief Build a new C++ exception declaration.
806 ///
807 /// By default, performs semantic analysis to build the new decaration.
808 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000809 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000810 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000811 IdentifierInfo *Name,
812 SourceLocation Loc,
813 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000814 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 TypeRange);
816 }
817
818 /// \brief Build a new C++ catch statement.
819 ///
820 /// By default, performs semantic analysis to build the new statement.
821 /// Subclasses may override this routine to provide different behavior.
822 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
823 VarDecl *ExceptionDecl,
824 StmtArg Handler) {
825 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000826 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 Handler.takeAs<Stmt>()));
828 }
Mike Stump11289f42009-09-09 15:08:12 +0000829
Douglas Gregorebe10102009-08-20 07:17:43 +0000830 /// \brief Build a new C++ try statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
834 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
835 StmtArg TryBlock,
836 MultiStmtArg Handlers) {
837 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
838 }
Mike Stump11289f42009-09-09 15:08:12 +0000839
Douglas Gregora16548e2009-08-11 05:31:07 +0000840 /// \brief Build a new expression that references a declaration.
841 ///
842 /// By default, performs semantic analysis to build the new expression.
843 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000844 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
845 LookupResult &R,
846 bool RequiresADL) {
847 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
848 }
849
850
851 /// \brief Build a new expression that references a declaration.
852 ///
853 /// By default, performs semantic analysis to build the new expression.
854 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000855 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
856 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000857 ValueDecl *VD, SourceLocation Loc,
858 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000859 CXXScopeSpec SS;
860 SS.setScopeRep(Qualifier);
861 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000862
863 // FIXME: loses template args.
864
865 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000866 }
Mike Stump11289f42009-09-09 15:08:12 +0000867
Douglas Gregora16548e2009-08-11 05:31:07 +0000868 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000869 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000870 /// By default, performs semantic analysis to build the new expression.
871 /// Subclasses may override this routine to provide different behavior.
872 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
873 SourceLocation RParen) {
874 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
875 }
876
Douglas Gregorad8a3362009-09-04 17:36:40 +0000877 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000878 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000879 /// By default, performs semantic analysis to build the new expression.
880 /// Subclasses may override this routine to provide different behavior.
881 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
882 SourceLocation OperatorLoc,
883 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000884 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +0000885 SourceRange QualifierRange,
886 TypeSourceInfo *ScopeType,
887 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +0000888 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +0000889 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +0000890
Douglas Gregora16548e2009-08-11 05:31:07 +0000891 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000892 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// By default, performs semantic analysis to build the new expression.
894 /// Subclasses may override this routine to provide different behavior.
895 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
896 UnaryOperator::Opcode Opc,
897 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000898 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 }
Mike Stump11289f42009-09-09 15:08:12 +0000900
Douglas Gregora16548e2009-08-11 05:31:07 +0000901 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000902 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000903 /// By default, performs semantic analysis to build the new expression.
904 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000905 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000906 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000907 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000908 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 }
910
Mike Stump11289f42009-09-09 15:08:12 +0000911 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000912 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000913 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 /// By default, performs semantic analysis to build the new expression.
915 /// Subclasses may override this routine to provide different behavior.
916 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
917 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000918 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000919 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
920 OpLoc, isSizeOf, R);
921 if (Result.isInvalid())
922 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000923
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 SubExpr.release();
925 return move(Result);
926 }
Mike Stump11289f42009-09-09 15:08:12 +0000927
Douglas Gregora16548e2009-08-11 05:31:07 +0000928 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000929 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000930 /// By default, performs semantic analysis to build the new expression.
931 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000932 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000933 SourceLocation LBracketLoc,
934 ExprArg RHS,
935 SourceLocation RBracketLoc) {
936 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000937 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000938 RBracketLoc);
939 }
940
941 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000942 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000943 /// By default, performs semantic analysis to build the new expression.
944 /// Subclasses may override this routine to provide different behavior.
945 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
946 MultiExprArg Args,
947 SourceLocation *CommaLocs,
948 SourceLocation RParenLoc) {
949 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
950 move(Args), CommaLocs, RParenLoc);
951 }
952
953 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000954 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000955 /// By default, performs semantic analysis to build the new expression.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000958 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000959 NestedNameSpecifier *Qualifier,
960 SourceRange QualifierRange,
961 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000962 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000963 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000964 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000965 if (!Member->getDeclName()) {
966 // We have a reference to an unnamed field.
967 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000968
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000969 Expr *BaseExpr = Base.takeAs<Expr>();
970 if (getSema().PerformObjectMemberConversion(BaseExpr, Member))
971 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +0000972
Mike Stump11289f42009-09-09 15:08:12 +0000973 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +0000974 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +0000975 Member, MemberLoc,
976 cast<FieldDecl>(Member)->getType());
977 return getSema().Owned(ME);
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000980 CXXScopeSpec SS;
981 if (Qualifier) {
982 SS.setRange(QualifierRange);
983 SS.setScopeRep(Qualifier);
984 }
985
John McCall2d74de92009-12-01 22:10:20 +0000986 QualType BaseType = ((Expr*) Base.get())->getType();
987
John McCall38836f02010-01-15 08:34:02 +0000988 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
989 Sema::LookupMemberName);
990 R.addDecl(Member);
991 R.resolveKind();
992
John McCall2d74de92009-12-01 22:10:20 +0000993 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
994 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000995 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +0000996 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 }
Mike Stump11289f42009-09-09 15:08:12 +0000998
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001000 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001001 /// By default, performs semantic analysis to build the new expression.
1002 /// Subclasses may override this routine to provide different behavior.
1003 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1004 BinaryOperator::Opcode Opc,
1005 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001006 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1007 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001008 }
1009
1010 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
1014 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1015 SourceLocation QuestionLoc,
1016 ExprArg LHS,
1017 SourceLocation ColonLoc,
1018 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001019 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001020 move(LHS), move(RHS));
1021 }
1022
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001024 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// By default, performs semantic analysis to build the new expression.
1026 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001027 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1028 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001029 SourceLocation RParenLoc,
1030 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001031 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1032 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001036 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
1039 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001040 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 SourceLocation RParenLoc,
1042 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001043 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1044 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregora16548e2009-08-11 05:31:07 +00001047 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001048 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 /// By default, performs semantic analysis to build the new expression.
1050 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001051 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001052 SourceLocation OpLoc,
1053 SourceLocation AccessorLoc,
1054 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001055
John McCall10eae182009-11-30 22:42:35 +00001056 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001057 QualType BaseType = ((Expr*) Base.get())->getType();
1058 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001059 OpLoc, /*IsArrow*/ false,
1060 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001061 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001062 AccessorLoc,
1063 /* TemplateArgs */ 0);
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 initializer list 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.
1070 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1071 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001072 SourceLocation RBraceLoc,
1073 QualType ResultTy) {
1074 OwningExprResult Result
1075 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1076 if (Result.isInvalid() || ResultTy->isDependentType())
1077 return move(Result);
1078
1079 // Patch in the result type we were given, which may have been computed
1080 // when the initial InitListExpr was built.
1081 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1082 ILE->setType(ResultTy);
1083 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 }
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
1090 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1091 MultiExprArg ArrayExprs,
1092 SourceLocation EqualOrColonLoc,
1093 bool GNUSyntax,
1094 ExprArg Init) {
1095 OwningExprResult Result
1096 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1097 move(Init));
1098 if (Result.isInvalid())
1099 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001100
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 ArrayExprs.release();
1102 return move(Result);
1103 }
Mike Stump11289f42009-09-09 15:08:12 +00001104
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001106 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001107 /// By default, builds the implicit value initialization without performing
1108 /// any semantic analysis. Subclasses may override this routine to provide
1109 /// different behavior.
1110 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1111 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1112 }
Mike Stump11289f42009-09-09 15:08:12 +00001113
Douglas Gregora16548e2009-08-11 05:31:07 +00001114 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001115 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001116 /// By default, performs semantic analysis to build the new expression.
1117 /// Subclasses may override this routine to provide different behavior.
1118 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1119 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001120 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001121 RParenLoc);
1122 }
1123
1124 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 /// By default, performs semantic analysis to build the new expression.
1127 /// Subclasses may override this routine to provide different behavior.
1128 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1129 MultiExprArg SubExprs,
1130 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001131 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1132 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001133 }
Mike Stump11289f42009-09-09 15:08:12 +00001134
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
1137 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// rather than attempting to map the label statement itself.
1139 /// Subclasses may override this routine to provide different behavior.
1140 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1141 SourceLocation LabelLoc,
1142 LabelStmt *Label) {
1143 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001147 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001148 /// By default, performs semantic analysis to build the new expression.
1149 /// Subclasses may override this routine to provide different behavior.
1150 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1151 StmtArg SubStmt,
1152 SourceLocation RParenLoc) {
1153 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1154 }
Mike Stump11289f42009-09-09 15:08:12 +00001155
Douglas Gregora16548e2009-08-11 05:31:07 +00001156 /// \brief Build a new __builtin_types_compatible_p expression.
1157 ///
1158 /// By default, performs semantic analysis to build the new expression.
1159 /// Subclasses may override this routine to provide different behavior.
1160 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1161 QualType T1, QualType T2,
1162 SourceLocation RParenLoc) {
1163 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1164 T1.getAsOpaquePtr(),
1165 T2.getAsOpaquePtr(),
1166 RParenLoc);
1167 }
Mike Stump11289f42009-09-09 15:08:12 +00001168
Douglas Gregora16548e2009-08-11 05:31:07 +00001169 /// \brief Build a new __builtin_choose_expr expression.
1170 ///
1171 /// By default, performs semantic analysis to build the new expression.
1172 /// Subclasses may override this routine to provide different behavior.
1173 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1174 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1175 SourceLocation RParenLoc) {
1176 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1177 move(Cond), move(LHS), move(RHS),
1178 RParenLoc);
1179 }
Mike Stump11289f42009-09-09 15:08:12 +00001180
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 /// \brief Build a new overloaded operator call expression.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// The semantic analysis provides the behavior of template instantiation,
1185 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001186 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001187 /// argument-dependent lookup, etc. Subclasses may override this routine to
1188 /// provide different behavior.
1189 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1190 SourceLocation OpLoc,
1191 ExprArg Callee,
1192 ExprArg First,
1193 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001194
1195 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// reinterpret_cast.
1197 ///
1198 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001199 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001200 /// Subclasses may override this routine to provide different behavior.
1201 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1202 Stmt::StmtClass Class,
1203 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001204 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001205 SourceLocation RAngleLoc,
1206 SourceLocation LParenLoc,
1207 ExprArg SubExpr,
1208 SourceLocation RParenLoc) {
1209 switch (Class) {
1210 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001211 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001212 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 move(SubExpr), RParenLoc);
1214
1215 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001216 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001217 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001221 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001222 RAngleLoc, LParenLoc,
1223 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001225
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001227 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001228 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001229 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora16548e2009-08-11 05:31:07 +00001231 default:
1232 assert(false && "Invalid C++ named cast");
1233 break;
1234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 return getSema().ExprError();
1237 }
Mike Stump11289f42009-09-09 15:08:12 +00001238
Douglas Gregora16548e2009-08-11 05:31:07 +00001239 /// \brief Build a new C++ static_cast expression.
1240 ///
1241 /// By default, performs semantic analysis to build the new expression.
1242 /// Subclasses may override this routine to provide different behavior.
1243 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1244 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001245 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001246 SourceLocation RAngleLoc,
1247 SourceLocation LParenLoc,
1248 ExprArg SubExpr,
1249 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001250 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1251 TInfo, move(SubExpr),
1252 SourceRange(LAngleLoc, RAngleLoc),
1253 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001254 }
1255
1256 /// \brief Build a new C++ dynamic_cast expression.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
1260 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1261 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001262 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 SourceLocation RAngleLoc,
1264 SourceLocation LParenLoc,
1265 ExprArg SubExpr,
1266 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001267 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1268 TInfo, move(SubExpr),
1269 SourceRange(LAngleLoc, RAngleLoc),
1270 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
1272
1273 /// \brief Build a new C++ reinterpret_cast expression.
1274 ///
1275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
1277 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1278 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001279 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 SourceLocation RAngleLoc,
1281 SourceLocation LParenLoc,
1282 ExprArg SubExpr,
1283 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001284 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1285 TInfo, move(SubExpr),
1286 SourceRange(LAngleLoc, RAngleLoc),
1287 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 }
1289
1290 /// \brief Build a new C++ const_cast expression.
1291 ///
1292 /// By default, performs semantic analysis to build the new expression.
1293 /// Subclasses may override this routine to provide different behavior.
1294 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1295 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001296 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 SourceLocation RAngleLoc,
1298 SourceLocation LParenLoc,
1299 ExprArg SubExpr,
1300 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001301 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1302 TInfo, move(SubExpr),
1303 SourceRange(LAngleLoc, RAngleLoc),
1304 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 }
Mike Stump11289f42009-09-09 15:08:12 +00001306
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 /// \brief Build a new C++ functional-style cast expression.
1308 ///
1309 /// By default, performs semantic analysis to build the new expression.
1310 /// Subclasses may override this routine to provide different behavior.
1311 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001312 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 SourceLocation LParenLoc,
1314 ExprArg SubExpr,
1315 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001316 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001318 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001320 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001321 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 RParenLoc);
1323 }
Mike Stump11289f42009-09-09 15:08:12 +00001324
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// \brief Build a new C++ typeid(type) expression.
1326 ///
1327 /// By default, performs semantic analysis to build the new expression.
1328 /// Subclasses may override this routine to provide different behavior.
1329 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1330 SourceLocation LParenLoc,
1331 QualType T,
1332 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001333 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 T.getAsOpaquePtr(), RParenLoc);
1335 }
Mike Stump11289f42009-09-09 15:08:12 +00001336
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 /// \brief Build a new C++ typeid(expr) expression.
1338 ///
1339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
1341 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1342 SourceLocation LParenLoc,
1343 ExprArg Operand,
1344 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001345 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1347 RParenLoc);
1348 if (Result.isInvalid())
1349 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1352 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001353 }
1354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new C++ "this" expression.
1356 ///
1357 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001358 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001359 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001360 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001361 QualType ThisType,
1362 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001363 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001364 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1365 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 }
1367
1368 /// \brief Build a new C++ throw expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1373 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1374 }
1375
1376 /// \brief Build a new C++ default-argument expression.
1377 ///
1378 /// By default, builds a new default-argument expression, which does not
1379 /// require any semantic analysis. Subclasses may override this routine to
1380 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001381 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1382 ParmVarDecl *Param) {
1383 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1384 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001385 }
1386
1387 /// \brief Build a new C++ zero-initialization expression.
1388 ///
1389 /// By default, performs semantic analysis to build the new expression.
1390 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001391 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation LParenLoc,
1393 QualType T,
1394 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001395 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1396 T.getAsOpaquePtr(), LParenLoc,
1397 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 0, RParenLoc);
1399 }
Mike Stump11289f42009-09-09 15:08:12 +00001400
Douglas Gregora16548e2009-08-11 05:31:07 +00001401 /// \brief Build a new C++ "new" expression.
1402 ///
1403 /// By default, performs semantic analysis to build the new expression.
1404 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001405 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 bool UseGlobal,
1407 SourceLocation PlacementLParen,
1408 MultiExprArg PlacementArgs,
1409 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001410 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001411 QualType AllocType,
1412 SourceLocation TypeLoc,
1413 SourceRange TypeRange,
1414 ExprArg ArraySize,
1415 SourceLocation ConstructorLParen,
1416 MultiExprArg ConstructorArgs,
1417 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001418 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 PlacementLParen,
1420 move(PlacementArgs),
1421 PlacementRParen,
1422 ParenTypeId,
1423 AllocType,
1424 TypeLoc,
1425 TypeRange,
1426 move(ArraySize),
1427 ConstructorLParen,
1428 move(ConstructorArgs),
1429 ConstructorRParen);
1430 }
Mike Stump11289f42009-09-09 15:08:12 +00001431
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// \brief Build a new C++ "delete" expression.
1433 ///
1434 /// By default, performs semantic analysis to build the new expression.
1435 /// Subclasses may override this routine to provide different behavior.
1436 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1437 bool IsGlobalDelete,
1438 bool IsArrayForm,
1439 ExprArg Operand) {
1440 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1441 move(Operand));
1442 }
Mike Stump11289f42009-09-09 15:08:12 +00001443
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// \brief Build a new unary type trait expression.
1445 ///
1446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
1448 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1449 SourceLocation StartLoc,
1450 SourceLocation LParenLoc,
1451 QualType T,
1452 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001453 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 T.getAsOpaquePtr(), RParenLoc);
1455 }
1456
Mike Stump11289f42009-09-09 15:08:12 +00001457 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 /// expression.
1459 ///
1460 /// By default, performs semantic analysis to build the new expression.
1461 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001462 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 SourceRange QualifierRange,
1464 DeclarationName Name,
1465 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001466 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001467 CXXScopeSpec SS;
1468 SS.setRange(QualifierRange);
1469 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001470
1471 if (TemplateArgs)
1472 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1473 *TemplateArgs);
1474
1475 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001476 }
1477
1478 /// \brief Build a new template-id expression.
1479 ///
1480 /// By default, performs semantic analysis to build the new expression.
1481 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001482 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1483 LookupResult &R,
1484 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001485 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001486 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 }
1488
1489 /// \brief Build a new object-construction expression.
1490 ///
1491 /// By default, performs semantic analysis to build the new expression.
1492 /// Subclasses may override this routine to provide different behavior.
1493 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001494 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 CXXConstructorDecl *Constructor,
1496 bool IsElidable,
1497 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001498 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1499 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1500 ConvertedArgs))
1501 return getSema().ExprError();
1502
1503 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1504 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 }
1506
1507 /// \brief Build a new object-construction expression.
1508 ///
1509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
1511 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1512 QualType T,
1513 SourceLocation LParenLoc,
1514 MultiExprArg Args,
1515 SourceLocation *Commas,
1516 SourceLocation RParenLoc) {
1517 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1518 T.getAsOpaquePtr(),
1519 LParenLoc,
1520 move(Args),
1521 Commas,
1522 RParenLoc);
1523 }
1524
1525 /// \brief Build a new object-construction expression.
1526 ///
1527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
1529 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1530 QualType T,
1531 SourceLocation LParenLoc,
1532 MultiExprArg Args,
1533 SourceLocation *Commas,
1534 SourceLocation RParenLoc) {
1535 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1536 /*FIXME*/LParenLoc),
1537 T.getAsOpaquePtr(),
1538 LParenLoc,
1539 move(Args),
1540 Commas,
1541 RParenLoc);
1542 }
Mike Stump11289f42009-09-09 15:08:12 +00001543
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// \brief Build a new member reference expression.
1545 ///
1546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001548 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001549 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001550 bool IsArrow,
1551 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001552 NestedNameSpecifier *Qualifier,
1553 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001554 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001556 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001557 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001558 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001559 SS.setRange(QualifierRange);
1560 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001561
John McCall2d74de92009-12-01 22:10:20 +00001562 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1563 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001564 SS, FirstQualifierInScope,
1565 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 }
1567
John McCall10eae182009-11-30 22:42:35 +00001568 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001572 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001573 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001574 SourceLocation OperatorLoc,
1575 bool IsArrow,
1576 NestedNameSpecifier *Qualifier,
1577 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001578 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001579 LookupResult &R,
1580 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001581 CXXScopeSpec SS;
1582 SS.setRange(QualifierRange);
1583 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001584
John McCall2d74de92009-12-01 22:10:20 +00001585 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1586 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001587 SS, FirstQualifierInScope,
1588 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001589 }
Mike Stump11289f42009-09-09 15:08:12 +00001590
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 /// \brief Build a new Objective-C @encode expression.
1592 ///
1593 /// By default, performs semantic analysis to build the new expression.
1594 /// Subclasses may override this routine to provide different behavior.
1595 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1596 QualType T,
1597 SourceLocation RParenLoc) {
1598 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1599 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001600 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001601
1602 /// \brief Build a new Objective-C protocol expression.
1603 ///
1604 /// By default, performs semantic analysis to build the new expression.
1605 /// Subclasses may override this routine to provide different behavior.
1606 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1607 SourceLocation AtLoc,
1608 SourceLocation ProtoLoc,
1609 SourceLocation LParenLoc,
1610 SourceLocation RParenLoc) {
1611 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1612 Protocol->getIdentifier(),
1613 AtLoc,
1614 ProtoLoc,
1615 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001616 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 }
Mike Stump11289f42009-09-09 15:08:12 +00001618
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 /// \brief Build a new shuffle vector expression.
1620 ///
1621 /// By default, performs semantic analysis to build the new expression.
1622 /// Subclasses may override this routine to provide different behavior.
1623 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1624 MultiExprArg SubExprs,
1625 SourceLocation RParenLoc) {
1626 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001627 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1629 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1630 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1631 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 // Build a reference to the __builtin_shufflevector builtin
1634 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001635 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001636 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001637 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001639
1640 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001641 unsigned NumSubExprs = SubExprs.size();
1642 Expr **Subs = (Expr **)SubExprs.release();
1643 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1644 Subs, NumSubExprs,
1645 Builtin->getResultType(),
1646 RParenLoc);
1647 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001648
Douglas Gregora16548e2009-08-11 05:31:07 +00001649 // Type-check the __builtin_shufflevector expression.
1650 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1651 if (Result.isInvalid())
1652 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001653
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001655 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001657};
Douglas Gregora16548e2009-08-11 05:31:07 +00001658
Douglas Gregorebe10102009-08-20 07:17:43 +00001659template<typename Derived>
1660Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1661 if (!S)
1662 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001663
Douglas Gregorebe10102009-08-20 07:17:43 +00001664 switch (S->getStmtClass()) {
1665 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001666
Douglas Gregorebe10102009-08-20 07:17:43 +00001667 // Transform individual statement nodes
1668#define STMT(Node, Parent) \
1669 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1670#define EXPR(Node, Parent)
1671#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 // Transform expressions by calling TransformExpr.
1674#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001675#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001676#define EXPR(Node, Parent) case Stmt::Node##Class:
1677#include "clang/AST/StmtNodes.def"
1678 {
1679 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1680 if (E.isInvalid())
1681 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001682
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001683 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001684 }
Mike Stump11289f42009-09-09 15:08:12 +00001685 }
1686
Douglas Gregorebe10102009-08-20 07:17:43 +00001687 return SemaRef.Owned(S->Retain());
1688}
Mike Stump11289f42009-09-09 15:08:12 +00001689
1690
Douglas Gregore922c772009-08-04 22:27:00 +00001691template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001692Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 if (!E)
1694 return SemaRef.Owned(E);
1695
1696 switch (E->getStmtClass()) {
1697 case Stmt::NoStmtClass: break;
1698#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001699#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001700#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001701 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001702#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001703 }
1704
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001706}
1707
1708template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001709NestedNameSpecifier *
1710TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001711 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001712 QualType ObjectType,
1713 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001714 if (!NNS)
1715 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001716
Douglas Gregorebe10102009-08-20 07:17:43 +00001717 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001718 NestedNameSpecifier *Prefix = NNS->getPrefix();
1719 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001720 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001721 ObjectType,
1722 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001723 if (!Prefix)
1724 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001725
1726 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001727 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001728 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001729 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 }
Mike Stump11289f42009-09-09 15:08:12 +00001731
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 switch (NNS->getKind()) {
1733 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001734 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001735 "Identifier nested-name-specifier with no prefix or object type");
1736 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1737 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001738 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001739
1740 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001741 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001742 ObjectType,
1743 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001744
Douglas Gregor1135c352009-08-06 05:28:30 +00001745 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001746 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 = cast_or_null<NamespaceDecl>(
1748 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001749 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001750 Prefix == NNS->getPrefix() &&
1751 NS == NNS->getAsNamespace())
1752 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1755 }
Mike Stump11289f42009-09-09 15:08:12 +00001756
Douglas Gregor1135c352009-08-06 05:28:30 +00001757 case NestedNameSpecifier::Global:
1758 // There is no meaningful transformation that one could perform on the
1759 // global scope.
1760 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001761
Douglas Gregor1135c352009-08-06 05:28:30 +00001762 case NestedNameSpecifier::TypeSpecWithTemplate:
1763 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001764 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001765 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1766 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001767 if (T.isNull())
1768 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregor1135c352009-08-06 05:28:30 +00001770 if (!getDerived().AlwaysRebuild() &&
1771 Prefix == NNS->getPrefix() &&
1772 T == QualType(NNS->getAsType(), 0))
1773 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001774
1775 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1776 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001777 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001778 }
1779 }
Mike Stump11289f42009-09-09 15:08:12 +00001780
Douglas Gregor1135c352009-08-06 05:28:30 +00001781 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001782 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001783}
1784
1785template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001786DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001787TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001788 SourceLocation Loc,
1789 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790 if (!Name)
1791 return Name;
1792
1793 switch (Name.getNameKind()) {
1794 case DeclarationName::Identifier:
1795 case DeclarationName::ObjCZeroArgSelector:
1796 case DeclarationName::ObjCOneArgSelector:
1797 case DeclarationName::ObjCMultiArgSelector:
1798 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001799 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001800 case DeclarationName::CXXUsingDirective:
1801 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001802
Douglas Gregorf816bd72009-09-03 22:13:48 +00001803 case DeclarationName::CXXConstructorName:
1804 case DeclarationName::CXXDestructorName:
1805 case DeclarationName::CXXConversionFunctionName: {
1806 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001807 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1808 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001809 if (T.isNull())
1810 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001811
Douglas Gregorf816bd72009-09-03 22:13:48 +00001812 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001813 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001814 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001815 }
Mike Stump11289f42009-09-09 15:08:12 +00001816 }
1817
Douglas Gregorf816bd72009-09-03 22:13:48 +00001818 return DeclarationName();
1819}
1820
1821template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001822TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001823TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1824 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001825 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001826 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001827 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001828 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1829 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001830 if (!NNS)
1831 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001832
Douglas Gregor71dc5092009-08-06 06:41:21 +00001833 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001834 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001835 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1836 if (!TransTemplate)
1837 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001838
Douglas Gregor71dc5092009-08-06 06:41:21 +00001839 if (!getDerived().AlwaysRebuild() &&
1840 NNS == QTN->getQualifier() &&
1841 TransTemplate == Template)
1842 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001843
Douglas Gregor71dc5092009-08-06 06:41:21 +00001844 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1845 TransTemplate);
1846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
John McCalle66edc12009-11-24 19:00:30 +00001848 // These should be getting filtered out before they make it into the AST.
1849 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001850 }
Mike Stump11289f42009-09-09 15:08:12 +00001851
Douglas Gregor71dc5092009-08-06 06:41:21 +00001852 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001853 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001854 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001855 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1856 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00001857 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001858 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001859
Douglas Gregor71dc5092009-08-06 06:41:21 +00001860 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001861 NNS == DTN->getQualifier() &&
1862 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001863 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001864
Douglas Gregor71395fa2009-11-04 00:56:37 +00001865 if (DTN->isIdentifier())
1866 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1867 ObjectType);
1868
1869 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1870 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001871 }
Mike Stump11289f42009-09-09 15:08:12 +00001872
Douglas Gregor71dc5092009-08-06 06:41:21 +00001873 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001874 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001875 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1876 if (!TransTemplate)
1877 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001878
Douglas Gregor71dc5092009-08-06 06:41:21 +00001879 if (!getDerived().AlwaysRebuild() &&
1880 TransTemplate == Template)
1881 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001882
Douglas Gregor71dc5092009-08-06 06:41:21 +00001883 return TemplateName(TransTemplate);
1884 }
Mike Stump11289f42009-09-09 15:08:12 +00001885
John McCalle66edc12009-11-24 19:00:30 +00001886 // These should be getting filtered out before they reach the AST.
1887 assert(false && "overloaded function decl survived to here");
1888 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001889}
1890
1891template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001892void TreeTransform<Derived>::InventTemplateArgumentLoc(
1893 const TemplateArgument &Arg,
1894 TemplateArgumentLoc &Output) {
1895 SourceLocation Loc = getDerived().getBaseLocation();
1896 switch (Arg.getKind()) {
1897 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00001898 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00001899 break;
1900
1901 case TemplateArgument::Type:
1902 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001903 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001904
1905 break;
1906
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001907 case TemplateArgument::Template:
1908 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1909 break;
1910
John McCall0ad16662009-10-29 08:12:44 +00001911 case TemplateArgument::Expression:
1912 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1913 break;
1914
1915 case TemplateArgument::Declaration:
1916 case TemplateArgument::Integral:
1917 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001918 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001919 break;
1920 }
1921}
1922
1923template<typename Derived>
1924bool TreeTransform<Derived>::TransformTemplateArgument(
1925 const TemplateArgumentLoc &Input,
1926 TemplateArgumentLoc &Output) {
1927 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001928 switch (Arg.getKind()) {
1929 case TemplateArgument::Null:
1930 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001931 Output = Input;
1932 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001933
Douglas Gregore922c772009-08-04 22:27:00 +00001934 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001935 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001936 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001937 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001938
1939 DI = getDerived().TransformType(DI);
1940 if (!DI) return true;
1941
1942 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1943 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001944 }
Mike Stump11289f42009-09-09 15:08:12 +00001945
Douglas Gregore922c772009-08-04 22:27:00 +00001946 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001947 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001948 DeclarationName Name;
1949 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1950 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001951 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001952 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001953 if (!D) return true;
1954
John McCall0d07eb32009-10-29 18:45:58 +00001955 Expr *SourceExpr = Input.getSourceDeclExpression();
1956 if (SourceExpr) {
1957 EnterExpressionEvaluationContext Unevaluated(getSema(),
1958 Action::Unevaluated);
1959 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1960 if (E.isInvalid())
1961 SourceExpr = NULL;
1962 else {
1963 SourceExpr = E.takeAs<Expr>();
1964 SourceExpr->Retain();
1965 }
1966 }
1967
1968 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001969 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001972 case TemplateArgument::Template: {
1973 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1974 TemplateName Template
1975 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1976 if (Template.isNull())
1977 return true;
1978
1979 Output = TemplateArgumentLoc(TemplateArgument(Template),
1980 Input.getTemplateQualifierRange(),
1981 Input.getTemplateNameLoc());
1982 return false;
1983 }
1984
Douglas Gregore922c772009-08-04 22:27:00 +00001985 case TemplateArgument::Expression: {
1986 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001987 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001988 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001989
John McCall0ad16662009-10-29 08:12:44 +00001990 Expr *InputExpr = Input.getSourceExpression();
1991 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1992
1993 Sema::OwningExprResult E
1994 = getDerived().TransformExpr(InputExpr);
1995 if (E.isInvalid()) return true;
1996
1997 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001998 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001999 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2000 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002001 }
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregore922c772009-08-04 22:27:00 +00002003 case TemplateArgument::Pack: {
2004 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2005 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002006 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002007 AEnd = Arg.pack_end();
2008 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002009
John McCall0ad16662009-10-29 08:12:44 +00002010 // FIXME: preserve source information here when we start
2011 // caring about parameter packs.
2012
John McCall0d07eb32009-10-29 18:45:58 +00002013 TemplateArgumentLoc InputArg;
2014 TemplateArgumentLoc OutputArg;
2015 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2016 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002017 return true;
2018
John McCall0d07eb32009-10-29 18:45:58 +00002019 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002020 }
2021 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002022 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002023 true);
John McCall0d07eb32009-10-29 18:45:58 +00002024 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002025 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002026 }
2027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Douglas Gregore922c772009-08-04 22:27:00 +00002029 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002030 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002031}
2032
Douglas Gregord6ff3322009-08-04 16:50:30 +00002033//===----------------------------------------------------------------------===//
2034// Type transformation
2035//===----------------------------------------------------------------------===//
2036
2037template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002038QualType TreeTransform<Derived>::TransformType(QualType T,
2039 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002040 if (getDerived().AlreadyTransformed(T))
2041 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002042
John McCall550e0c22009-10-21 00:40:46 +00002043 // Temporary workaround. All of these transformations should
2044 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002045 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002046 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002047
Douglas Gregorfe17d252010-02-16 19:09:40 +00002048 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002049
John McCall550e0c22009-10-21 00:40:46 +00002050 if (!NewDI)
2051 return QualType();
2052
2053 return NewDI->getType();
2054}
2055
2056template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002057TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2058 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002059 if (getDerived().AlreadyTransformed(DI->getType()))
2060 return DI;
2061
2062 TypeLocBuilder TLB;
2063
2064 TypeLoc TL = DI->getTypeLoc();
2065 TLB.reserve(TL.getFullDataSize());
2066
Douglas Gregorfe17d252010-02-16 19:09:40 +00002067 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002068 if (Result.isNull())
2069 return 0;
2070
John McCallbcd03502009-12-07 02:54:59 +00002071 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002072}
2073
2074template<typename Derived>
2075QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002076TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2077 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002078 switch (T.getTypeLocClass()) {
2079#define ABSTRACT_TYPELOC(CLASS, PARENT)
2080#define TYPELOC(CLASS, PARENT) \
2081 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002082 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2083 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002084#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002087 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002088 return QualType();
2089}
2090
2091/// FIXME: By default, this routine adds type qualifiers only to types
2092/// that can have qualifiers, and silently suppresses those qualifiers
2093/// that are not permitted (e.g., qualifiers on reference or function
2094/// types). This is the right thing for template instantiation, but
2095/// probably not for other clients.
2096template<typename Derived>
2097QualType
2098TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002099 QualifiedTypeLoc T,
2100 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002101 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002102
Douglas Gregorfe17d252010-02-16 19:09:40 +00002103 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2104 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002105 if (Result.isNull())
2106 return QualType();
2107
2108 // Silently suppress qualifiers if the result type can't be qualified.
2109 // FIXME: this is the right thing for template instantiation, but
2110 // probably not for other clients.
2111 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002112 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002113
John McCall550e0c22009-10-21 00:40:46 +00002114 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2115
2116 TLB.push<QualifiedTypeLoc>(Result);
2117
2118 // No location information to preserve.
2119
2120 return Result;
2121}
2122
2123template <class TyLoc> static inline
2124QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2125 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2126 NewT.setNameLoc(T.getNameLoc());
2127 return T.getType();
2128}
2129
2130// Ugly metaprogramming macros because I couldn't be bothered to make
2131// the equivalent template version work.
2132#define TransformPointerLikeType(TypeClass) do { \
2133 QualType PointeeType \
2134 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2135 if (PointeeType.isNull()) \
2136 return QualType(); \
2137 \
2138 QualType Result = TL.getType(); \
2139 if (getDerived().AlwaysRebuild() || \
2140 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002141 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2142 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002143 if (Result.isNull()) \
2144 return QualType(); \
2145 } \
2146 \
2147 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2148 NewT.setSigilLoc(TL.getSigilLoc()); \
2149 \
2150 return Result; \
2151} while(0)
2152
John McCall550e0c22009-10-21 00:40:46 +00002153template<typename Derived>
2154QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002155 BuiltinTypeLoc T,
2156 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002157 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2158 NewT.setBuiltinLoc(T.getBuiltinLoc());
2159 if (T.needsExtraLocalData())
2160 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2161 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002162}
Mike Stump11289f42009-09-09 15:08:12 +00002163
Douglas Gregord6ff3322009-08-04 16:50:30 +00002164template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002165QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002166 ComplexTypeLoc T,
2167 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002168 // FIXME: recurse?
2169 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002170}
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregord6ff3322009-08-04 16:50:30 +00002172template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002173QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002174 PointerTypeLoc TL,
2175 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002176 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177}
Mike Stump11289f42009-09-09 15:08:12 +00002178
2179template<typename Derived>
2180QualType
John McCall550e0c22009-10-21 00:40:46 +00002181TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002182 BlockPointerTypeLoc TL,
2183 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002184 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002185}
2186
John McCall70dd5f62009-10-30 00:06:24 +00002187/// Transforms a reference type. Note that somewhat paradoxically we
2188/// don't care whether the type itself is an l-value type or an r-value
2189/// type; we only care if the type was *written* as an l-value type
2190/// or an r-value type.
2191template<typename Derived>
2192QualType
2193TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002194 ReferenceTypeLoc TL,
2195 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002196 const ReferenceType *T = TL.getTypePtr();
2197
2198 // Note that this works with the pointee-as-written.
2199 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2200 if (PointeeType.isNull())
2201 return QualType();
2202
2203 QualType Result = TL.getType();
2204 if (getDerived().AlwaysRebuild() ||
2205 PointeeType != T->getPointeeTypeAsWritten()) {
2206 Result = getDerived().RebuildReferenceType(PointeeType,
2207 T->isSpelledAsLValue(),
2208 TL.getSigilLoc());
2209 if (Result.isNull())
2210 return QualType();
2211 }
2212
2213 // r-value references can be rebuilt as l-value references.
2214 ReferenceTypeLoc NewTL;
2215 if (isa<LValueReferenceType>(Result))
2216 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2217 else
2218 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2219 NewTL.setSigilLoc(TL.getSigilLoc());
2220
2221 return Result;
2222}
2223
Mike Stump11289f42009-09-09 15:08:12 +00002224template<typename Derived>
2225QualType
John McCall550e0c22009-10-21 00:40:46 +00002226TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002227 LValueReferenceTypeLoc TL,
2228 QualType ObjectType) {
2229 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002230}
2231
Mike Stump11289f42009-09-09 15:08:12 +00002232template<typename Derived>
2233QualType
John McCall550e0c22009-10-21 00:40:46 +00002234TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002235 RValueReferenceTypeLoc TL,
2236 QualType ObjectType) {
2237 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002238}
Mike Stump11289f42009-09-09 15:08:12 +00002239
Douglas Gregord6ff3322009-08-04 16:50:30 +00002240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002241QualType
John McCall550e0c22009-10-21 00:40:46 +00002242TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002243 MemberPointerTypeLoc TL,
2244 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002245 MemberPointerType *T = TL.getTypePtr();
2246
2247 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002248 if (PointeeType.isNull())
2249 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002250
John McCall550e0c22009-10-21 00:40:46 +00002251 // TODO: preserve source information for this.
2252 QualType ClassType
2253 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002254 if (ClassType.isNull())
2255 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002256
John McCall550e0c22009-10-21 00:40:46 +00002257 QualType Result = TL.getType();
2258 if (getDerived().AlwaysRebuild() ||
2259 PointeeType != T->getPointeeType() ||
2260 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002261 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2262 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002263 if (Result.isNull())
2264 return QualType();
2265 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002266
John McCall550e0c22009-10-21 00:40:46 +00002267 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2268 NewTL.setSigilLoc(TL.getSigilLoc());
2269
2270 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002271}
2272
Mike Stump11289f42009-09-09 15:08:12 +00002273template<typename Derived>
2274QualType
John McCall550e0c22009-10-21 00:40:46 +00002275TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002276 ConstantArrayTypeLoc TL,
2277 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002278 ConstantArrayType *T = TL.getTypePtr();
2279 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002280 if (ElementType.isNull())
2281 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002282
John McCall550e0c22009-10-21 00:40:46 +00002283 QualType Result = TL.getType();
2284 if (getDerived().AlwaysRebuild() ||
2285 ElementType != T->getElementType()) {
2286 Result = getDerived().RebuildConstantArrayType(ElementType,
2287 T->getSizeModifier(),
2288 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002289 T->getIndexTypeCVRQualifiers(),
2290 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002291 if (Result.isNull())
2292 return QualType();
2293 }
2294
2295 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2296 NewTL.setLBracketLoc(TL.getLBracketLoc());
2297 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCall550e0c22009-10-21 00:40:46 +00002299 Expr *Size = TL.getSizeExpr();
2300 if (Size) {
2301 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2302 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2303 }
2304 NewTL.setSizeExpr(Size);
2305
2306 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002307}
Mike Stump11289f42009-09-09 15:08:12 +00002308
Douglas Gregord6ff3322009-08-04 16:50:30 +00002309template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002310QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002311 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002312 IncompleteArrayTypeLoc TL,
2313 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002314 IncompleteArrayType *T = TL.getTypePtr();
2315 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002316 if (ElementType.isNull())
2317 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002318
John McCall550e0c22009-10-21 00:40:46 +00002319 QualType Result = TL.getType();
2320 if (getDerived().AlwaysRebuild() ||
2321 ElementType != T->getElementType()) {
2322 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002323 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002324 T->getIndexTypeCVRQualifiers(),
2325 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002326 if (Result.isNull())
2327 return QualType();
2328 }
2329
2330 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2331 NewTL.setLBracketLoc(TL.getLBracketLoc());
2332 NewTL.setRBracketLoc(TL.getRBracketLoc());
2333 NewTL.setSizeExpr(0);
2334
2335 return Result;
2336}
2337
2338template<typename Derived>
2339QualType
2340TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002341 VariableArrayTypeLoc TL,
2342 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002343 VariableArrayType *T = TL.getTypePtr();
2344 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2345 if (ElementType.isNull())
2346 return QualType();
2347
2348 // Array bounds are not potentially evaluated contexts
2349 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2350
2351 Sema::OwningExprResult SizeResult
2352 = getDerived().TransformExpr(T->getSizeExpr());
2353 if (SizeResult.isInvalid())
2354 return QualType();
2355
2356 Expr *Size = static_cast<Expr*>(SizeResult.get());
2357
2358 QualType Result = TL.getType();
2359 if (getDerived().AlwaysRebuild() ||
2360 ElementType != T->getElementType() ||
2361 Size != T->getSizeExpr()) {
2362 Result = getDerived().RebuildVariableArrayType(ElementType,
2363 T->getSizeModifier(),
2364 move(SizeResult),
2365 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002366 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002367 if (Result.isNull())
2368 return QualType();
2369 }
2370 else SizeResult.take();
2371
2372 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2373 NewTL.setLBracketLoc(TL.getLBracketLoc());
2374 NewTL.setRBracketLoc(TL.getRBracketLoc());
2375 NewTL.setSizeExpr(Size);
2376
2377 return Result;
2378}
2379
2380template<typename Derived>
2381QualType
2382TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002383 DependentSizedArrayTypeLoc TL,
2384 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002385 DependentSizedArrayType *T = TL.getTypePtr();
2386 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2387 if (ElementType.isNull())
2388 return QualType();
2389
2390 // Array bounds are not potentially evaluated contexts
2391 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2392
2393 Sema::OwningExprResult SizeResult
2394 = getDerived().TransformExpr(T->getSizeExpr());
2395 if (SizeResult.isInvalid())
2396 return QualType();
2397
2398 Expr *Size = static_cast<Expr*>(SizeResult.get());
2399
2400 QualType Result = TL.getType();
2401 if (getDerived().AlwaysRebuild() ||
2402 ElementType != T->getElementType() ||
2403 Size != T->getSizeExpr()) {
2404 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2405 T->getSizeModifier(),
2406 move(SizeResult),
2407 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002408 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002409 if (Result.isNull())
2410 return QualType();
2411 }
2412 else SizeResult.take();
2413
2414 // We might have any sort of array type now, but fortunately they
2415 // all have the same location layout.
2416 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2417 NewTL.setLBracketLoc(TL.getLBracketLoc());
2418 NewTL.setRBracketLoc(TL.getRBracketLoc());
2419 NewTL.setSizeExpr(Size);
2420
2421 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002422}
Mike Stump11289f42009-09-09 15:08:12 +00002423
2424template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002425QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002426 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002427 DependentSizedExtVectorTypeLoc TL,
2428 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002429 DependentSizedExtVectorType *T = TL.getTypePtr();
2430
2431 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002432 QualType ElementType = getDerived().TransformType(T->getElementType());
2433 if (ElementType.isNull())
2434 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002435
Douglas Gregore922c772009-08-04 22:27:00 +00002436 // Vector sizes are not potentially evaluated contexts
2437 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2438
Douglas Gregord6ff3322009-08-04 16:50:30 +00002439 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2440 if (Size.isInvalid())
2441 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002442
John McCall550e0c22009-10-21 00:40:46 +00002443 QualType Result = TL.getType();
2444 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002445 ElementType != T->getElementType() ||
2446 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002447 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002448 move(Size),
2449 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002450 if (Result.isNull())
2451 return QualType();
2452 }
2453 else Size.take();
2454
2455 // Result might be dependent or not.
2456 if (isa<DependentSizedExtVectorType>(Result)) {
2457 DependentSizedExtVectorTypeLoc NewTL
2458 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2459 NewTL.setNameLoc(TL.getNameLoc());
2460 } else {
2461 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2462 NewTL.setNameLoc(TL.getNameLoc());
2463 }
2464
2465 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466}
Mike Stump11289f42009-09-09 15:08:12 +00002467
2468template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002469QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002470 VectorTypeLoc TL,
2471 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002472 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002473 QualType ElementType = getDerived().TransformType(T->getElementType());
2474 if (ElementType.isNull())
2475 return QualType();
2476
John McCall550e0c22009-10-21 00:40:46 +00002477 QualType Result = TL.getType();
2478 if (getDerived().AlwaysRebuild() ||
2479 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002480 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2481 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002482 if (Result.isNull())
2483 return QualType();
2484 }
2485
2486 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2487 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002488
John McCall550e0c22009-10-21 00:40:46 +00002489 return Result;
2490}
2491
2492template<typename Derived>
2493QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002494 ExtVectorTypeLoc TL,
2495 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002496 VectorType *T = TL.getTypePtr();
2497 QualType ElementType = getDerived().TransformType(T->getElementType());
2498 if (ElementType.isNull())
2499 return QualType();
2500
2501 QualType Result = TL.getType();
2502 if (getDerived().AlwaysRebuild() ||
2503 ElementType != T->getElementType()) {
2504 Result = getDerived().RebuildExtVectorType(ElementType,
2505 T->getNumElements(),
2506 /*FIXME*/ SourceLocation());
2507 if (Result.isNull())
2508 return QualType();
2509 }
2510
2511 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2512 NewTL.setNameLoc(TL.getNameLoc());
2513
2514 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002515}
Mike Stump11289f42009-09-09 15:08:12 +00002516
2517template<typename Derived>
2518QualType
John McCall550e0c22009-10-21 00:40:46 +00002519TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002520 FunctionProtoTypeLoc TL,
2521 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002522 FunctionProtoType *T = TL.getTypePtr();
2523 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002524 if (ResultType.isNull())
2525 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002526
John McCall550e0c22009-10-21 00:40:46 +00002527 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002528 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002529 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2530 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2531 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002532
John McCall550e0c22009-10-21 00:40:46 +00002533 QualType NewType;
2534 ParmVarDecl *NewParm;
2535
2536 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002537 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002538 assert(OldDI->getType() == T->getArgType(i));
2539
John McCallbcd03502009-12-07 02:54:59 +00002540 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002541 if (!NewDI)
2542 return QualType();
2543
2544 if (NewDI == OldDI)
2545 NewParm = OldParm;
2546 else
2547 NewParm = ParmVarDecl::Create(SemaRef.Context,
2548 OldParm->getDeclContext(),
2549 OldParm->getLocation(),
2550 OldParm->getIdentifier(),
2551 NewDI->getType(),
2552 NewDI,
2553 OldParm->getStorageClass(),
2554 /* DefArg */ NULL);
2555 NewType = NewParm->getType();
2556
2557 // Deal with the possibility that we don't have a parameter
2558 // declaration for this parameter.
2559 } else {
2560 NewParm = 0;
2561
2562 QualType OldType = T->getArgType(i);
2563 NewType = getDerived().TransformType(OldType);
2564 if (NewType.isNull())
2565 return QualType();
2566 }
2567
2568 ParamTypes.push_back(NewType);
2569 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002570 }
Mike Stump11289f42009-09-09 15:08:12 +00002571
John McCall550e0c22009-10-21 00:40:46 +00002572 QualType Result = TL.getType();
2573 if (getDerived().AlwaysRebuild() ||
2574 ResultType != T->getResultType() ||
2575 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2576 Result = getDerived().RebuildFunctionProtoType(ResultType,
2577 ParamTypes.data(),
2578 ParamTypes.size(),
2579 T->isVariadic(),
2580 T->getTypeQuals());
2581 if (Result.isNull())
2582 return QualType();
2583 }
Mike Stump11289f42009-09-09 15:08:12 +00002584
John McCall550e0c22009-10-21 00:40:46 +00002585 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2586 NewTL.setLParenLoc(TL.getLParenLoc());
2587 NewTL.setRParenLoc(TL.getRParenLoc());
2588 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2589 NewTL.setArg(i, ParamDecls[i]);
2590
2591 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002592}
Mike Stump11289f42009-09-09 15:08:12 +00002593
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594template<typename Derived>
2595QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002596 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002597 FunctionNoProtoTypeLoc TL,
2598 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002599 FunctionNoProtoType *T = TL.getTypePtr();
2600 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2601 if (ResultType.isNull())
2602 return QualType();
2603
2604 QualType Result = TL.getType();
2605 if (getDerived().AlwaysRebuild() ||
2606 ResultType != T->getResultType())
2607 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2608
2609 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2610 NewTL.setLParenLoc(TL.getLParenLoc());
2611 NewTL.setRParenLoc(TL.getRParenLoc());
2612
2613 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002614}
Mike Stump11289f42009-09-09 15:08:12 +00002615
John McCallb96ec562009-12-04 22:46:56 +00002616template<typename Derived> QualType
2617TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002618 UnresolvedUsingTypeLoc TL,
2619 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002620 UnresolvedUsingType *T = TL.getTypePtr();
2621 Decl *D = getDerived().TransformDecl(T->getDecl());
2622 if (!D)
2623 return QualType();
2624
2625 QualType Result = TL.getType();
2626 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2627 Result = getDerived().RebuildUnresolvedUsingType(D);
2628 if (Result.isNull())
2629 return QualType();
2630 }
2631
2632 // We might get an arbitrary type spec type back. We should at
2633 // least always get a type spec type, though.
2634 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2635 NewTL.setNameLoc(TL.getNameLoc());
2636
2637 return Result;
2638}
2639
Douglas Gregord6ff3322009-08-04 16:50:30 +00002640template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002641QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002642 TypedefTypeLoc TL,
2643 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002644 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 TypedefDecl *Typedef
2646 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2647 if (!Typedef)
2648 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002649
John McCall550e0c22009-10-21 00:40:46 +00002650 QualType Result = TL.getType();
2651 if (getDerived().AlwaysRebuild() ||
2652 Typedef != T->getDecl()) {
2653 Result = getDerived().RebuildTypedefType(Typedef);
2654 if (Result.isNull())
2655 return QualType();
2656 }
Mike Stump11289f42009-09-09 15:08:12 +00002657
John McCall550e0c22009-10-21 00:40:46 +00002658 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2659 NewTL.setNameLoc(TL.getNameLoc());
2660
2661 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662}
Mike Stump11289f42009-09-09 15:08:12 +00002663
Douglas Gregord6ff3322009-08-04 16:50:30 +00002664template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002665QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002666 TypeOfExprTypeLoc TL,
2667 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002668 // typeof expressions are not potentially evaluated contexts
2669 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002670
John McCalle8595032010-01-13 20:03:27 +00002671 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002672 if (E.isInvalid())
2673 return QualType();
2674
John McCall550e0c22009-10-21 00:40:46 +00002675 QualType Result = TL.getType();
2676 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002677 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002678 Result = getDerived().RebuildTypeOfExprType(move(E));
2679 if (Result.isNull())
2680 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002681 }
John McCall550e0c22009-10-21 00:40:46 +00002682 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002683
John McCall550e0c22009-10-21 00:40:46 +00002684 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002685 NewTL.setTypeofLoc(TL.getTypeofLoc());
2686 NewTL.setLParenLoc(TL.getLParenLoc());
2687 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002688
2689 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002690}
Mike Stump11289f42009-09-09 15:08:12 +00002691
2692template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002693QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002694 TypeOfTypeLoc TL,
2695 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002696 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2697 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2698 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002699 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002700
John McCall550e0c22009-10-21 00:40:46 +00002701 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002702 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2703 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002704 if (Result.isNull())
2705 return QualType();
2706 }
Mike Stump11289f42009-09-09 15:08:12 +00002707
John McCall550e0c22009-10-21 00:40:46 +00002708 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002709 NewTL.setTypeofLoc(TL.getTypeofLoc());
2710 NewTL.setLParenLoc(TL.getLParenLoc());
2711 NewTL.setRParenLoc(TL.getRParenLoc());
2712 NewTL.setUnderlyingTInfo(New_Under_TI);
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>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002719 DecltypeTypeLoc TL,
2720 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002721 DecltypeType *T = TL.getTypePtr();
2722
Douglas Gregore922c772009-08-04 22:27:00 +00002723 // decltype expressions are not potentially evaluated contexts
2724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002725
Douglas Gregord6ff3322009-08-04 16:50:30 +00002726 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2727 if (E.isInvalid())
2728 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002729
John McCall550e0c22009-10-21 00:40:46 +00002730 QualType Result = TL.getType();
2731 if (getDerived().AlwaysRebuild() ||
2732 E.get() != T->getUnderlyingExpr()) {
2733 Result = getDerived().RebuildDecltypeType(move(E));
2734 if (Result.isNull())
2735 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736 }
John McCall550e0c22009-10-21 00:40:46 +00002737 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002738
John McCall550e0c22009-10-21 00:40:46 +00002739 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2740 NewTL.setNameLoc(TL.getNameLoc());
2741
2742 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002743}
2744
2745template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002746QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002747 RecordTypeLoc TL,
2748 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002749 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002751 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002752 if (!Record)
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 Record != T->getDecl()) {
2758 Result = getDerived().RebuildRecordType(Record);
2759 if (Result.isNull())
2760 return QualType();
2761 }
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall550e0c22009-10-21 00:40:46 +00002763 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2764 NewTL.setNameLoc(TL.getNameLoc());
2765
2766 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002767}
Mike Stump11289f42009-09-09 15:08:12 +00002768
2769template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002770QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002771 EnumTypeLoc TL,
2772 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002773 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002774 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002775 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002776 if (!Enum)
2777 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002778
John McCall550e0c22009-10-21 00:40:46 +00002779 QualType Result = TL.getType();
2780 if (getDerived().AlwaysRebuild() ||
2781 Enum != T->getDecl()) {
2782 Result = getDerived().RebuildEnumType(Enum);
2783 if (Result.isNull())
2784 return QualType();
2785 }
Mike Stump11289f42009-09-09 15:08:12 +00002786
John McCall550e0c22009-10-21 00:40:46 +00002787 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2788 NewTL.setNameLoc(TL.getNameLoc());
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
John McCallfcc33b02009-09-05 00:15:47 +00002792
2793template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 ElaboratedTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 ElaboratedType *T = TL.getTypePtr();
2798
2799 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002800 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2801 if (Underlying.isNull())
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 Underlying != T->getUnderlyingType()) {
2807 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2808 if (Result.isNull())
2809 return QualType();
2810 }
Mike Stump11289f42009-09-09 15:08:12 +00002811
John McCall550e0c22009-10-21 00:40:46 +00002812 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2813 NewTL.setNameLoc(TL.getNameLoc());
2814
2815 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002816}
Mike Stump11289f42009-09-09 15:08:12 +00002817
2818
Douglas Gregord6ff3322009-08-04 16:50:30 +00002819template<typename Derived>
2820QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002821 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002822 TemplateTypeParmTypeLoc TL,
2823 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002824 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002825}
2826
Mike Stump11289f42009-09-09 15:08:12 +00002827template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002828QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002829 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002830 SubstTemplateTypeParmTypeLoc TL,
2831 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002832 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002833}
2834
2835template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002836QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2837 const TemplateSpecializationType *TST,
2838 QualType ObjectType) {
2839 // FIXME: this entire method is a temporary workaround; callers
2840 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002841
John McCall0ad16662009-10-29 08:12:44 +00002842 // Fake up a TemplateSpecializationTypeLoc.
2843 TypeLocBuilder TLB;
2844 TemplateSpecializationTypeLoc TL
2845 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2846
John McCall0d07eb32009-10-29 18:45:58 +00002847 SourceLocation BaseLoc = getDerived().getBaseLocation();
2848
2849 TL.setTemplateNameLoc(BaseLoc);
2850 TL.setLAngleLoc(BaseLoc);
2851 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002852 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2853 const TemplateArgument &TA = TST->getArg(i);
2854 TemplateArgumentLoc TAL;
2855 getDerived().InventTemplateArgumentLoc(TA, TAL);
2856 TL.setArgLocInfo(i, TAL.getLocInfo());
2857 }
2858
2859 TypeLocBuilder IgnoredTLB;
2860 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002861}
2862
2863template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002864QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002865 TypeLocBuilder &TLB,
2866 TemplateSpecializationTypeLoc TL,
2867 QualType ObjectType) {
2868 const TemplateSpecializationType *T = TL.getTypePtr();
2869
Mike Stump11289f42009-09-09 15:08:12 +00002870 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002871 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002872 if (Template.isNull())
2873 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002874
John McCall6b51f282009-11-23 01:53:49 +00002875 TemplateArgumentListInfo NewTemplateArgs;
2876 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2877 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2878
2879 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2880 TemplateArgumentLoc Loc;
2881 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002883 NewTemplateArgs.addArgument(Loc);
2884 }
Mike Stump11289f42009-09-09 15:08:12 +00002885
John McCall0ad16662009-10-29 08:12:44 +00002886 // FIXME: maybe don't rebuild if all the template arguments are the same.
2887
2888 QualType Result =
2889 getDerived().RebuildTemplateSpecializationType(Template,
2890 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002891 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002892
2893 if (!Result.isNull()) {
2894 TemplateSpecializationTypeLoc NewTL
2895 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2896 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2897 NewTL.setLAngleLoc(TL.getLAngleLoc());
2898 NewTL.setRAngleLoc(TL.getRAngleLoc());
2899 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2900 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901 }
Mike Stump11289f42009-09-09 15:08:12 +00002902
John McCall0ad16662009-10-29 08:12:44 +00002903 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904}
Mike Stump11289f42009-09-09 15:08:12 +00002905
2906template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002907QualType
2908TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002909 QualifiedNameTypeLoc TL,
2910 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002911 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002912 NestedNameSpecifier *NNS
2913 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002914 SourceRange(),
2915 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916 if (!NNS)
2917 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002918
Douglas Gregord6ff3322009-08-04 16:50:30 +00002919 QualType Named = getDerived().TransformType(T->getNamedType());
2920 if (Named.isNull())
2921 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002922
John McCall550e0c22009-10-21 00:40:46 +00002923 QualType Result = TL.getType();
2924 if (getDerived().AlwaysRebuild() ||
2925 NNS != T->getQualifier() ||
2926 Named != T->getNamedType()) {
2927 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2928 if (Result.isNull())
2929 return QualType();
2930 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931
John McCall550e0c22009-10-21 00:40:46 +00002932 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2933 NewTL.setNameLoc(TL.getNameLoc());
2934
2935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936}
Mike Stump11289f42009-09-09 15:08:12 +00002937
2938template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002939QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002940 TypenameTypeLoc TL,
2941 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002942 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002943
2944 /* FIXME: preserve source information better than this */
2945 SourceRange SR(TL.getNameLoc());
2946
Douglas Gregord6ff3322009-08-04 16:50:30 +00002947 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00002948 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002949 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002950 if (!NNS)
2951 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002952
John McCall550e0c22009-10-21 00:40:46 +00002953 QualType Result;
2954
Douglas Gregord6ff3322009-08-04 16:50:30 +00002955 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002956 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002957 = getDerived().TransformType(QualType(TemplateId, 0));
2958 if (NewTemplateId.isNull())
2959 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002960
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961 if (!getDerived().AlwaysRebuild() &&
2962 NNS == T->getQualifier() &&
2963 NewTemplateId == QualType(TemplateId, 0))
2964 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002965
John McCall550e0c22009-10-21 00:40:46 +00002966 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2967 } else {
John McCall0ad16662009-10-29 08:12:44 +00002968 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969 }
John McCall550e0c22009-10-21 00:40:46 +00002970 if (Result.isNull())
2971 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002972
John McCall550e0c22009-10-21 00:40:46 +00002973 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2974 NewTL.setNameLoc(TL.getNameLoc());
2975
2976 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977}
Mike Stump11289f42009-09-09 15:08:12 +00002978
Douglas Gregord6ff3322009-08-04 16:50:30 +00002979template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002980QualType
2981TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002982 ObjCInterfaceTypeLoc TL,
2983 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00002984 assert(false && "TransformObjCInterfaceType unimplemented");
2985 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002986}
Mike Stump11289f42009-09-09 15:08:12 +00002987
2988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002989QualType
2990TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002991 ObjCObjectPointerTypeLoc TL,
2992 QualType ObjectType) {
John McCallfc93cf92009-10-22 22:37:11 +00002993 assert(false && "TransformObjCObjectPointerType unimplemented");
2994 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002995}
2996
Douglas Gregord6ff3322009-08-04 16:50:30 +00002997//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002998// Statement transformation
2999//===----------------------------------------------------------------------===//
3000template<typename Derived>
3001Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003002TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3003 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003004}
3005
3006template<typename Derived>
3007Sema::OwningStmtResult
3008TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3009 return getDerived().TransformCompoundStmt(S, false);
3010}
3011
3012template<typename Derived>
3013Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003014TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003015 bool IsStmtExpr) {
3016 bool SubStmtChanged = false;
3017 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3018 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3019 B != BEnd; ++B) {
3020 OwningStmtResult Result = getDerived().TransformStmt(*B);
3021 if (Result.isInvalid())
3022 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003023
Douglas Gregorebe10102009-08-20 07:17:43 +00003024 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3025 Statements.push_back(Result.takeAs<Stmt>());
3026 }
Mike Stump11289f42009-09-09 15:08:12 +00003027
Douglas Gregorebe10102009-08-20 07:17:43 +00003028 if (!getDerived().AlwaysRebuild() &&
3029 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003030 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003031
3032 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3033 move_arg(Statements),
3034 S->getRBracLoc(),
3035 IsStmtExpr);
3036}
Mike Stump11289f42009-09-09 15:08:12 +00003037
Douglas Gregorebe10102009-08-20 07:17:43 +00003038template<typename Derived>
3039Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003040TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003041 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3042 {
3043 // The case value expressions are not potentially evaluated.
3044 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003045
Eli Friedman06577382009-11-19 03:14:00 +00003046 // Transform the left-hand case value.
3047 LHS = getDerived().TransformExpr(S->getLHS());
3048 if (LHS.isInvalid())
3049 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003050
Eli Friedman06577382009-11-19 03:14:00 +00003051 // Transform the right-hand case value (for the GNU case-range extension).
3052 RHS = getDerived().TransformExpr(S->getRHS());
3053 if (RHS.isInvalid())
3054 return SemaRef.StmtError();
3055 }
Mike Stump11289f42009-09-09 15:08:12 +00003056
Douglas Gregorebe10102009-08-20 07:17:43 +00003057 // Build the case statement.
3058 // Case statements are always rebuilt so that they will attached to their
3059 // transformed switch statement.
3060 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3061 move(LHS),
3062 S->getEllipsisLoc(),
3063 move(RHS),
3064 S->getColonLoc());
3065 if (Case.isInvalid())
3066 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003067
Douglas Gregorebe10102009-08-20 07:17:43 +00003068 // Transform the statement following the case
3069 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3070 if (SubStmt.isInvalid())
3071 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003072
Douglas Gregorebe10102009-08-20 07:17:43 +00003073 // Attach the body to the case statement
3074 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3075}
3076
3077template<typename Derived>
3078Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003079TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003080 // Transform the statement following the default case
3081 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3082 if (SubStmt.isInvalid())
3083 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003084
Douglas Gregorebe10102009-08-20 07:17:43 +00003085 // Default statements are always rebuilt
3086 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3087 move(SubStmt));
3088}
Mike Stump11289f42009-09-09 15:08:12 +00003089
Douglas Gregorebe10102009-08-20 07:17:43 +00003090template<typename Derived>
3091Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003092TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003093 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3094 if (SubStmt.isInvalid())
3095 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003096
Douglas Gregorebe10102009-08-20 07:17:43 +00003097 // FIXME: Pass the real colon location in.
3098 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3099 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3100 move(SubStmt));
3101}
Mike Stump11289f42009-09-09 15:08:12 +00003102
Douglas Gregorebe10102009-08-20 07:17:43 +00003103template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003104Sema::OwningStmtResult
3105TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003106 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003107 OwningExprResult Cond(SemaRef);
3108 VarDecl *ConditionVar = 0;
3109 if (S->getConditionVariable()) {
3110 ConditionVar
3111 = cast_or_null<VarDecl>(
3112 getDerived().TransformDefinition(S->getConditionVariable()));
3113 if (!ConditionVar)
3114 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003115 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003116 Cond = getDerived().TransformExpr(S->getCond());
3117
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003118 if (Cond.isInvalid())
3119 return SemaRef.StmtError();
3120 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003121
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003122 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003123
Douglas Gregorebe10102009-08-20 07:17:43 +00003124 // Transform the "then" branch.
3125 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3126 if (Then.isInvalid())
3127 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003128
Douglas Gregorebe10102009-08-20 07:17:43 +00003129 // Transform the "else" branch.
3130 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3131 if (Else.isInvalid())
3132 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003133
Douglas Gregorebe10102009-08-20 07:17:43 +00003134 if (!getDerived().AlwaysRebuild() &&
3135 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003136 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003137 Then.get() == S->getThen() &&
3138 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003139 return SemaRef.Owned(S->Retain());
3140
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003141 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3142 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003143 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003144}
3145
3146template<typename Derived>
3147Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003148TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003149 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003150 OwningExprResult Cond(SemaRef);
3151 VarDecl *ConditionVar = 0;
3152 if (S->getConditionVariable()) {
3153 ConditionVar
3154 = cast_or_null<VarDecl>(
3155 getDerived().TransformDefinition(S->getConditionVariable()));
3156 if (!ConditionVar)
3157 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003158 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003159 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003160
3161 if (Cond.isInvalid())
3162 return SemaRef.StmtError();
3163 }
Mike Stump11289f42009-09-09 15:08:12 +00003164
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003165 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003166
Douglas Gregorebe10102009-08-20 07:17:43 +00003167 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003168 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3169 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003170 if (Switch.isInvalid())
3171 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003172
Douglas Gregorebe10102009-08-20 07:17:43 +00003173 // Transform the body of the switch statement.
3174 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3175 if (Body.isInvalid())
3176 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003177
Douglas Gregorebe10102009-08-20 07:17:43 +00003178 // Complete the switch statement.
3179 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3180 move(Body));
3181}
Mike Stump11289f42009-09-09 15:08:12 +00003182
Douglas Gregorebe10102009-08-20 07:17:43 +00003183template<typename Derived>
3184Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003185TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003186 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003187 OwningExprResult Cond(SemaRef);
3188 VarDecl *ConditionVar = 0;
3189 if (S->getConditionVariable()) {
3190 ConditionVar
3191 = cast_or_null<VarDecl>(
3192 getDerived().TransformDefinition(S->getConditionVariable()));
3193 if (!ConditionVar)
3194 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003195 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003196 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003197
3198 if (Cond.isInvalid())
3199 return SemaRef.StmtError();
3200 }
Mike Stump11289f42009-09-09 15:08:12 +00003201
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003202 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003203
Douglas Gregorebe10102009-08-20 07:17:43 +00003204 // Transform the body
3205 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3206 if (Body.isInvalid())
3207 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003208
Douglas Gregorebe10102009-08-20 07:17:43 +00003209 if (!getDerived().AlwaysRebuild() &&
3210 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003211 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003212 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003213 return SemaRef.Owned(S->Retain());
3214
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003215 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3216 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003217}
Mike Stump11289f42009-09-09 15:08:12 +00003218
Douglas Gregorebe10102009-08-20 07:17:43 +00003219template<typename Derived>
3220Sema::OwningStmtResult
3221TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3222 // Transform the condition
3223 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3224 if (Cond.isInvalid())
3225 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003226
Douglas Gregorebe10102009-08-20 07:17:43 +00003227 // Transform the body
3228 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3229 if (Body.isInvalid())
3230 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003231
Douglas Gregorebe10102009-08-20 07:17:43 +00003232 if (!getDerived().AlwaysRebuild() &&
3233 Cond.get() == S->getCond() &&
3234 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003235 return SemaRef.Owned(S->Retain());
3236
Douglas Gregorebe10102009-08-20 07:17:43 +00003237 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3238 /*FIXME:*/S->getWhileLoc(), move(Cond),
3239 S->getRParenLoc());
3240}
Mike Stump11289f42009-09-09 15:08:12 +00003241
Douglas Gregorebe10102009-08-20 07:17:43 +00003242template<typename Derived>
3243Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003244TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003245 // Transform the initialization statement
3246 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3247 if (Init.isInvalid())
3248 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003249
Douglas Gregorebe10102009-08-20 07:17:43 +00003250 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003251 OwningExprResult Cond(SemaRef);
3252 VarDecl *ConditionVar = 0;
3253 if (S->getConditionVariable()) {
3254 ConditionVar
3255 = cast_or_null<VarDecl>(
3256 getDerived().TransformDefinition(S->getConditionVariable()));
3257 if (!ConditionVar)
3258 return SemaRef.StmtError();
3259 } else {
3260 Cond = getDerived().TransformExpr(S->getCond());
3261
3262 if (Cond.isInvalid())
3263 return SemaRef.StmtError();
3264 }
Mike Stump11289f42009-09-09 15:08:12 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266 // Transform the increment
3267 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3268 if (Inc.isInvalid())
3269 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003270
Douglas Gregorebe10102009-08-20 07:17:43 +00003271 // Transform the body
3272 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3273 if (Body.isInvalid())
3274 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003275
Douglas Gregorebe10102009-08-20 07:17:43 +00003276 if (!getDerived().AlwaysRebuild() &&
3277 Init.get() == S->getInit() &&
3278 Cond.get() == S->getCond() &&
3279 Inc.get() == S->getInc() &&
3280 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003281 return SemaRef.Owned(S->Retain());
3282
Douglas Gregorebe10102009-08-20 07:17:43 +00003283 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003284 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003285 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003286 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 S->getRParenLoc(), move(Body));
3288}
3289
3290template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003291Sema::OwningStmtResult
3292TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003293 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003294 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003295 S->getLabel());
3296}
3297
3298template<typename Derived>
3299Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003300TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3302 if (Target.isInvalid())
3303 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003304
Douglas Gregorebe10102009-08-20 07:17:43 +00003305 if (!getDerived().AlwaysRebuild() &&
3306 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003307 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003308
3309 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3310 move(Target));
3311}
3312
3313template<typename Derived>
3314Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003315TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3316 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003317}
Mike Stump11289f42009-09-09 15:08:12 +00003318
Douglas Gregorebe10102009-08-20 07:17:43 +00003319template<typename Derived>
3320Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003321TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3322 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003323}
Mike Stump11289f42009-09-09 15:08:12 +00003324
Douglas Gregorebe10102009-08-20 07:17:43 +00003325template<typename Derived>
3326Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003327TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003328 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3329 if (Result.isInvalid())
3330 return SemaRef.StmtError();
3331
Mike Stump11289f42009-09-09 15:08:12 +00003332 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003333 // to tell whether the return type of the function has changed.
3334 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3335}
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregorebe10102009-08-20 07:17:43 +00003337template<typename Derived>
3338Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003339TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003340 bool DeclChanged = false;
3341 llvm::SmallVector<Decl *, 4> Decls;
3342 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3343 D != DEnd; ++D) {
3344 Decl *Transformed = getDerived().TransformDefinition(*D);
3345 if (!Transformed)
3346 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003347
Douglas Gregorebe10102009-08-20 07:17:43 +00003348 if (Transformed != *D)
3349 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003350
Douglas Gregorebe10102009-08-20 07:17:43 +00003351 Decls.push_back(Transformed);
3352 }
Mike Stump11289f42009-09-09 15:08:12 +00003353
Douglas Gregorebe10102009-08-20 07:17:43 +00003354 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003355 return SemaRef.Owned(S->Retain());
3356
3357 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003358 S->getStartLoc(), S->getEndLoc());
3359}
Mike Stump11289f42009-09-09 15:08:12 +00003360
Douglas Gregorebe10102009-08-20 07:17:43 +00003361template<typename Derived>
3362Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003363TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003364 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003365 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003366}
3367
3368template<typename Derived>
3369Sema::OwningStmtResult
3370TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003371
3372 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3373 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003374 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003375
Anders Carlssonaaeef072010-01-24 05:50:09 +00003376 OwningExprResult AsmString(SemaRef);
3377 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3378
3379 bool ExprsChanged = false;
3380
3381 // Go through the outputs.
3382 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003383 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003384
Anders Carlssonaaeef072010-01-24 05:50:09 +00003385 // No need to transform the constraint literal.
3386 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3387
3388 // Transform the output expr.
3389 Expr *OutputExpr = S->getOutputExpr(I);
3390 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3391 if (Result.isInvalid())
3392 return SemaRef.StmtError();
3393
3394 ExprsChanged |= Result.get() != OutputExpr;
3395
3396 Exprs.push_back(Result.takeAs<Expr>());
3397 }
3398
3399 // Go through the inputs.
3400 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003401 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003402
Anders Carlssonaaeef072010-01-24 05:50:09 +00003403 // No need to transform the constraint literal.
3404 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3405
3406 // Transform the input expr.
3407 Expr *InputExpr = S->getInputExpr(I);
3408 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3409 if (Result.isInvalid())
3410 return SemaRef.StmtError();
3411
3412 ExprsChanged |= Result.get() != InputExpr;
3413
3414 Exprs.push_back(Result.takeAs<Expr>());
3415 }
3416
3417 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3418 return SemaRef.Owned(S->Retain());
3419
3420 // Go through the clobbers.
3421 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3422 Clobbers.push_back(S->getClobber(I)->Retain());
3423
3424 // No need to transform the asm string literal.
3425 AsmString = SemaRef.Owned(S->getAsmString());
3426
3427 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3428 S->isSimple(),
3429 S->isVolatile(),
3430 S->getNumOutputs(),
3431 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003432 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003433 move_arg(Constraints),
3434 move_arg(Exprs),
3435 move(AsmString),
3436 move_arg(Clobbers),
3437 S->getRParenLoc(),
3438 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003439}
3440
3441
3442template<typename Derived>
3443Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003444TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003445 // FIXME: Implement this
3446 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003447 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003448}
Mike Stump11289f42009-09-09 15:08:12 +00003449
Douglas Gregorebe10102009-08-20 07:17:43 +00003450template<typename Derived>
3451Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003452TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 // FIXME: Implement this
3454 assert(false && "Cannot transform an Objective-C @catch statement");
3455 return SemaRef.Owned(S->Retain());
3456}
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458template<typename Derived>
3459Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003460TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003461 // FIXME: Implement this
3462 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003463 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003464}
Mike Stump11289f42009-09-09 15:08:12 +00003465
Douglas Gregorebe10102009-08-20 07:17:43 +00003466template<typename Derived>
3467Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003468TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 // FIXME: Implement this
3470 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003471 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003472}
Mike Stump11289f42009-09-09 15:08:12 +00003473
Douglas Gregorebe10102009-08-20 07:17:43 +00003474template<typename Derived>
3475Sema::OwningStmtResult
3476TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003477 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003478 // FIXME: Implement this
3479 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003480 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003481}
3482
3483template<typename Derived>
3484Sema::OwningStmtResult
3485TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003486 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003487 // FIXME: Implement this
3488 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003489 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003490}
3491
3492
3493template<typename Derived>
3494Sema::OwningStmtResult
3495TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3496 // Transform the exception declaration, if any.
3497 VarDecl *Var = 0;
3498 if (S->getExceptionDecl()) {
3499 VarDecl *ExceptionDecl = S->getExceptionDecl();
3500 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3501 ExceptionDecl->getDeclName());
3502
3503 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3504 if (T.isNull())
3505 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3508 T,
John McCallbcd03502009-12-07 02:54:59 +00003509 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003510 ExceptionDecl->getIdentifier(),
3511 ExceptionDecl->getLocation(),
3512 /*FIXME: Inaccurate*/
3513 SourceRange(ExceptionDecl->getLocation()));
3514 if (!Var || Var->isInvalidDecl()) {
3515 if (Var)
3516 Var->Destroy(SemaRef.Context);
3517 return SemaRef.StmtError();
3518 }
3519 }
Mike Stump11289f42009-09-09 15:08:12 +00003520
Douglas Gregorebe10102009-08-20 07:17:43 +00003521 // Transform the actual exception handler.
3522 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3523 if (Handler.isInvalid()) {
3524 if (Var)
3525 Var->Destroy(SemaRef.Context);
3526 return SemaRef.StmtError();
3527 }
Mike Stump11289f42009-09-09 15:08:12 +00003528
Douglas Gregorebe10102009-08-20 07:17:43 +00003529 if (!getDerived().AlwaysRebuild() &&
3530 !Var &&
3531 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003532 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003533
3534 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3535 Var,
3536 move(Handler));
3537}
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539template<typename Derived>
3540Sema::OwningStmtResult
3541TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3542 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003543 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003544 = getDerived().TransformCompoundStmt(S->getTryBlock());
3545 if (TryBlock.isInvalid())
3546 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003547
Douglas Gregorebe10102009-08-20 07:17:43 +00003548 // Transform the handlers.
3549 bool HandlerChanged = false;
3550 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3551 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003552 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003553 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3554 if (Handler.isInvalid())
3555 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregorebe10102009-08-20 07:17:43 +00003557 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3558 Handlers.push_back(Handler.takeAs<Stmt>());
3559 }
Mike Stump11289f42009-09-09 15:08:12 +00003560
Douglas Gregorebe10102009-08-20 07:17:43 +00003561 if (!getDerived().AlwaysRebuild() &&
3562 TryBlock.get() == S->getTryBlock() &&
3563 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003564 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003565
3566 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003567 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003568}
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregorebe10102009-08-20 07:17:43 +00003570//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003571// Expression transformation
3572//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003573template<typename Derived>
3574Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003575TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003576 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003577}
Mike Stump11289f42009-09-09 15:08:12 +00003578
3579template<typename Derived>
3580Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003581TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003582 NestedNameSpecifier *Qualifier = 0;
3583 if (E->getQualifier()) {
3584 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003585 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003586 if (!Qualifier)
3587 return SemaRef.ExprError();
3588 }
John McCallce546572009-12-08 09:08:17 +00003589
3590 ValueDecl *ND
3591 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003592 if (!ND)
3593 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003594
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003595 if (!getDerived().AlwaysRebuild() &&
3596 Qualifier == E->getQualifier() &&
3597 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003598 !E->hasExplicitTemplateArgumentList()) {
3599
3600 // Mark it referenced in the new context regardless.
3601 // FIXME: this is a bit instantiation-specific.
3602 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3603
Mike Stump11289f42009-09-09 15:08:12 +00003604 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003605 }
John McCallce546572009-12-08 09:08:17 +00003606
3607 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3608 if (E->hasExplicitTemplateArgumentList()) {
3609 TemplateArgs = &TransArgs;
3610 TransArgs.setLAngleLoc(E->getLAngleLoc());
3611 TransArgs.setRAngleLoc(E->getRAngleLoc());
3612 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3613 TemplateArgumentLoc Loc;
3614 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3615 return SemaRef.ExprError();
3616 TransArgs.addArgument(Loc);
3617 }
3618 }
3619
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003620 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003621 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003622}
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregora16548e2009-08-11 05:31:07 +00003624template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003625Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003626TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003627 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003628}
Mike Stump11289f42009-09-09 15:08:12 +00003629
Douglas Gregora16548e2009-08-11 05:31:07 +00003630template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003631Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003632TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003633 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003634}
Mike Stump11289f42009-09-09 15:08:12 +00003635
Douglas Gregora16548e2009-08-11 05:31:07 +00003636template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003637Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003638TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003639 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003640}
Mike Stump11289f42009-09-09 15:08:12 +00003641
Douglas Gregora16548e2009-08-11 05:31:07 +00003642template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003643Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003644TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003645 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003646}
Mike Stump11289f42009-09-09 15:08:12 +00003647
Douglas Gregora16548e2009-08-11 05:31:07 +00003648template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003649Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003650TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003651 return SemaRef.Owned(E->Retain());
3652}
3653
3654template<typename Derived>
3655Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003656TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003657 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3658 if (SubExpr.isInvalid())
3659 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003660
Douglas Gregora16548e2009-08-11 05:31:07 +00003661 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003662 return SemaRef.Owned(E->Retain());
3663
3664 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003665 E->getRParen());
3666}
3667
Mike Stump11289f42009-09-09 15:08:12 +00003668template<typename Derived>
3669Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003670TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3671 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003672 if (SubExpr.isInvalid())
3673 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregora16548e2009-08-11 05:31:07 +00003675 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003676 return SemaRef.Owned(E->Retain());
3677
Douglas Gregora16548e2009-08-11 05:31:07 +00003678 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3679 E->getOpcode(),
3680 move(SubExpr));
3681}
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregora16548e2009-08-11 05:31:07 +00003683template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003684Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003685TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003686 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003687 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003688
John McCallbcd03502009-12-07 02:54:59 +00003689 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003690 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003691 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003692
John McCall4c98fd82009-11-04 07:28:41 +00003693 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003694 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003695
John McCall4c98fd82009-11-04 07:28:41 +00003696 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003697 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003698 E->getSourceRange());
3699 }
Mike Stump11289f42009-09-09 15:08:12 +00003700
Douglas Gregora16548e2009-08-11 05:31:07 +00003701 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003702 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003703 // C++0x [expr.sizeof]p1:
3704 // The operand is either an expression, which is an unevaluated operand
3705 // [...]
3706 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregora16548e2009-08-11 05:31:07 +00003708 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3709 if (SubExpr.isInvalid())
3710 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003711
Douglas Gregora16548e2009-08-11 05:31:07 +00003712 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3713 return SemaRef.Owned(E->Retain());
3714 }
Mike Stump11289f42009-09-09 15:08:12 +00003715
Douglas Gregora16548e2009-08-11 05:31:07 +00003716 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3717 E->isSizeOf(),
3718 E->getSourceRange());
3719}
Mike Stump11289f42009-09-09 15:08:12 +00003720
Douglas Gregora16548e2009-08-11 05:31:07 +00003721template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003722Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003723TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003724 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3725 if (LHS.isInvalid())
3726 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregora16548e2009-08-11 05:31:07 +00003728 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3729 if (RHS.isInvalid())
3730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003731
3732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 if (!getDerived().AlwaysRebuild() &&
3734 LHS.get() == E->getLHS() &&
3735 RHS.get() == E->getRHS())
3736 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregora16548e2009-08-11 05:31:07 +00003738 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3739 /*FIXME:*/E->getLHS()->getLocStart(),
3740 move(RHS),
3741 E->getRBracketLoc());
3742}
Mike Stump11289f42009-09-09 15:08:12 +00003743
3744template<typename Derived>
3745Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003746TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003747 // Transform the callee.
3748 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3749 if (Callee.isInvalid())
3750 return SemaRef.ExprError();
3751
3752 // Transform arguments.
3753 bool ArgChanged = false;
3754 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3755 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3756 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3757 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3758 if (Arg.isInvalid())
3759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 // FIXME: Wrong source location information for the ','.
3762 FakeCommaLocs.push_back(
3763 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003764
3765 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003766 Args.push_back(Arg.takeAs<Expr>());
3767 }
Mike Stump11289f42009-09-09 15:08:12 +00003768
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 if (!getDerived().AlwaysRebuild() &&
3770 Callee.get() == E->getCallee() &&
3771 !ArgChanged)
3772 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003773
Douglas Gregora16548e2009-08-11 05:31:07 +00003774 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003775 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003776 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3777 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3778 move_arg(Args),
3779 FakeCommaLocs.data(),
3780 E->getRParenLoc());
3781}
Mike Stump11289f42009-09-09 15:08:12 +00003782
3783template<typename Derived>
3784Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003785TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3787 if (Base.isInvalid())
3788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003790 NestedNameSpecifier *Qualifier = 0;
3791 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003792 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003793 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003794 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003795 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003796 return SemaRef.ExprError();
3797 }
Mike Stump11289f42009-09-09 15:08:12 +00003798
Eli Friedman2cfcef62009-12-04 06:40:45 +00003799 ValueDecl *Member
3800 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 if (!Member)
3802 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003803
Douglas Gregora16548e2009-08-11 05:31:07 +00003804 if (!getDerived().AlwaysRebuild() &&
3805 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003806 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003807 Member == E->getMemberDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003808 !E->hasExplicitTemplateArgumentList()) {
3809
3810 // Mark it referenced in the new context regardless.
3811 // FIXME: this is a bit instantiation-specific.
3812 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00003813 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00003814 }
Douglas Gregora16548e2009-08-11 05:31:07 +00003815
John McCall6b51f282009-11-23 01:53:49 +00003816 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003817 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003818 TransArgs.setLAngleLoc(E->getLAngleLoc());
3819 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003820 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003821 TemplateArgumentLoc Loc;
3822 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003823 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003824 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003825 }
3826 }
3827
Douglas Gregora16548e2009-08-11 05:31:07 +00003828 // FIXME: Bogus source location for the operator
3829 SourceLocation FakeOperatorLoc
3830 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3831
John McCall38836f02010-01-15 08:34:02 +00003832 // FIXME: to do this check properly, we will need to preserve the
3833 // first-qualifier-in-scope here, just in case we had a dependent
3834 // base (and therefore couldn't do the check) and a
3835 // nested-name-qualifier (and therefore could do the lookup).
3836 NamedDecl *FirstQualifierInScope = 0;
3837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3839 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003840 Qualifier,
3841 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003843 Member,
John McCall6b51f282009-11-23 01:53:49 +00003844 (E->hasExplicitTemplateArgumentList()
3845 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00003846 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00003847}
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003850Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003851TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003852 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3853 if (LHS.isInvalid())
3854 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003855
Douglas Gregora16548e2009-08-11 05:31:07 +00003856 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3857 if (RHS.isInvalid())
3858 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregora16548e2009-08-11 05:31:07 +00003860 if (!getDerived().AlwaysRebuild() &&
3861 LHS.get() == E->getLHS() &&
3862 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003863 return SemaRef.Owned(E->Retain());
3864
Douglas Gregora16548e2009-08-11 05:31:07 +00003865 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3866 move(LHS), move(RHS));
3867}
3868
Mike Stump11289f42009-09-09 15:08:12 +00003869template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003870Sema::OwningExprResult
3871TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003872 CompoundAssignOperator *E) {
3873 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003874}
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003877Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003878TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3880 if (Cond.isInvalid())
3881 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003882
Douglas Gregora16548e2009-08-11 05:31:07 +00003883 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3884 if (LHS.isInvalid())
3885 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3888 if (RHS.isInvalid())
3889 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891 if (!getDerived().AlwaysRebuild() &&
3892 Cond.get() == E->getCond() &&
3893 LHS.get() == E->getLHS() &&
3894 RHS.get() == E->getRHS())
3895 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003896
3897 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003898 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003899 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003900 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003901 move(RHS));
3902}
Mike Stump11289f42009-09-09 15:08:12 +00003903
3904template<typename Derived>
3905Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003906TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00003907 // Implicit casts are eliminated during transformation, since they
3908 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00003909 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003910}
Mike Stump11289f42009-09-09 15:08:12 +00003911
Douglas Gregora16548e2009-08-11 05:31:07 +00003912template<typename Derived>
3913Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003914TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00003915 TypeSourceInfo *OldT;
3916 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00003917 {
3918 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003919 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003920 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3921 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003922
John McCall97513962010-01-15 18:39:57 +00003923 OldT = E->getTypeInfoAsWritten();
3924 NewT = getDerived().TransformType(OldT);
3925 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 return SemaRef.ExprError();
3927 }
Mike Stump11289f42009-09-09 15:08:12 +00003928
Douglas Gregor6131b442009-12-12 18:16:41 +00003929 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00003930 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00003931 if (SubExpr.isInvalid())
3932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003933
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00003935 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003937 return SemaRef.Owned(E->Retain());
3938
John McCall97513962010-01-15 18:39:57 +00003939 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
3940 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 E->getRParenLoc(),
3942 move(SubExpr));
3943}
Mike Stump11289f42009-09-09 15:08:12 +00003944
Douglas Gregora16548e2009-08-11 05:31:07 +00003945template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003946Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003947TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00003948 TypeSourceInfo *OldT = E->getTypeSourceInfo();
3949 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
3950 if (!NewT)
3951 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003952
Douglas Gregora16548e2009-08-11 05:31:07 +00003953 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3954 if (Init.isInvalid())
3955 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003956
Douglas Gregora16548e2009-08-11 05:31:07 +00003957 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00003958 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003960 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003961
John McCall5d7aa7f2010-01-19 22:33:45 +00003962 // Note: the expression type doesn't necessarily match the
3963 // type-as-written, but that's okay, because it should always be
3964 // derivable from the initializer.
3965
John McCalle15bbff2010-01-18 19:35:47 +00003966 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 /*FIXME:*/E->getInitializer()->getLocEnd(),
3968 move(Init));
3969}
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregora16548e2009-08-11 05:31:07 +00003971template<typename Derived>
3972Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003973TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3975 if (Base.isInvalid())
3976 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003977
Douglas Gregora16548e2009-08-11 05:31:07 +00003978 if (!getDerived().AlwaysRebuild() &&
3979 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003980 return SemaRef.Owned(E->Retain());
3981
Douglas Gregora16548e2009-08-11 05:31:07 +00003982 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003983 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3985 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3986 E->getAccessorLoc(),
3987 E->getAccessor());
3988}
Mike Stump11289f42009-09-09 15:08:12 +00003989
Douglas Gregora16548e2009-08-11 05:31:07 +00003990template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003991Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003992TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003993 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregora16548e2009-08-11 05:31:07 +00003995 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3996 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3997 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3998 if (Init.isInvalid())
3999 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004000
Douglas Gregora16548e2009-08-11 05:31:07 +00004001 InitChanged = InitChanged || Init.get() != E->getInit(I);
4002 Inits.push_back(Init.takeAs<Expr>());
4003 }
Mike Stump11289f42009-09-09 15:08:12 +00004004
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004006 return SemaRef.Owned(E->Retain());
4007
Douglas Gregora16548e2009-08-11 05:31:07 +00004008 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004009 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004010}
Mike Stump11289f42009-09-09 15:08:12 +00004011
Douglas Gregora16548e2009-08-11 05:31:07 +00004012template<typename Derived>
4013Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004014TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004016
Douglas Gregorebe10102009-08-20 07:17:43 +00004017 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4019 if (Init.isInvalid())
4020 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004021
Douglas Gregorebe10102009-08-20 07:17:43 +00004022 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004023 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4024 bool ExprChanged = false;
4025 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4026 DEnd = E->designators_end();
4027 D != DEnd; ++D) {
4028 if (D->isFieldDesignator()) {
4029 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4030 D->getDotLoc(),
4031 D->getFieldLoc()));
4032 continue;
4033 }
Mike Stump11289f42009-09-09 15:08:12 +00004034
Douglas Gregora16548e2009-08-11 05:31:07 +00004035 if (D->isArrayDesignator()) {
4036 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4037 if (Index.isInvalid())
4038 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004039
4040 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004042
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4044 ArrayExprs.push_back(Index.release());
4045 continue;
4046 }
Mike Stump11289f42009-09-09 15:08:12 +00004047
Douglas Gregora16548e2009-08-11 05:31:07 +00004048 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004049 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004050 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4051 if (Start.isInvalid())
4052 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4055 if (End.isInvalid())
4056 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004057
4058 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004059 End.get(),
4060 D->getLBracketLoc(),
4061 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004062
Douglas Gregora16548e2009-08-11 05:31:07 +00004063 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4064 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004065
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 ArrayExprs.push_back(Start.release());
4067 ArrayExprs.push_back(End.release());
4068 }
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 if (!getDerived().AlwaysRebuild() &&
4071 Init.get() == E->getInit() &&
4072 !ExprChanged)
4073 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4076 E->getEqualOrColonLoc(),
4077 E->usesGNUSyntax(), move(Init));
4078}
Mike Stump11289f42009-09-09 15:08:12 +00004079
Douglas Gregora16548e2009-08-11 05:31:07 +00004080template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004081Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004082TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004083 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004084 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4085
4086 // FIXME: Will we ever have proper type location here? Will we actually
4087 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 QualType T = getDerived().TransformType(E->getType());
4089 if (T.isNull())
4090 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregora16548e2009-08-11 05:31:07 +00004092 if (!getDerived().AlwaysRebuild() &&
4093 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004094 return SemaRef.Owned(E->Retain());
4095
Douglas Gregora16548e2009-08-11 05:31:07 +00004096 return getDerived().RebuildImplicitValueInitExpr(T);
4097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregora16548e2009-08-11 05:31:07 +00004099template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004101TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 // FIXME: Do we want the type as written?
4103 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004104
Douglas Gregora16548e2009-08-11 05:31:07 +00004105 {
4106 // FIXME: Source location isn't quite accurate.
4107 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4108 T = getDerived().TransformType(E->getType());
4109 if (T.isNull())
4110 return SemaRef.ExprError();
4111 }
Mike Stump11289f42009-09-09 15:08:12 +00004112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4114 if (SubExpr.isInvalid())
4115 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117 if (!getDerived().AlwaysRebuild() &&
4118 T == E->getType() &&
4119 SubExpr.get() == E->getSubExpr())
4120 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4123 T, E->getRParenLoc());
4124}
4125
4126template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004128TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 bool ArgumentChanged = false;
4130 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4131 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4132 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4133 if (Init.isInvalid())
4134 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004135
Douglas Gregora16548e2009-08-11 05:31:07 +00004136 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4137 Inits.push_back(Init.takeAs<Expr>());
4138 }
Mike Stump11289f42009-09-09 15:08:12 +00004139
Douglas Gregora16548e2009-08-11 05:31:07 +00004140 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4141 move_arg(Inits),
4142 E->getRParenLoc());
4143}
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregora16548e2009-08-11 05:31:07 +00004145/// \brief Transform an address-of-label expression.
4146///
4147/// By default, the transformation of an address-of-label expression always
4148/// rebuilds the expression, so that the label identifier can be resolved to
4149/// the corresponding label statement by semantic analysis.
4150template<typename Derived>
4151Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004152TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004153 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4154 E->getLabel());
4155}
Mike Stump11289f42009-09-09 15:08:12 +00004156
4157template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004158Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004159TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004160 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004161 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4162 if (SubStmt.isInvalid())
4163 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165 if (!getDerived().AlwaysRebuild() &&
4166 SubStmt.get() == E->getSubStmt())
4167 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004168
4169 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 move(SubStmt),
4171 E->getRParenLoc());
4172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174template<typename Derived>
4175Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004176TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 QualType T1, T2;
4178 {
4179 // FIXME: Source location isn't quite accurate.
4180 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182 T1 = getDerived().TransformType(E->getArgType1());
4183 if (T1.isNull())
4184 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004185
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 T2 = getDerived().TransformType(E->getArgType2());
4187 if (T2.isNull())
4188 return SemaRef.ExprError();
4189 }
4190
4191 if (!getDerived().AlwaysRebuild() &&
4192 T1 == E->getArgType1() &&
4193 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004194 return SemaRef.Owned(E->Retain());
4195
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4197 T1, T2, E->getRParenLoc());
4198}
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200template<typename Derived>
4201Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004202TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004203 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4204 if (Cond.isInvalid())
4205 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004206
Douglas Gregora16548e2009-08-11 05:31:07 +00004207 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4208 if (LHS.isInvalid())
4209 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4212 if (RHS.isInvalid())
4213 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004214
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 if (!getDerived().AlwaysRebuild() &&
4216 Cond.get() == E->getCond() &&
4217 LHS.get() == E->getLHS() &&
4218 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004219 return SemaRef.Owned(E->Retain());
4220
Douglas Gregora16548e2009-08-11 05:31:07 +00004221 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4222 move(Cond), move(LHS), move(RHS),
4223 E->getRParenLoc());
4224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregora16548e2009-08-11 05:31:07 +00004226template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004227Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004228TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004229 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004230}
4231
4232template<typename Derived>
4233Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004234TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004235 switch (E->getOperator()) {
4236 case OO_New:
4237 case OO_Delete:
4238 case OO_Array_New:
4239 case OO_Array_Delete:
4240 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4241 return SemaRef.ExprError();
4242
4243 case OO_Call: {
4244 // This is a call to an object's operator().
4245 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4246
4247 // Transform the object itself.
4248 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4249 if (Object.isInvalid())
4250 return SemaRef.ExprError();
4251
4252 // FIXME: Poor location information
4253 SourceLocation FakeLParenLoc
4254 = SemaRef.PP.getLocForEndOfToken(
4255 static_cast<Expr *>(Object.get())->getLocEnd());
4256
4257 // Transform the call arguments.
4258 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4259 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4260 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004261 if (getDerived().DropCallArgument(E->getArg(I)))
4262 break;
4263
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004264 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4265 if (Arg.isInvalid())
4266 return SemaRef.ExprError();
4267
4268 // FIXME: Poor source location information.
4269 SourceLocation FakeCommaLoc
4270 = SemaRef.PP.getLocForEndOfToken(
4271 static_cast<Expr *>(Arg.get())->getLocEnd());
4272 FakeCommaLocs.push_back(FakeCommaLoc);
4273 Args.push_back(Arg.release());
4274 }
4275
4276 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4277 move_arg(Args),
4278 FakeCommaLocs.data(),
4279 E->getLocEnd());
4280 }
4281
4282#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4283 case OO_##Name:
4284#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4285#include "clang/Basic/OperatorKinds.def"
4286 case OO_Subscript:
4287 // Handled below.
4288 break;
4289
4290 case OO_Conditional:
4291 llvm_unreachable("conditional operator is not actually overloadable");
4292 return SemaRef.ExprError();
4293
4294 case OO_None:
4295 case NUM_OVERLOADED_OPERATORS:
4296 llvm_unreachable("not an overloaded operator?");
4297 return SemaRef.ExprError();
4298 }
4299
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4301 if (Callee.isInvalid())
4302 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004303
John McCall47f29ea2009-12-08 09:21:05 +00004304 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 if (First.isInvalid())
4306 return SemaRef.ExprError();
4307
4308 OwningExprResult Second(SemaRef);
4309 if (E->getNumArgs() == 2) {
4310 Second = getDerived().TransformExpr(E->getArg(1));
4311 if (Second.isInvalid())
4312 return SemaRef.ExprError();
4313 }
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 if (!getDerived().AlwaysRebuild() &&
4316 Callee.get() == E->getCallee() &&
4317 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004318 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4319 return SemaRef.Owned(E->Retain());
4320
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4322 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004323 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004324 move(First),
4325 move(Second));
4326}
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328template<typename Derived>
4329Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004330TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4331 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004332}
Mike Stump11289f42009-09-09 15:08:12 +00004333
Douglas Gregora16548e2009-08-11 05:31:07 +00004334template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004335Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004336TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004337 TypeSourceInfo *OldT;
4338 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 {
4340 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004341 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004342 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4343 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004344
John McCall97513962010-01-15 18:39:57 +00004345 OldT = E->getTypeInfoAsWritten();
4346 NewT = getDerived().TransformType(OldT);
4347 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 return SemaRef.ExprError();
4349 }
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregor6131b442009-12-12 18:16:41 +00004351 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004352 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 if (SubExpr.isInvalid())
4354 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004357 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004359 return SemaRef.Owned(E->Retain());
4360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004362 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004363 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4364 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4365 SourceLocation FakeRParenLoc
4366 = SemaRef.PP.getLocForEndOfToken(
4367 E->getSubExpr()->getSourceRange().getEnd());
4368 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004369 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004371 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 FakeRAngleLoc,
4373 FakeRAngleLoc,
4374 move(SubExpr),
4375 FakeRParenLoc);
4376}
Mike Stump11289f42009-09-09 15:08:12 +00004377
Douglas Gregora16548e2009-08-11 05:31:07 +00004378template<typename Derived>
4379Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004380TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4381 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004382}
Mike Stump11289f42009-09-09 15:08:12 +00004383
4384template<typename Derived>
4385Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004386TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4387 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004388}
4389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390template<typename Derived>
4391Sema::OwningExprResult
4392TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004393 CXXReinterpretCastExpr *E) {
4394 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
4398Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4400 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004401}
Mike Stump11289f42009-09-09 15:08:12 +00004402
Douglas Gregora16548e2009-08-11 05:31:07 +00004403template<typename Derived>
4404Sema::OwningExprResult
4405TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004406 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004407 TypeSourceInfo *OldT;
4408 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 {
4410 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004411
John McCall97513962010-01-15 18:39:57 +00004412 OldT = E->getTypeInfoAsWritten();
4413 NewT = getDerived().TransformType(OldT);
4414 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 return SemaRef.ExprError();
4416 }
Mike Stump11289f42009-09-09 15:08:12 +00004417
Douglas Gregor6131b442009-12-12 18:16:41 +00004418 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004419 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004420 if (SubExpr.isInvalid())
4421 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004424 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004426 return SemaRef.Owned(E->Retain());
4427
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 // FIXME: The end of the type's source range is wrong
4429 return getDerived().RebuildCXXFunctionalCastExpr(
4430 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004431 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004432 /*FIXME:*/E->getSubExpr()->getLocStart(),
4433 move(SubExpr),
4434 E->getRParenLoc());
4435}
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437template<typename Derived>
4438Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004439TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 if (E->isTypeOperand()) {
4441 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004442
Douglas Gregora16548e2009-08-11 05:31:07 +00004443 QualType T = getDerived().TransformType(E->getTypeOperand());
4444 if (T.isNull())
4445 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 if (!getDerived().AlwaysRebuild() &&
4448 T == E->getTypeOperand())
4449 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004450
Douglas Gregora16548e2009-08-11 05:31:07 +00004451 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4452 /*FIXME:*/E->getLocStart(),
4453 T,
4454 E->getLocEnd());
4455 }
Mike Stump11289f42009-09-09 15:08:12 +00004456
Douglas Gregora16548e2009-08-11 05:31:07 +00004457 // We don't know whether the expression is potentially evaluated until
4458 // after we perform semantic analysis, so the expression is potentially
4459 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004460 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004462
Douglas Gregora16548e2009-08-11 05:31:07 +00004463 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4464 if (SubExpr.isInvalid())
4465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 if (!getDerived().AlwaysRebuild() &&
4468 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004469 return SemaRef.Owned(E->Retain());
4470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4472 /*FIXME:*/E->getLocStart(),
4473 move(SubExpr),
4474 E->getLocEnd());
4475}
4476
4477template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004478Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004479TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004480 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004481}
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483template<typename Derived>
4484Sema::OwningExprResult
4485TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004486 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004487 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004488}
Mike Stump11289f42009-09-09 15:08:12 +00004489
Douglas Gregora16548e2009-08-11 05:31:07 +00004490template<typename Derived>
4491Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004492TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregora16548e2009-08-11 05:31:07 +00004495 QualType T = getDerived().TransformType(E->getType());
4496 if (T.isNull())
4497 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004498
Douglas Gregora16548e2009-08-11 05:31:07 +00004499 if (!getDerived().AlwaysRebuild() &&
4500 T == E->getType())
4501 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregorb15af892010-01-07 23:12:05 +00004503 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004504}
Mike Stump11289f42009-09-09 15:08:12 +00004505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506template<typename Derived>
4507Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004508TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004509 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4510 if (SubExpr.isInvalid())
4511 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004512
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 if (!getDerived().AlwaysRebuild() &&
4514 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004515 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004516
4517 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4518}
Mike Stump11289f42009-09-09 15:08:12 +00004519
Douglas Gregora16548e2009-08-11 05:31:07 +00004520template<typename Derived>
4521Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004522TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004523 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4525 if (!Param)
4526 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004527
Chandler Carruth794da4c2010-02-08 06:42:49 +00004528 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 Param == E->getParam())
4530 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregor033f6752009-12-23 23:03:06 +00004532 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004533}
Mike Stump11289f42009-09-09 15:08:12 +00004534
Douglas Gregora16548e2009-08-11 05:31:07 +00004535template<typename Derived>
4536Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004537TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004538 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4539
4540 QualType T = getDerived().TransformType(E->getType());
4541 if (T.isNull())
4542 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregora16548e2009-08-11 05:31:07 +00004544 if (!getDerived().AlwaysRebuild() &&
4545 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004546 return SemaRef.Owned(E->Retain());
4547
4548 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 /*FIXME:*/E->getTypeBeginLoc(),
4550 T,
4551 E->getRParenLoc());
4552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554template<typename Derived>
4555Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004556TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 // Transform the type that we're allocating
4558 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4559 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4560 if (AllocType.isNull())
4561 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004562
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 // Transform the size of the array we're allocating (if any).
4564 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4565 if (ArraySize.isInvalid())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 // Transform the placement arguments (if any).
4569 bool ArgumentChanged = false;
4570 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4571 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4572 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4573 if (Arg.isInvalid())
4574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004575
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4577 PlacementArgs.push_back(Arg.take());
4578 }
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregorebe10102009-08-20 07:17:43 +00004580 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4582 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4583 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4584 if (Arg.isInvalid())
4585 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004586
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4588 ConstructorArgs.push_back(Arg.take());
4589 }
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregord2d9da02010-02-26 00:38:10 +00004591 // Transform constructor, new operator, and delete operator.
4592 CXXConstructorDecl *Constructor = 0;
4593 if (E->getConstructor()) {
4594 Constructor = cast_or_null<CXXConstructorDecl>(
4595 getDerived().TransformDecl(E->getConstructor()));
4596 if (!Constructor)
4597 return SemaRef.ExprError();
4598 }
4599
4600 FunctionDecl *OperatorNew = 0;
4601 if (E->getOperatorNew()) {
4602 OperatorNew = cast_or_null<FunctionDecl>(
4603 getDerived().TransformDecl(E->getOperatorNew()));
4604 if (!OperatorNew)
4605 return SemaRef.ExprError();
4606 }
4607
4608 FunctionDecl *OperatorDelete = 0;
4609 if (E->getOperatorDelete()) {
4610 OperatorDelete = cast_or_null<FunctionDecl>(
4611 getDerived().TransformDecl(E->getOperatorDelete()));
4612 if (!OperatorDelete)
4613 return SemaRef.ExprError();
4614 }
4615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 if (!getDerived().AlwaysRebuild() &&
4617 AllocType == E->getAllocatedType() &&
4618 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004619 Constructor == E->getConstructor() &&
4620 OperatorNew == E->getOperatorNew() &&
4621 OperatorDelete == E->getOperatorDelete() &&
4622 !ArgumentChanged) {
4623 // Mark any declarations we need as referenced.
4624 // FIXME: instantiation-specific.
4625 if (Constructor)
4626 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4627 if (OperatorNew)
4628 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4629 if (OperatorDelete)
4630 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004631 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004632 }
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004634 if (!ArraySize.get()) {
4635 // If no array size was specified, but the new expression was
4636 // instantiated with an array type (e.g., "new T" where T is
4637 // instantiated with "int[4]"), extract the outer bound from the
4638 // array type as our array size. We do this with constant and
4639 // dependently-sized array types.
4640 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4641 if (!ArrayT) {
4642 // Do nothing
4643 } else if (const ConstantArrayType *ConsArrayT
4644 = dyn_cast<ConstantArrayType>(ArrayT)) {
4645 ArraySize
4646 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4647 ConsArrayT->getSize(),
4648 SemaRef.Context.getSizeType(),
4649 /*FIXME:*/E->getLocStart()));
4650 AllocType = ConsArrayT->getElementType();
4651 } else if (const DependentSizedArrayType *DepArrayT
4652 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4653 if (DepArrayT->getSizeExpr()) {
4654 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4655 AllocType = DepArrayT->getElementType();
4656 }
4657 }
4658 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4660 E->isGlobalNew(),
4661 /*FIXME:*/E->getLocStart(),
4662 move_arg(PlacementArgs),
4663 /*FIXME:*/E->getLocStart(),
4664 E->isParenTypeId(),
4665 AllocType,
4666 /*FIXME:*/E->getLocStart(),
4667 /*FIXME:*/SourceRange(),
4668 move(ArraySize),
4669 /*FIXME:*/E->getLocStart(),
4670 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004671 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004672}
Mike Stump11289f42009-09-09 15:08:12 +00004673
Douglas Gregora16548e2009-08-11 05:31:07 +00004674template<typename Derived>
4675Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004676TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004677 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4678 if (Operand.isInvalid())
4679 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004680
Douglas Gregord2d9da02010-02-26 00:38:10 +00004681 // Transform the delete operator, if known.
4682 FunctionDecl *OperatorDelete = 0;
4683 if (E->getOperatorDelete()) {
4684 OperatorDelete = cast_or_null<FunctionDecl>(
4685 getDerived().TransformDecl(E->getOperatorDelete()));
4686 if (!OperatorDelete)
4687 return SemaRef.ExprError();
4688 }
4689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004691 Operand.get() == E->getArgument() &&
4692 OperatorDelete == E->getOperatorDelete()) {
4693 // Mark any declarations we need as referenced.
4694 // FIXME: instantiation-specific.
4695 if (OperatorDelete)
4696 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004697 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004698 }
Mike Stump11289f42009-09-09 15:08:12 +00004699
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4701 E->isGlobalDelete(),
4702 E->isArrayForm(),
4703 move(Operand));
4704}
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregora16548e2009-08-11 05:31:07 +00004706template<typename Derived>
4707Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004708TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004709 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004710 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4711 if (Base.isInvalid())
4712 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregor678f90d2010-02-25 01:56:36 +00004714 Sema::TypeTy *ObjectTypePtr = 0;
4715 bool MayBePseudoDestructor = false;
4716 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4717 E->getOperatorLoc(),
4718 E->isArrow()? tok::arrow : tok::period,
4719 ObjectTypePtr,
4720 MayBePseudoDestructor);
4721 if (Base.isInvalid())
4722 return SemaRef.ExprError();
4723
4724 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004725 NestedNameSpecifier *Qualifier
4726 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00004727 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004728 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004729 if (E->getQualifier() && !Qualifier)
4730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregor678f90d2010-02-25 01:56:36 +00004732 PseudoDestructorTypeStorage Destroyed;
4733 if (E->getDestroyedTypeInfo()) {
4734 TypeSourceInfo *DestroyedTypeInfo
4735 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
4736 if (!DestroyedTypeInfo)
4737 return SemaRef.ExprError();
4738 Destroyed = DestroyedTypeInfo;
4739 } else if (ObjectType->isDependentType()) {
4740 // We aren't likely to be able to resolve the identifier down to a type
4741 // now anyway, so just retain the identifier.
4742 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
4743 E->getDestroyedTypeLoc());
4744 } else {
4745 // Look for a destructor known with the given name.
4746 CXXScopeSpec SS;
4747 if (Qualifier) {
4748 SS.setScopeRep(Qualifier);
4749 SS.setRange(E->getQualifierRange());
4750 }
4751
4752 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
4753 *E->getDestroyedTypeIdentifier(),
4754 E->getDestroyedTypeLoc(),
4755 /*Scope=*/0,
4756 SS, ObjectTypePtr,
4757 false);
4758 if (!T)
4759 return SemaRef.ExprError();
4760
4761 Destroyed
4762 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
4763 E->getDestroyedTypeLoc());
4764 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004765
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004766 TypeSourceInfo *ScopeTypeInfo = 0;
4767 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00004768 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
4769 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004770 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00004771 return SemaRef.ExprError();
4772 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004773
Douglas Gregorad8a3362009-09-04 17:36:40 +00004774 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4775 E->getOperatorLoc(),
4776 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00004777 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00004778 E->getQualifierRange(),
4779 ScopeTypeInfo,
4780 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00004781 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00004782 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00004783}
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregorad8a3362009-09-04 17:36:40 +00004785template<typename Derived>
4786Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004787TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004788 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004789 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4790
4791 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4792 Sema::LookupOrdinaryName);
4793
4794 // Transform all the decls.
4795 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4796 E = Old->decls_end(); I != E; ++I) {
4797 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00004798 if (!InstD) {
4799 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
4800 // This can happen because of dependent hiding.
4801 if (isa<UsingShadowDecl>(*I))
4802 continue;
4803 else
4804 return SemaRef.ExprError();
4805 }
John McCalle66edc12009-11-24 19:00:30 +00004806
4807 // Expand using declarations.
4808 if (isa<UsingDecl>(InstD)) {
4809 UsingDecl *UD = cast<UsingDecl>(InstD);
4810 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4811 E = UD->shadow_end(); I != E; ++I)
4812 R.addDecl(*I);
4813 continue;
4814 }
4815
4816 R.addDecl(InstD);
4817 }
4818
4819 // Resolve a kind, but don't do any further analysis. If it's
4820 // ambiguous, the callee needs to deal with it.
4821 R.resolveKind();
4822
4823 // Rebuild the nested-name qualifier, if present.
4824 CXXScopeSpec SS;
4825 NestedNameSpecifier *Qualifier = 0;
4826 if (Old->getQualifier()) {
4827 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004828 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00004829 if (!Qualifier)
4830 return SemaRef.ExprError();
4831
4832 SS.setScopeRep(Qualifier);
4833 SS.setRange(Old->getQualifierRange());
4834 }
4835
4836 // If we have no template arguments, it's a normal declaration name.
4837 if (!Old->hasExplicitTemplateArgs())
4838 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4839
4840 // If we have template arguments, rebuild them, then rebuild the
4841 // templateid expression.
4842 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4843 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4844 TemplateArgumentLoc Loc;
4845 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4846 return SemaRef.ExprError();
4847 TransArgs.addArgument(Loc);
4848 }
4849
4850 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4851 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004852}
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854template<typename Derived>
4855Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004856TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004857 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 QualType T = getDerived().TransformType(E->getQueriedType());
4860 if (T.isNull())
4861 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863 if (!getDerived().AlwaysRebuild() &&
4864 T == E->getQueriedType())
4865 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004866
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 // FIXME: Bad location information
4868 SourceLocation FakeLParenLoc
4869 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004870
4871 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004872 E->getLocStart(),
4873 /*FIXME:*/FakeLParenLoc,
4874 T,
4875 E->getLocEnd());
4876}
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregora16548e2009-08-11 05:31:07 +00004878template<typename Derived>
4879Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004880TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004881 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004882 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004883 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004884 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004885 if (!NNS)
4886 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004887
4888 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004889 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4890 if (!Name)
4891 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
John McCalle66edc12009-11-24 19:00:30 +00004893 if (!E->hasExplicitTemplateArgs()) {
4894 if (!getDerived().AlwaysRebuild() &&
4895 NNS == E->getQualifier() &&
4896 Name == E->getDeclName())
4897 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004898
John McCalle66edc12009-11-24 19:00:30 +00004899 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4900 E->getQualifierRange(),
4901 Name, E->getLocation(),
4902 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004903 }
John McCall6b51f282009-11-23 01:53:49 +00004904
4905 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004906 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004907 TemplateArgumentLoc Loc;
4908 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004909 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004910 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 }
4912
John McCalle66edc12009-11-24 19:00:30 +00004913 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4914 E->getQualifierRange(),
4915 Name, E->getLocation(),
4916 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004917}
4918
4919template<typename Derived>
4920Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004921TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00004922 // CXXConstructExprs are always implicit, so when we have a
4923 // 1-argument construction we just transform that argument.
4924 if (E->getNumArgs() == 1 ||
4925 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
4926 return getDerived().TransformExpr(E->getArg(0));
4927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4929
4930 QualType T = getDerived().TransformType(E->getType());
4931 if (T.isNull())
4932 return SemaRef.ExprError();
4933
4934 CXXConstructorDecl *Constructor
4935 = cast_or_null<CXXConstructorDecl>(
4936 getDerived().TransformDecl(E->getConstructor()));
4937 if (!Constructor)
4938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004939
Douglas Gregora16548e2009-08-11 05:31:07 +00004940 bool ArgumentChanged = false;
4941 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004942 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004943 ArgEnd = E->arg_end();
4944 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00004945 if (getDerived().DropCallArgument(*Arg)) {
4946 ArgumentChanged = true;
4947 break;
4948 }
4949
Douglas Gregora16548e2009-08-11 05:31:07 +00004950 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4951 if (TransArg.isInvalid())
4952 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004953
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4955 Args.push_back(TransArg.takeAs<Expr>());
4956 }
4957
4958 if (!getDerived().AlwaysRebuild() &&
4959 T == E->getType() &&
4960 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00004961 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00004962 // Mark the constructor as referenced.
4963 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00004964 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00004965 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00004966 }
Mike Stump11289f42009-09-09 15:08:12 +00004967
Douglas Gregordb121ba2009-12-14 16:27:04 +00004968 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
4969 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004970 move_arg(Args));
4971}
Mike Stump11289f42009-09-09 15:08:12 +00004972
Douglas Gregora16548e2009-08-11 05:31:07 +00004973/// \brief Transform a C++ temporary-binding expression.
4974///
Douglas Gregor363b1512009-12-24 18:51:59 +00004975/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
4976/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004977template<typename Derived>
4978Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004979TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00004980 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004981}
Mike Stump11289f42009-09-09 15:08:12 +00004982
Anders Carlssonba6c4372010-01-29 02:39:32 +00004983/// \brief Transform a C++ reference-binding expression.
4984///
4985/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
4986/// transform the subexpression and return that.
4987template<typename Derived>
4988Sema::OwningExprResult
4989TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
4990 return getDerived().TransformExpr(E->getSubExpr());
4991}
4992
Mike Stump11289f42009-09-09 15:08:12 +00004993/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004994/// be destroyed after the expression is evaluated.
4995///
Douglas Gregor363b1512009-12-24 18:51:59 +00004996/// Since CXXExprWithTemporaries nodes are implicitly generated, we
4997/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00004998template<typename Derived>
4999Sema::OwningExprResult
5000TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005001 CXXExprWithTemporaries *E) {
5002 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005template<typename Derived>
5006Sema::OwningExprResult
5007TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005008 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005009 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5010 QualType T = getDerived().TransformType(E->getType());
5011 if (T.isNull())
5012 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014 CXXConstructorDecl *Constructor
5015 = cast_or_null<CXXConstructorDecl>(
5016 getDerived().TransformDecl(E->getConstructor()));
5017 if (!Constructor)
5018 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 bool ArgumentChanged = false;
5021 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5022 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005023 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 ArgEnd = E->arg_end();
5025 Arg != ArgEnd; ++Arg) {
5026 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5027 if (TransArg.isInvalid())
5028 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005029
Douglas Gregora16548e2009-08-11 05:31:07 +00005030 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5031 Args.push_back((Expr *)TransArg.release());
5032 }
Mike Stump11289f42009-09-09 15:08:12 +00005033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 if (!getDerived().AlwaysRebuild() &&
5035 T == E->getType() &&
5036 Constructor == E->getConstructor() &&
5037 !ArgumentChanged)
5038 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005039
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 // FIXME: Bogus location information
5041 SourceLocation CommaLoc;
5042 if (Args.size() > 1) {
5043 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005044 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5046 }
5047 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5048 T,
5049 /*FIXME:*/E->getTypeBeginLoc(),
5050 move_arg(Args),
5051 &CommaLoc,
5052 E->getLocEnd());
5053}
Mike Stump11289f42009-09-09 15:08:12 +00005054
Douglas Gregora16548e2009-08-11 05:31:07 +00005055template<typename Derived>
5056Sema::OwningExprResult
5057TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005058 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5060 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5061 if (T.isNull())
5062 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005063
Douglas Gregora16548e2009-08-11 05:31:07 +00005064 bool ArgumentChanged = false;
5065 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5066 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5067 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5068 ArgEnd = E->arg_end();
5069 Arg != ArgEnd; ++Arg) {
5070 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5071 if (TransArg.isInvalid())
5072 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5075 FakeCommaLocs.push_back(
5076 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5077 Args.push_back(TransArg.takeAs<Expr>());
5078 }
Mike Stump11289f42009-09-09 15:08:12 +00005079
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 if (!getDerived().AlwaysRebuild() &&
5081 T == E->getTypeAsWritten() &&
5082 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005083 return SemaRef.Owned(E->Retain());
5084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 // FIXME: we're faking the locations of the commas
5086 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5087 T,
5088 E->getLParenLoc(),
5089 move_arg(Args),
5090 FakeCommaLocs.data(),
5091 E->getRParenLoc());
5092}
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094template<typename Derived>
5095Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005096TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005097 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005099 OwningExprResult Base(SemaRef, (Expr*) 0);
5100 Expr *OldBase;
5101 QualType BaseType;
5102 QualType ObjectType;
5103 if (!E->isImplicitAccess()) {
5104 OldBase = E->getBase();
5105 Base = getDerived().TransformExpr(OldBase);
5106 if (Base.isInvalid())
5107 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005108
John McCall2d74de92009-12-01 22:10:20 +00005109 // Start the member reference and compute the object's type.
5110 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005111 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005112 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5113 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005114 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005115 ObjectTy,
5116 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005117 if (Base.isInvalid())
5118 return SemaRef.ExprError();
5119
5120 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5121 BaseType = ((Expr*) Base.get())->getType();
5122 } else {
5123 OldBase = 0;
5124 BaseType = getDerived().TransformType(E->getBaseType());
5125 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5126 }
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005128 // Transform the first part of the nested-name-specifier that qualifies
5129 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005130 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005131 = getDerived().TransformFirstQualifierInScope(
5132 E->getFirstQualifierFoundInScope(),
5133 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005135 NestedNameSpecifier *Qualifier = 0;
5136 if (E->getQualifier()) {
5137 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5138 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005139 ObjectType,
5140 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005141 if (!Qualifier)
5142 return SemaRef.ExprError();
5143 }
Mike Stump11289f42009-09-09 15:08:12 +00005144
5145 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005146 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005147 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005148 if (!Name)
5149 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005150
John McCall2d74de92009-12-01 22:10:20 +00005151 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005152 // This is a reference to a member without an explicitly-specified
5153 // template argument list. Optimize for this common case.
5154 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005155 Base.get() == OldBase &&
5156 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005157 Qualifier == E->getQualifier() &&
5158 Name == E->getMember() &&
5159 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005160 return SemaRef.Owned(E->Retain());
5161
John McCall8cd78132009-11-19 22:55:06 +00005162 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005163 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005164 E->isArrow(),
5165 E->getOperatorLoc(),
5166 Qualifier,
5167 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005168 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005169 Name,
5170 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005171 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005172 }
5173
John McCall6b51f282009-11-23 01:53:49 +00005174 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005175 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005176 TemplateArgumentLoc Loc;
5177 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005178 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005179 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005180 }
Mike Stump11289f42009-09-09 15:08:12 +00005181
John McCall8cd78132009-11-19 22:55:06 +00005182 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005183 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005184 E->isArrow(),
5185 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005186 Qualifier,
5187 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005188 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005189 Name,
5190 E->getMemberLoc(),
5191 &TransArgs);
5192}
5193
5194template<typename Derived>
5195Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005196TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005197 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005198 OwningExprResult Base(SemaRef, (Expr*) 0);
5199 QualType BaseType;
5200 if (!Old->isImplicitAccess()) {
5201 Base = getDerived().TransformExpr(Old->getBase());
5202 if (Base.isInvalid())
5203 return SemaRef.ExprError();
5204 BaseType = ((Expr*) Base.get())->getType();
5205 } else {
5206 BaseType = getDerived().TransformType(Old->getBaseType());
5207 }
John McCall10eae182009-11-30 22:42:35 +00005208
5209 NestedNameSpecifier *Qualifier = 0;
5210 if (Old->getQualifier()) {
5211 Qualifier
5212 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005213 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005214 if (Qualifier == 0)
5215 return SemaRef.ExprError();
5216 }
5217
5218 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5219 Sema::LookupOrdinaryName);
5220
5221 // Transform all the decls.
5222 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5223 E = Old->decls_end(); I != E; ++I) {
5224 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
John McCall84d87672009-12-10 09:41:52 +00005225 if (!InstD) {
5226 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5227 // This can happen because of dependent hiding.
5228 if (isa<UsingShadowDecl>(*I))
5229 continue;
5230 else
5231 return SemaRef.ExprError();
5232 }
John McCall10eae182009-11-30 22:42:35 +00005233
5234 // Expand using declarations.
5235 if (isa<UsingDecl>(InstD)) {
5236 UsingDecl *UD = cast<UsingDecl>(InstD);
5237 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5238 E = UD->shadow_end(); I != E; ++I)
5239 R.addDecl(*I);
5240 continue;
5241 }
5242
5243 R.addDecl(InstD);
5244 }
5245
5246 R.resolveKind();
5247
5248 TemplateArgumentListInfo TransArgs;
5249 if (Old->hasExplicitTemplateArgs()) {
5250 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5251 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5252 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5253 TemplateArgumentLoc Loc;
5254 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5255 Loc))
5256 return SemaRef.ExprError();
5257 TransArgs.addArgument(Loc);
5258 }
5259 }
John McCall38836f02010-01-15 08:34:02 +00005260
5261 // FIXME: to do this check properly, we will need to preserve the
5262 // first-qualifier-in-scope here, just in case we had a dependent
5263 // base (and therefore couldn't do the check) and a
5264 // nested-name-qualifier (and therefore could do the lookup).
5265 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005266
5267 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005268 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005269 Old->getOperatorLoc(),
5270 Old->isArrow(),
5271 Qualifier,
5272 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005273 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005274 R,
5275 (Old->hasExplicitTemplateArgs()
5276 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005277}
5278
5279template<typename Derived>
5280Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005281TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005282 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005283}
5284
Mike Stump11289f42009-09-09 15:08:12 +00005285template<typename Derived>
5286Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005287TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005288 // FIXME: poor source location
5289 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
5290 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
5291 if (EncodedType.isNull())
5292 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (!getDerived().AlwaysRebuild() &&
5295 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00005296 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005297
5298 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
5299 EncodedType,
5300 E->getRParenLoc());
5301}
Mike Stump11289f42009-09-09 15:08:12 +00005302
Douglas Gregora16548e2009-08-11 05:31:07 +00005303template<typename Derived>
5304Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005305TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005306 // FIXME: Implement this!
5307 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005308 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005309}
5310
Mike Stump11289f42009-09-09 15:08:12 +00005311template<typename Derived>
5312Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005313TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005314 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005315}
5316
Mike Stump11289f42009-09-09 15:08:12 +00005317template<typename Derived>
5318Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005319TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005320 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00005321 = cast_or_null<ObjCProtocolDecl>(
5322 getDerived().TransformDecl(E->getProtocol()));
5323 if (!Protocol)
5324 return SemaRef.ExprError();
5325
5326 if (!getDerived().AlwaysRebuild() &&
5327 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005328 return SemaRef.Owned(E->Retain());
5329
Douglas Gregora16548e2009-08-11 05:31:07 +00005330 return getDerived().RebuildObjCProtocolExpr(Protocol,
5331 E->getAtLoc(),
5332 /*FIXME:*/E->getAtLoc(),
5333 /*FIXME:*/E->getAtLoc(),
5334 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005335
Douglas Gregora16548e2009-08-11 05:31:07 +00005336}
5337
Mike Stump11289f42009-09-09 15:08:12 +00005338template<typename Derived>
5339Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005340TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005341 // FIXME: Implement this!
5342 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005343 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005344}
5345
Mike Stump11289f42009-09-09 15:08:12 +00005346template<typename Derived>
5347Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005348TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005349 // FIXME: Implement this!
5350 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005351 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005352}
5353
Mike Stump11289f42009-09-09 15:08:12 +00005354template<typename Derived>
5355Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005356TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005357 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005358 // FIXME: Implement this!
5359 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005360 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005361}
5362
Mike Stump11289f42009-09-09 15:08:12 +00005363template<typename Derived>
5364Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005365TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 // FIXME: Implement this!
5367 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005368 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005369}
5370
Mike Stump11289f42009-09-09 15:08:12 +00005371template<typename Derived>
5372Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005373TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005374 // FIXME: Implement this!
5375 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005376 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005377}
5378
Mike Stump11289f42009-09-09 15:08:12 +00005379template<typename Derived>
5380Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005381TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 bool ArgumentChanged = false;
5383 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5384 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5385 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5386 if (SubExpr.isInvalid())
5387 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregora16548e2009-08-11 05:31:07 +00005389 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5390 SubExprs.push_back(SubExpr.takeAs<Expr>());
5391 }
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393 if (!getDerived().AlwaysRebuild() &&
5394 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005395 return SemaRef.Owned(E->Retain());
5396
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5398 move_arg(SubExprs),
5399 E->getRParenLoc());
5400}
5401
Mike Stump11289f42009-09-09 15:08:12 +00005402template<typename Derived>
5403Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005404TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005405 // FIXME: Implement this!
5406 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005407 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005408}
5409
Mike Stump11289f42009-09-09 15:08:12 +00005410template<typename Derived>
5411Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 // FIXME: Implement this!
5414 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005415 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005416}
Mike Stump11289f42009-09-09 15:08:12 +00005417
Douglas Gregora16548e2009-08-11 05:31:07 +00005418//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005419// Type reconstruction
5420//===----------------------------------------------------------------------===//
5421
Mike Stump11289f42009-09-09 15:08:12 +00005422template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005423QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5424 SourceLocation Star) {
5425 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005426 getDerived().getBaseEntity());
5427}
5428
Mike Stump11289f42009-09-09 15:08:12 +00005429template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005430QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5431 SourceLocation Star) {
5432 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005433 getDerived().getBaseEntity());
5434}
5435
Mike Stump11289f42009-09-09 15:08:12 +00005436template<typename Derived>
5437QualType
John McCall70dd5f62009-10-30 00:06:24 +00005438TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5439 bool WrittenAsLValue,
5440 SourceLocation Sigil) {
5441 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5442 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005443}
5444
5445template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005446QualType
John McCall70dd5f62009-10-30 00:06:24 +00005447TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5448 QualType ClassType,
5449 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005450 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005451 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005452}
5453
5454template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005455QualType
John McCall70dd5f62009-10-30 00:06:24 +00005456TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5457 SourceLocation Sigil) {
5458 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005459 getDerived().getBaseEntity());
5460}
5461
5462template<typename Derived>
5463QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005464TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5465 ArrayType::ArraySizeModifier SizeMod,
5466 const llvm::APInt *Size,
5467 Expr *SizeExpr,
5468 unsigned IndexTypeQuals,
5469 SourceRange BracketsRange) {
5470 if (SizeExpr || !Size)
5471 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5472 IndexTypeQuals, BracketsRange,
5473 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005474
5475 QualType Types[] = {
5476 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5477 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5478 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005479 };
5480 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5481 QualType SizeType;
5482 for (unsigned I = 0; I != NumTypes; ++I)
5483 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5484 SizeType = Types[I];
5485 break;
5486 }
Mike Stump11289f42009-09-09 15:08:12 +00005487
Douglas Gregord6ff3322009-08-04 16:50:30 +00005488 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005489 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005490 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005491 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005492}
Mike Stump11289f42009-09-09 15:08:12 +00005493
Douglas Gregord6ff3322009-08-04 16:50:30 +00005494template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005495QualType
5496TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005497 ArrayType::ArraySizeModifier SizeMod,
5498 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005499 unsigned IndexTypeQuals,
5500 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005501 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005502 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005503}
5504
5505template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005506QualType
Mike Stump11289f42009-09-09 15:08:12 +00005507TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005508 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005509 unsigned IndexTypeQuals,
5510 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005511 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005512 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005513}
Mike Stump11289f42009-09-09 15:08:12 +00005514
Douglas Gregord6ff3322009-08-04 16:50:30 +00005515template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005516QualType
5517TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005518 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005520 unsigned IndexTypeQuals,
5521 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005522 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005523 SizeExpr.takeAs<Expr>(),
5524 IndexTypeQuals, BracketsRange);
5525}
5526
5527template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005528QualType
5529TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005530 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005531 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005532 unsigned IndexTypeQuals,
5533 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005534 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005535 SizeExpr.takeAs<Expr>(),
5536 IndexTypeQuals, BracketsRange);
5537}
5538
5539template<typename Derived>
5540QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005541 unsigned NumElements,
5542 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005543 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005544 return SemaRef.Context.getVectorType(ElementType, NumElements,
5545 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005546}
Mike Stump11289f42009-09-09 15:08:12 +00005547
Douglas Gregord6ff3322009-08-04 16:50:30 +00005548template<typename Derived>
5549QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5550 unsigned NumElements,
5551 SourceLocation AttributeLoc) {
5552 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5553 NumElements, true);
5554 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005555 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005556 AttributeLoc);
5557 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5558 AttributeLoc);
5559}
Mike Stump11289f42009-09-09 15:08:12 +00005560
Douglas Gregord6ff3322009-08-04 16:50:30 +00005561template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005562QualType
5563TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005565 SourceLocation AttributeLoc) {
5566 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5567}
Mike Stump11289f42009-09-09 15:08:12 +00005568
Douglas Gregord6ff3322009-08-04 16:50:30 +00005569template<typename Derived>
5570QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005571 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005572 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005573 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005574 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005575 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005576 Quals,
5577 getDerived().getBaseLocation(),
5578 getDerived().getBaseEntity());
5579}
Mike Stump11289f42009-09-09 15:08:12 +00005580
Douglas Gregord6ff3322009-08-04 16:50:30 +00005581template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005582QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5583 return SemaRef.Context.getFunctionNoProtoType(T);
5584}
5585
5586template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005587QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5588 assert(D && "no decl found");
5589 if (D->isInvalidDecl()) return QualType();
5590
5591 TypeDecl *Ty;
5592 if (isa<UsingDecl>(D)) {
5593 UsingDecl *Using = cast<UsingDecl>(D);
5594 assert(Using->isTypeName() &&
5595 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5596
5597 // A valid resolved using typename decl points to exactly one type decl.
5598 assert(++Using->shadow_begin() == Using->shadow_end());
5599 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5600
5601 } else {
5602 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5603 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5604 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5605 }
5606
5607 return SemaRef.Context.getTypeDeclType(Ty);
5608}
5609
5610template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005611QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005612 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5613}
5614
5615template<typename Derived>
5616QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5617 return SemaRef.Context.getTypeOfType(Underlying);
5618}
5619
5620template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005621QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005622 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5623}
5624
5625template<typename Derived>
5626QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005627 TemplateName Template,
5628 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005629 const TemplateArgumentListInfo &TemplateArgs) {
5630 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005631}
Mike Stump11289f42009-09-09 15:08:12 +00005632
Douglas Gregor1135c352009-08-06 05:28:30 +00005633template<typename Derived>
5634NestedNameSpecifier *
5635TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5636 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005637 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005638 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005639 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005640 CXXScopeSpec SS;
5641 // FIXME: The source location information is all wrong.
5642 SS.setRange(Range);
5643 SS.setScopeRep(Prefix);
5644 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005645 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005646 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005647 ObjectType,
5648 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005649 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005650}
5651
5652template<typename Derived>
5653NestedNameSpecifier *
5654TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5655 SourceRange Range,
5656 NamespaceDecl *NS) {
5657 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5658}
5659
5660template<typename Derived>
5661NestedNameSpecifier *
5662TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5663 SourceRange Range,
5664 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005665 QualType T) {
5666 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005667 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005668 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005669 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5670 T.getTypePtr());
5671 }
Mike Stump11289f42009-09-09 15:08:12 +00005672
Douglas Gregor1135c352009-08-06 05:28:30 +00005673 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5674 return 0;
5675}
Mike Stump11289f42009-09-09 15:08:12 +00005676
Douglas Gregor71dc5092009-08-06 06:41:21 +00005677template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005678TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005679TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5680 bool TemplateKW,
5681 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005682 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005683 Template);
5684}
5685
5686template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005687TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005688TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005689 const IdentifierInfo &II,
5690 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005691 CXXScopeSpec SS;
5692 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005693 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005694 UnqualifiedId Name;
5695 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005696 return getSema().ActOnDependentTemplateName(
5697 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005698 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005699 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005700 ObjectType.getAsOpaquePtr(),
5701 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005702 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005703}
Mike Stump11289f42009-09-09 15:08:12 +00005704
Douglas Gregora16548e2009-08-11 05:31:07 +00005705template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005706TemplateName
5707TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5708 OverloadedOperatorKind Operator,
5709 QualType ObjectType) {
5710 CXXScopeSpec SS;
5711 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5712 SS.setScopeRep(Qualifier);
5713 UnqualifiedId Name;
5714 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5715 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5716 Operator, SymbolLocations);
5717 return getSema().ActOnDependentTemplateName(
5718 /*FIXME:*/getDerived().getBaseLocation(),
5719 SS,
5720 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005721 ObjectType.getAsOpaquePtr(),
5722 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005723 .template getAsVal<TemplateName>();
5724}
5725
5726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005727Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005728TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5729 SourceLocation OpLoc,
5730 ExprArg Callee,
5731 ExprArg First,
5732 ExprArg Second) {
5733 Expr *FirstExpr = (Expr *)First.get();
5734 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005735 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005736 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005737
Douglas Gregora16548e2009-08-11 05:31:07 +00005738 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005739 if (Op == OO_Subscript) {
5740 if (!FirstExpr->getType()->isOverloadableType() &&
5741 !SecondExpr->getType()->isOverloadableType())
5742 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005743 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005744 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005745 } else if (Op == OO_Arrow) {
5746 // -> is never a builtin operation.
5747 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005748 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005749 if (!FirstExpr->getType()->isOverloadableType()) {
5750 // The argument is not of overloadable type, so try to create a
5751 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005752 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005753 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5756 }
5757 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005758 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 !SecondExpr->getType()->isOverloadableType()) {
5760 // Neither of the arguments is an overloadable type, so try to
5761 // create a built-in binary operation.
5762 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005763 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5765 if (Result.isInvalid())
5766 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005767
Douglas Gregora16548e2009-08-11 05:31:07 +00005768 First.release();
5769 Second.release();
5770 return move(Result);
5771 }
5772 }
Mike Stump11289f42009-09-09 15:08:12 +00005773
5774 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005775 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00005776 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005777
John McCalld14a8642009-11-21 08:51:07 +00005778 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5779 assert(ULE->requiresADL());
5780
5781 // FIXME: Do we have to check
5782 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00005783 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00005784 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00005785 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00005786 }
Mike Stump11289f42009-09-09 15:08:12 +00005787
Douglas Gregora16548e2009-08-11 05:31:07 +00005788 // Add any functions found via argument-dependent lookup.
5789 Expr *Args[2] = { FirstExpr, SecondExpr };
5790 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 // Create the overloaded operator invocation for unary operators.
5793 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005794 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005795 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5796 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5797 }
Mike Stump11289f42009-09-09 15:08:12 +00005798
Sebastian Redladba46e2009-10-29 20:17:01 +00005799 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005800 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5801 OpLoc,
5802 move(First),
5803 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005806 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005808 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005809 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5810 if (Result.isInvalid())
5811 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813 First.release();
5814 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005815 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005816}
Mike Stump11289f42009-09-09 15:08:12 +00005817
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005818template<typename Derived>
5819Sema::OwningExprResult
5820TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
5821 SourceLocation OperatorLoc,
5822 bool isArrow,
5823 NestedNameSpecifier *Qualifier,
5824 SourceRange QualifierRange,
5825 TypeSourceInfo *ScopeType,
5826 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005827 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005828 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005829 CXXScopeSpec SS;
5830 if (Qualifier) {
5831 SS.setRange(QualifierRange);
5832 SS.setScopeRep(Qualifier);
5833 }
5834
5835 Expr *BaseE = (Expr *)Base.get();
5836 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00005837 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005838 (!isArrow && !BaseType->getAs<RecordType>()) ||
5839 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00005840 !BaseType->getAs<PointerType>()->getPointeeType()
5841 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005842 // This pseudo-destructor expression is still a pseudo-destructor.
5843 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
5844 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005845 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005846 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005847 /*FIXME?*/true);
5848 }
5849
Douglas Gregor678f90d2010-02-25 01:56:36 +00005850 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005851 DeclarationName Name
5852 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
5853 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
5854
5855 // FIXME: the ScopeType should be tacked onto SS.
5856
5857 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
5858 OperatorLoc, isArrow,
5859 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00005860 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005861 /*TemplateArgs*/ 0);
5862}
5863
Douglas Gregord6ff3322009-08-04 16:50:30 +00005864} // end namespace clang
5865
5866#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H