blob: e1d0bba4a4e8284cef5fe44dae341f3497a91a98 [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;
Mike Stump11289f42009-09-09 15:08:12 +000098
Douglas Gregord6ff3322009-08-04 16:50:30 +000099 /// \brief Initializes a new tree transformer.
100 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000101
Douglas Gregord6ff3322009-08-04 16:50:30 +0000102 /// \brief Retrieves a reference to the derived class.
103 Derived &getDerived() { return static_cast<Derived&>(*this); }
104
105 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000106 const Derived &getDerived() const {
107 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000108 }
109
110 /// \brief Retrieves a reference to the semantic analysis object used for
111 /// this tree transform.
112 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000113
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Whether the transformation should always rebuild AST nodes, even
115 /// if none of the children have changed.
116 ///
117 /// Subclasses may override this function to specify when the transformation
118 /// should rebuild all AST nodes.
119 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000120
Douglas Gregord6ff3322009-08-04 16:50:30 +0000121 /// \brief Returns the location of the entity being transformed, if that
122 /// information was not available elsewhere in the AST.
123 ///
Mike Stump11289f42009-09-09 15:08:12 +0000124 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// provide an alternative implementation that provides better location
126 /// information.
127 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000128
Douglas Gregord6ff3322009-08-04 16:50:30 +0000129 /// \brief Returns the name of the entity being transformed, if that
130 /// information was not available elsewhere in the AST.
131 ///
132 /// By default, returns an empty name. Subclasses can provide an alternative
133 /// implementation with a more precise name.
134 DeclarationName getBaseEntity() { return DeclarationName(); }
135
Douglas Gregora16548e2009-08-11 05:31:07 +0000136 /// \brief Sets the "base" location and entity when that
137 /// information is known based on another transformation.
138 ///
139 /// By default, the source location and entity are ignored. Subclasses can
140 /// override this function to provide a customized implementation.
141 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000142
Douglas Gregora16548e2009-08-11 05:31:07 +0000143 /// \brief RAII object that temporarily sets the base location and entity
144 /// used for reporting diagnostics in types.
145 class TemporaryBase {
146 TreeTransform &Self;
147 SourceLocation OldLocation;
148 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000149
Douglas Gregora16548e2009-08-11 05:31:07 +0000150 public:
151 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000152 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000153 OldLocation = Self.getDerived().getBaseLocation();
154 OldEntity = Self.getDerived().getBaseEntity();
155 Self.getDerived().setBase(Location, Entity);
156 }
Mike Stump11289f42009-09-09 15:08:12 +0000157
Douglas Gregora16548e2009-08-11 05:31:07 +0000158 ~TemporaryBase() {
159 Self.getDerived().setBase(OldLocation, OldEntity);
160 }
161 };
Mike Stump11289f42009-09-09 15:08:12 +0000162
163 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000164 /// transformed.
165 ///
166 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000167 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000168 /// not change. For example, template instantiation need not traverse
169 /// non-dependent types.
170 bool AlreadyTransformed(QualType T) {
171 return T.isNull();
172 }
173
174 /// \brief Transforms the given type into another type.
175 ///
John McCall550e0c22009-10-21 00:40:46 +0000176 /// By default, this routine transforms a type by creating a
177 /// DeclaratorInfo for it and delegating to the appropriate
178 /// function. This is expensive, but we don't mind, because
179 /// this method is deprecated anyway; all users should be
180 /// switched to storing DeclaratorInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000181 ///
182 /// \returns the transformed type.
183 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000184
John McCall550e0c22009-10-21 00:40:46 +0000185 /// \brief Transforms the given type-with-location into a new
186 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000187 ///
John McCall550e0c22009-10-21 00:40:46 +0000188 /// By default, this routine transforms a type by delegating to the
189 /// appropriate TransformXXXType to build a new type. Subclasses
190 /// may override this function (to take over all type
191 /// transformations) or some set of the TransformXXXType functions
192 /// to alter the transformation.
193 DeclaratorInfo *TransformType(DeclaratorInfo *DI);
194
195 /// \brief Transform the given type-with-location into a new
196 /// type, collecting location information in the given builder
197 /// as necessary.
198 ///
199 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000200
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000201 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000202 ///
Mike Stump11289f42009-09-09 15:08:12 +0000203 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000204 /// appropriate TransformXXXStmt function to transform a specific kind of
205 /// statement or the TransformExpr() function to transform an expression.
206 /// Subclasses may override this function to transform statements using some
207 /// other mechanism.
208 ///
209 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000210 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000211
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000212 /// \brief Transform the given expression.
213 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000214 /// By default, this routine transforms an expression by delegating to the
215 /// appropriate TransformXXXExpr function to build a new expression.
216 /// Subclasses may override this function to transform expressions using some
217 /// other mechanism.
218 ///
219 /// \returns the transformed expression.
220 OwningExprResult TransformExpr(Expr *E) {
221 return getDerived().TransformExpr(E, /*isAddressOfOperand=*/false);
222 }
223
224 /// \brief Transform the given expression.
225 ///
226 /// By default, this routine transforms an expression by delegating to the
227 /// appropriate TransformXXXExpr function to build a new expression.
228 /// Subclasses may override this function to transform expressions using some
229 /// other mechanism.
230 ///
231 /// \returns the transformed expression.
232 OwningExprResult TransformExpr(Expr *E, bool isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +0000233
Douglas Gregord6ff3322009-08-04 16:50:30 +0000234 /// \brief Transform the given declaration, which is referenced from a type
235 /// or expression.
236 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000237 /// By default, acts as the identity function on declarations. Subclasses
238 /// may override this function to provide alternate behavior.
239 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000240
241 /// \brief Transform the definition of the given declaration.
242 ///
Mike Stump11289f42009-09-09 15:08:12 +0000243 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000244 /// Subclasses may override this function to provide alternate behavior.
245 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000246
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000247 /// \brief Transform the given declaration, which was the first part of a
248 /// nested-name-specifier in a member access expression.
249 ///
250 /// This specific declaration transformation only applies to the first
251 /// identifier in a nested-name-specifier of a member access expression, e.g.,
252 /// the \c T in \c x->T::member
253 ///
254 /// By default, invokes TransformDecl() to transform the declaration.
255 /// Subclasses may override this function to provide alternate behavior.
256 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
257 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
258 }
259
Douglas Gregord6ff3322009-08-04 16:50:30 +0000260 /// \brief Transform the given nested-name-specifier.
261 ///
Mike Stump11289f42009-09-09 15:08:12 +0000262 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000263 /// nested-name-specifier. Subclasses may override this function to provide
264 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000265 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000266 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000267 QualType ObjectType = QualType(),
268 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000269
Douglas Gregorf816bd72009-09-03 22:13:48 +0000270 /// \brief Transform the given declaration name.
271 ///
272 /// By default, transforms the types of conversion function, constructor,
273 /// and destructor names and then (if needed) rebuilds the declaration name.
274 /// Identifiers and selectors are returned unmodified. Sublcasses may
275 /// override this function to provide alternate behavior.
276 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000277 SourceLocation Loc,
278 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000279
Douglas Gregord6ff3322009-08-04 16:50:30 +0000280 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000281 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000282 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000283 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000284 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000285 TemplateName TransformTemplateName(TemplateName Name,
286 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000287
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 /// \brief Transform the given template argument.
289 ///
Mike Stump11289f42009-09-09 15:08:12 +0000290 /// By default, this operation transforms the type, expression, or
291 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000292 /// new template argument from the transformed result. Subclasses may
293 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000294 ///
295 /// Returns true if there was an error.
296 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
297 TemplateArgumentLoc &Output);
298
299 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
300 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
301 TemplateArgumentLoc &ArgLoc);
302
303 /// \brief Fakes up a DeclaratorInfo for a type.
304 DeclaratorInfo *InventDeclaratorInfo(QualType T) {
305 return SemaRef.Context.getTrivialDeclaratorInfo(T,
306 getDerived().getBaseLocation());
307 }
Mike Stump11289f42009-09-09 15:08:12 +0000308
John McCall550e0c22009-10-21 00:40:46 +0000309#define ABSTRACT_TYPELOC(CLASS, PARENT)
310#define TYPELOC(CLASS, PARENT) \
311 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
312#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000313
John McCall70dd5f62009-10-30 00:06:24 +0000314 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
315
Douglas Gregorc59e5612009-10-19 22:04:39 +0000316 QualType
317 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
318 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000319
320 QualType
321 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
322 TemplateSpecializationTypeLoc TL,
323 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000324
Douglas Gregorebe10102009-08-20 07:17:43 +0000325 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000326
Douglas Gregorebe10102009-08-20 07:17:43 +0000327#define STMT(Node, Parent) \
328 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000329#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000330 OwningExprResult Transform##Node(Node *E, bool isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000331#define ABSTRACT_EXPR(Node, Parent)
332#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000333
Douglas Gregord6ff3322009-08-04 16:50:30 +0000334 /// \brief Build a new pointer type given its pointee type.
335 ///
336 /// By default, performs semantic analysis when building the pointer type.
337 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000338 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000339
340 /// \brief Build a new block pointer type given its pointee type.
341 ///
Mike Stump11289f42009-09-09 15:08:12 +0000342 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000343 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000344 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000345
John McCall70dd5f62009-10-30 00:06:24 +0000346 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 ///
John McCall70dd5f62009-10-30 00:06:24 +0000348 /// By default, performs semantic analysis when building the
349 /// reference type. Subclasses may override this routine to provide
350 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 ///
John McCall70dd5f62009-10-30 00:06:24 +0000352 /// \param LValue whether the type was written with an lvalue sigil
353 /// or an rvalue sigil.
354 QualType RebuildReferenceType(QualType ReferentType,
355 bool LValue,
356 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000357
Douglas Gregord6ff3322009-08-04 16:50:30 +0000358 /// \brief Build a new member pointer type given the pointee type and the
359 /// class type it refers into.
360 ///
361 /// By default, performs semantic analysis when building the member pointer
362 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000363 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
364 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000365
John McCall550e0c22009-10-21 00:40:46 +0000366 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000367 QualType RebuildObjCObjectPointerType(QualType PointeeType,
368 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000369
Douglas Gregord6ff3322009-08-04 16:50:30 +0000370 /// \brief Build a new array type given the element type, size
371 /// modifier, size of the array (if known), size expression, and index type
372 /// qualifiers.
373 ///
374 /// By default, performs semantic analysis when building the array type.
375 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000376 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000377 QualType RebuildArrayType(QualType ElementType,
378 ArrayType::ArraySizeModifier SizeMod,
379 const llvm::APInt *Size,
380 Expr *SizeExpr,
381 unsigned IndexTypeQuals,
382 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000383
Douglas Gregord6ff3322009-08-04 16:50:30 +0000384 /// \brief Build a new constant array type given the element type, size
385 /// modifier, (known) size of the array, and index type qualifiers.
386 ///
387 /// By default, performs semantic analysis when building the array type.
388 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000389 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000392 unsigned IndexTypeQuals,
393 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000394
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395 /// \brief Build a new incomplete array type given the element type, size
396 /// modifier, and index type qualifiers.
397 ///
398 /// By default, performs semantic analysis when building the array type.
399 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000400 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000401 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000404
Mike Stump11289f42009-09-09 15:08:12 +0000405 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406 /// size modifier, size expression, and index type qualifiers.
407 ///
408 /// By default, performs semantic analysis when building the array type.
409 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000410 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000411 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000412 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 unsigned IndexTypeQuals,
414 SourceRange BracketsRange);
415
Mike Stump11289f42009-09-09 15:08:12 +0000416 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// size modifier, size expression, and index type qualifiers.
418 ///
419 /// By default, performs semantic analysis when building the array type.
420 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000421 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000422 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000423 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000424 unsigned IndexTypeQuals,
425 SourceRange BracketsRange);
426
427 /// \brief Build a new vector type given the element type and
428 /// number of elements.
429 ///
430 /// By default, performs semantic analysis when building the vector type.
431 /// Subclasses may override this routine to provide different behavior.
432 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000433
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 /// \brief Build a new extended vector type given the element type and
435 /// number of elements.
436 ///
437 /// By default, performs semantic analysis when building the vector type.
438 /// Subclasses may override this routine to provide different behavior.
439 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
440 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000441
442 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000443 /// given the element type and number of elements.
444 ///
445 /// By default, performs semantic analysis when building the vector type.
446 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000447 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000448 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000449 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000450
Douglas Gregord6ff3322009-08-04 16:50:30 +0000451 /// \brief Build a new function type.
452 ///
453 /// By default, performs semantic analysis when building the function type.
454 /// Subclasses may override this routine to provide different behavior.
455 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000456 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000457 unsigned NumParamTypes,
458 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000459
John McCall550e0c22009-10-21 00:40:46 +0000460 /// \brief Build a new unprototyped function type.
461 QualType RebuildFunctionNoProtoType(QualType ResultType);
462
Douglas Gregord6ff3322009-08-04 16:50:30 +0000463 /// \brief Build a new typedef type.
464 QualType RebuildTypedefType(TypedefDecl *Typedef) {
465 return SemaRef.Context.getTypeDeclType(Typedef);
466 }
467
468 /// \brief Build a new class/struct/union type.
469 QualType RebuildRecordType(RecordDecl *Record) {
470 return SemaRef.Context.getTypeDeclType(Record);
471 }
472
473 /// \brief Build a new Enum type.
474 QualType RebuildEnumType(EnumDecl *Enum) {
475 return SemaRef.Context.getTypeDeclType(Enum);
476 }
John McCallfcc33b02009-09-05 00:15:47 +0000477
478 /// \brief Build a new elaborated type.
479 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
480 return SemaRef.Context.getElaboratedType(T, Tag);
481 }
Mike Stump11289f42009-09-09 15:08:12 +0000482
483 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000484 ///
485 /// By default, performs semantic analysis when building the typeof type.
486 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000487 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488
Mike Stump11289f42009-09-09 15:08:12 +0000489 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000490 ///
491 /// By default, builds a new TypeOfType with the given underlying type.
492 QualType RebuildTypeOfType(QualType Underlying);
493
Mike Stump11289f42009-09-09 15:08:12 +0000494 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000495 ///
496 /// By default, performs semantic analysis when building the decltype type.
497 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000498 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000499
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500 /// \brief Build a new template specialization type.
501 ///
502 /// By default, performs semantic analysis when building the template
503 /// specialization type. Subclasses may override this routine to provide
504 /// different behavior.
505 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000506 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000507 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000508
Douglas Gregord6ff3322009-08-04 16:50:30 +0000509 /// \brief Build a new qualified name type.
510 ///
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// By default, builds a new QualifiedNameType type from the
512 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000513 /// this routine to provide different behavior.
514 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
515 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000516 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517
518 /// \brief Build a new typename type that refers to a template-id.
519 ///
520 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000521 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000522 /// different behavior.
523 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
524 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000525 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000527
Douglas Gregord6ff3322009-08-04 16:50:30 +0000528 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to an identifier.
532 ///
533 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000534 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000536 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000537 const IdentifierInfo *Id,
538 SourceRange SR) {
539 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000540 }
Mike Stump11289f42009-09-09 15:08:12 +0000541
Douglas Gregor1135c352009-08-06 05:28:30 +0000542 /// \brief Build a new nested-name-specifier given the prefix and an
543 /// identifier that names the next step in the nested-name-specifier.
544 ///
545 /// By default, performs semantic analysis when building the new
546 /// nested-name-specifier. Subclasses may override this routine to provide
547 /// different behavior.
548 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
549 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000550 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000551 QualType ObjectType,
552 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000553
554 /// \brief Build a new nested-name-specifier given the prefix and the
555 /// namespace named in the next step in the nested-name-specifier.
556 ///
557 /// By default, performs semantic analysis when building the new
558 /// nested-name-specifier. Subclasses may override this routine to provide
559 /// different behavior.
560 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
561 SourceRange Range,
562 NamespaceDecl *NS);
563
564 /// \brief Build a new nested-name-specifier given the prefix and the
565 /// type named in the next step in the nested-name-specifier.
566 ///
567 /// By default, performs semantic analysis when building the new
568 /// nested-name-specifier. Subclasses may override this routine to provide
569 /// different behavior.
570 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
571 SourceRange Range,
572 bool TemplateKW,
573 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000574
575 /// \brief Build a new template name given a nested name specifier, a flag
576 /// indicating whether the "template" keyword was provided, and the template
577 /// that the template name refers to.
578 ///
579 /// By default, builds the new template name directly. Subclasses may override
580 /// this routine to provide different behavior.
581 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
582 bool TemplateKW,
583 TemplateDecl *Template);
584
Douglas Gregor71dc5092009-08-06 06:41:21 +0000585 /// \brief Build a new template name given a nested name specifier and the
586 /// name that is referred to as a template.
587 ///
588 /// By default, performs semantic analysis to determine whether the name can
589 /// be resolved to a specific template, then builds the appropriate kind of
590 /// template name. Subclasses may override this routine to provide different
591 /// behavior.
592 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000593 const IdentifierInfo &II,
594 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000595
Douglas Gregor71395fa2009-11-04 00:56:37 +0000596 /// \brief Build a new template name given a nested name specifier and the
597 /// overloaded operator name that is referred to as a template.
598 ///
599 /// By default, performs semantic analysis to determine whether the name can
600 /// be resolved to a specific template, then builds the appropriate kind of
601 /// template name. Subclasses may override this routine to provide different
602 /// behavior.
603 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
604 OverloadedOperatorKind Operator,
605 QualType ObjectType);
606
Douglas Gregorebe10102009-08-20 07:17:43 +0000607 /// \brief Build a new compound statement.
608 ///
609 /// By default, performs semantic analysis to build the new statement.
610 /// Subclasses may override this routine to provide different behavior.
611 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
612 MultiStmtArg Statements,
613 SourceLocation RBraceLoc,
614 bool IsStmtExpr) {
615 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
616 IsStmtExpr);
617 }
618
619 /// \brief Build a new case statement.
620 ///
621 /// By default, performs semantic analysis to build the new statement.
622 /// Subclasses may override this routine to provide different behavior.
623 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
624 ExprArg LHS,
625 SourceLocation EllipsisLoc,
626 ExprArg RHS,
627 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000628 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000629 ColonLoc);
630 }
Mike Stump11289f42009-09-09 15:08:12 +0000631
Douglas Gregorebe10102009-08-20 07:17:43 +0000632 /// \brief Attach the body to a new case statement.
633 ///
634 /// By default, performs semantic analysis to build the new statement.
635 /// Subclasses may override this routine to provide different behavior.
636 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
637 getSema().ActOnCaseStmtBody(S.get(), move(Body));
638 return move(S);
639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregorebe10102009-08-20 07:17:43 +0000641 /// \brief Build a new default statement.
642 ///
643 /// By default, performs semantic analysis to build the new statement.
644 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000645 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000646 SourceLocation ColonLoc,
647 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000648 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000649 /*CurScope=*/0);
650 }
Mike Stump11289f42009-09-09 15:08:12 +0000651
Douglas Gregorebe10102009-08-20 07:17:43 +0000652 /// \brief Build a new label statement.
653 ///
654 /// By default, performs semantic analysis to build the new statement.
655 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000656 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000657 IdentifierInfo *Id,
658 SourceLocation ColonLoc,
659 StmtArg SubStmt) {
660 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
661 }
Mike Stump11289f42009-09-09 15:08:12 +0000662
Douglas Gregorebe10102009-08-20 07:17:43 +0000663 /// \brief Build a new "if" statement.
664 ///
665 /// By default, performs semantic analysis to build the new statement.
666 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000667 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
668 StmtArg Then, SourceLocation ElseLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000669 StmtArg Else) {
670 return getSema().ActOnIfStmt(IfLoc, Cond, move(Then), ElseLoc, move(Else));
671 }
Mike Stump11289f42009-09-09 15:08:12 +0000672
Douglas Gregorebe10102009-08-20 07:17:43 +0000673 /// \brief Start building a new switch statement.
674 ///
675 /// By default, performs semantic analysis to build the new statement.
676 /// Subclasses may override this routine to provide different behavior.
677 OwningStmtResult RebuildSwitchStmtStart(ExprArg Cond) {
678 return getSema().ActOnStartOfSwitchStmt(move(Cond));
679 }
Mike Stump11289f42009-09-09 15:08:12 +0000680
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 /// \brief Attach the body to the switch statement.
682 ///
683 /// By default, performs semantic analysis to build the new statement.
684 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000685 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000686 StmtArg Switch, StmtArg Body) {
687 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
688 move(Body));
689 }
690
691 /// \brief Build a new while statement.
692 ///
693 /// By default, performs semantic analysis to build the new statement.
694 /// Subclasses may override this routine to provide different behavior.
695 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
696 Sema::FullExprArg Cond,
697 StmtArg Body) {
698 return getSema().ActOnWhileStmt(WhileLoc, Cond, move(Body));
699 }
Mike Stump11289f42009-09-09 15:08:12 +0000700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new do-while statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
706 SourceLocation WhileLoc,
707 SourceLocation LParenLoc,
708 ExprArg Cond,
709 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000710 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000711 move(Cond), RParenLoc);
712 }
713
714 /// \brief Build a new for statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000718 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000719 SourceLocation LParenLoc,
720 StmtArg Init, ExprArg Cond, ExprArg Inc,
721 SourceLocation RParenLoc, StmtArg Body) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), move(Cond),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 move(Inc), RParenLoc, move(Body));
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Build a new goto statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
731 SourceLocation LabelLoc,
732 LabelStmt *Label) {
733 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
734 }
735
736 /// \brief Build a new indirect goto statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
740 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
741 SourceLocation StarLoc,
742 ExprArg Target) {
743 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new return statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
750 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
751 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000752
Douglas Gregorebe10102009-08-20 07:17:43 +0000753 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
754 }
Mike Stump11289f42009-09-09 15:08:12 +0000755
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 /// \brief Build a new declaration statement.
757 ///
758 /// By default, performs semantic analysis to build the new statement.
759 /// Subclasses may override this routine to provide different behavior.
760 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000761 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 SourceLocation EndLoc) {
763 return getSema().Owned(
764 new (getSema().Context) DeclStmt(
765 DeclGroupRef::Create(getSema().Context,
766 Decls, NumDecls),
767 StartLoc, EndLoc));
768 }
Mike Stump11289f42009-09-09 15:08:12 +0000769
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 /// \brief Build a new C++ exception declaration.
771 ///
772 /// By default, performs semantic analysis to build the new decaration.
773 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000774 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 DeclaratorInfo *Declarator,
776 IdentifierInfo *Name,
777 SourceLocation Loc,
778 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000779 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000780 TypeRange);
781 }
782
783 /// \brief Build a new C++ catch 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 RebuildCXXCatchStmt(SourceLocation CatchLoc,
788 VarDecl *ExceptionDecl,
789 StmtArg Handler) {
790 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000791 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 Handler.takeAs<Stmt>()));
793 }
Mike Stump11289f42009-09-09 15:08:12 +0000794
Douglas Gregorebe10102009-08-20 07:17:43 +0000795 /// \brief Build a new C++ try statement.
796 ///
797 /// By default, performs semantic analysis to build the new statement.
798 /// Subclasses may override this routine to provide different behavior.
799 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
800 StmtArg TryBlock,
801 MultiStmtArg Handlers) {
802 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
803 }
Mike Stump11289f42009-09-09 15:08:12 +0000804
Douglas Gregora16548e2009-08-11 05:31:07 +0000805 /// \brief Build a new expression that references a declaration.
806 ///
807 /// By default, performs semantic analysis to build the new expression.
808 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000809 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
810 LookupResult &R,
811 bool RequiresADL) {
812 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
813 }
814
815
816 /// \brief Build a new expression that references a declaration.
817 ///
818 /// By default, performs semantic analysis to build the new expression.
819 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000820 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
821 SourceRange QualifierRange,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000822 NamedDecl *ND, SourceLocation Loc,
823 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000824 CXXScopeSpec SS;
825 SS.setScopeRep(Qualifier);
826 SS.setRange(QualifierRange);
Douglas Gregora16548e2009-08-11 05:31:07 +0000827 return getSema().BuildDeclarationNameExpr(Loc, ND,
828 /*FIXME:*/false,
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000829 &SS,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +0000830 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +0000831 }
Mike Stump11289f42009-09-09 15:08:12 +0000832
Douglas Gregora16548e2009-08-11 05:31:07 +0000833 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000834 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000835 /// By default, performs semantic analysis to build the new expression.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
838 SourceLocation RParen) {
839 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
840 }
841
Douglas Gregorad8a3362009-09-04 17:36:40 +0000842 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000843 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000844 /// By default, performs semantic analysis to build the new expression.
845 /// Subclasses may override this routine to provide different behavior.
846 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
847 SourceLocation OperatorLoc,
848 bool isArrow,
849 SourceLocation DestroyedTypeLoc,
850 QualType DestroyedType,
851 NestedNameSpecifier *Qualifier,
852 SourceRange QualifierRange) {
853 CXXScopeSpec SS;
854 if (Qualifier) {
855 SS.setRange(QualifierRange);
856 SS.setScopeRep(Qualifier);
857 }
858
Mike Stump11289f42009-09-09 15:08:12 +0000859 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000860 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
861 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000862
863 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
Douglas Gregorad8a3362009-09-04 17:36:40 +0000864 OperatorLoc,
865 isArrow? tok::arrow : tok::period,
866 DestroyedTypeLoc,
867 Name,
868 Sema::DeclPtrTy::make((Decl *)0),
869 &SS);
Mike Stump11289f42009-09-09 15:08:12 +0000870 }
871
Douglas Gregora16548e2009-08-11 05:31:07 +0000872 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000873 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000874 /// By default, performs semantic analysis to build the new expression.
875 /// Subclasses may override this routine to provide different behavior.
876 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
877 UnaryOperator::Opcode Opc,
878 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000879 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000880 }
Mike Stump11289f42009-09-09 15:08:12 +0000881
Douglas Gregora16548e2009-08-11 05:31:07 +0000882 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000883 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000884 /// By default, performs semantic analysis to build the new expression.
885 /// Subclasses may override this routine to provide different behavior.
John McCall4c98fd82009-11-04 07:28:41 +0000886 OwningExprResult RebuildSizeOfAlignOf(DeclaratorInfo *DInfo,
887 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000888 bool isSizeOf, SourceRange R) {
John McCall4c98fd82009-11-04 07:28:41 +0000889 return getSema().CreateSizeOfAlignOfExpr(DInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000890 }
891
Mike Stump11289f42009-09-09 15:08:12 +0000892 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000893 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000894 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000895 /// By default, performs semantic analysis to build the new expression.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
898 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000899 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000900 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
901 OpLoc, isSizeOf, R);
902 if (Result.isInvalid())
903 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000904
Douglas Gregora16548e2009-08-11 05:31:07 +0000905 SubExpr.release();
906 return move(Result);
907 }
Mike Stump11289f42009-09-09 15:08:12 +0000908
Douglas Gregora16548e2009-08-11 05:31:07 +0000909 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000910 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000911 /// By default, performs semantic analysis to build the new expression.
912 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000913 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000914 SourceLocation LBracketLoc,
915 ExprArg RHS,
916 SourceLocation RBracketLoc) {
917 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000918 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000919 RBracketLoc);
920 }
921
922 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000923 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000924 /// By default, performs semantic analysis to build the new expression.
925 /// Subclasses may override this routine to provide different behavior.
926 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
927 MultiExprArg Args,
928 SourceLocation *CommaLocs,
929 SourceLocation RParenLoc) {
930 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
931 move(Args), CommaLocs, RParenLoc);
932 }
933
934 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000935 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000936 /// By default, performs semantic analysis to build the new expression.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000939 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000940 NestedNameSpecifier *Qualifier,
941 SourceRange QualifierRange,
942 SourceLocation MemberLoc,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000943 NamedDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000944 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000945 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000946 if (!Member->getDeclName()) {
947 // We have a reference to an unnamed field.
948 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000949
950 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000951 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
952 Member, MemberLoc,
953 cast<FieldDecl>(Member)->getType());
954 return getSema().Owned(ME);
955 }
Mike Stump11289f42009-09-09 15:08:12 +0000956
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000957 CXXScopeSpec SS;
958 if (Qualifier) {
959 SS.setRange(QualifierRange);
960 SS.setScopeRep(Qualifier);
961 }
962
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000963 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000964 isArrow? tok::arrow : tok::period,
965 MemberLoc,
Douglas Gregorf14b46f2009-08-31 20:00:26 +0000966 Member->getDeclName(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000967 ExplicitTemplateArgs,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000968 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000969 &SS,
970 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +0000971 }
Mike Stump11289f42009-09-09 15:08:12 +0000972
Douglas Gregora16548e2009-08-11 05:31:07 +0000973 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000974 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000975 /// By default, performs semantic analysis to build the new expression.
976 /// Subclasses may override this routine to provide different behavior.
977 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
978 BinaryOperator::Opcode Opc,
979 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000980 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
981 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000982 }
983
984 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000985 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000986 /// By default, performs semantic analysis to build the new expression.
987 /// Subclasses may override this routine to provide different behavior.
988 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
989 SourceLocation QuestionLoc,
990 ExprArg LHS,
991 SourceLocation ColonLoc,
992 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000993 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000994 move(LHS), move(RHS));
995 }
996
997 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000998 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000999 /// By default, builds a new implicit cast without any semantic analysis.
1000 /// Subclasses may override this routine to provide different behavior.
1001 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
1002 ExprArg SubExpr, bool isLvalue) {
1003 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +00001004 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +00001005 (Expr *)SubExpr.release(),
1006 isLvalue);
1007 return getSema().Owned(ICE);
1008 }
1009
1010 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001011 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001012 /// By default, performs semantic analysis to build the new expression.
1013 /// Subclasses may override this routine to provide different behavior.
1014 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1015 QualType ExplicitTy,
1016 SourceLocation RParenLoc,
1017 ExprArg SubExpr) {
1018 return getSema().ActOnCastExpr(/*Scope=*/0,
1019 LParenLoc,
1020 ExplicitTy.getAsOpaquePtr(),
1021 RParenLoc,
1022 move(SubExpr));
1023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1030 QualType T,
1031 SourceLocation RParenLoc,
1032 ExprArg Init) {
1033 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1034 RParenLoc, move(Init));
1035 }
Mike Stump11289f42009-09-09 15:08:12 +00001036
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001041 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 SourceLocation OpLoc,
1043 SourceLocation AccessorLoc,
1044 IdentifierInfo &Accessor) {
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001045 return getSema().BuildMemberReferenceExpr(/*Scope=*/0, move(Base), OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 tok::period, AccessorLoc,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001047 DeclarationName(&Accessor),
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0));
1049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Douglas Gregora16548e2009-08-11 05:31:07 +00001051 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001052 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 /// By default, performs semantic analysis to build the new expression.
1054 /// Subclasses may override this routine to provide different behavior.
1055 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1056 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001057 SourceLocation RBraceLoc,
1058 QualType ResultTy) {
1059 OwningExprResult Result
1060 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1061 if (Result.isInvalid() || ResultTy->isDependentType())
1062 return move(Result);
1063
1064 // Patch in the result type we were given, which may have been computed
1065 // when the initial InitListExpr was built.
1066 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1067 ILE->setType(ResultTy);
1068 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
1075 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1076 MultiExprArg ArrayExprs,
1077 SourceLocation EqualOrColonLoc,
1078 bool GNUSyntax,
1079 ExprArg Init) {
1080 OwningExprResult Result
1081 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1082 move(Init));
1083 if (Result.isInvalid())
1084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 ArrayExprs.release();
1087 return move(Result);
1088 }
Mike Stump11289f42009-09-09 15:08:12 +00001089
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001091 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001092 /// By default, builds the implicit value initialization without performing
1093 /// any semantic analysis. Subclasses may override this routine to provide
1094 /// different behavior.
1095 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1096 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1097 }
Mike Stump11289f42009-09-09 15:08:12 +00001098
Douglas Gregora16548e2009-08-11 05:31:07 +00001099 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 /// By default, performs semantic analysis to build the new expression.
1102 /// Subclasses may override this routine to provide different behavior.
1103 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1104 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001105 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001106 RParenLoc);
1107 }
1108
1109 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001110 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// By default, performs semantic analysis to build the new expression.
1112 /// Subclasses may override this routine to provide different behavior.
1113 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1114 MultiExprArg SubExprs,
1115 SourceLocation RParenLoc) {
1116 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
1117 }
Mike Stump11289f42009-09-09 15:08:12 +00001118
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001120 ///
1121 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 /// rather than attempting to map the label statement itself.
1123 /// Subclasses may override this routine to provide different behavior.
1124 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1125 SourceLocation LabelLoc,
1126 LabelStmt *Label) {
1127 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001131 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 /// By default, performs semantic analysis to build the new expression.
1133 /// Subclasses may override this routine to provide different behavior.
1134 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1135 StmtArg SubStmt,
1136 SourceLocation RParenLoc) {
1137 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1138 }
Mike Stump11289f42009-09-09 15:08:12 +00001139
Douglas Gregora16548e2009-08-11 05:31:07 +00001140 /// \brief Build a new __builtin_types_compatible_p expression.
1141 ///
1142 /// By default, performs semantic analysis to build the new expression.
1143 /// Subclasses may override this routine to provide different behavior.
1144 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1145 QualType T1, QualType T2,
1146 SourceLocation RParenLoc) {
1147 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1148 T1.getAsOpaquePtr(),
1149 T2.getAsOpaquePtr(),
1150 RParenLoc);
1151 }
Mike Stump11289f42009-09-09 15:08:12 +00001152
Douglas Gregora16548e2009-08-11 05:31:07 +00001153 /// \brief Build a new __builtin_choose_expr expression.
1154 ///
1155 /// By default, performs semantic analysis to build the new expression.
1156 /// Subclasses may override this routine to provide different behavior.
1157 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1158 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1159 SourceLocation RParenLoc) {
1160 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1161 move(Cond), move(LHS), move(RHS),
1162 RParenLoc);
1163 }
Mike Stump11289f42009-09-09 15:08:12 +00001164
Douglas Gregora16548e2009-08-11 05:31:07 +00001165 /// \brief Build a new overloaded operator call expression.
1166 ///
1167 /// By default, performs semantic analysis to build the new expression.
1168 /// The semantic analysis provides the behavior of template instantiation,
1169 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001170 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 /// argument-dependent lookup, etc. Subclasses may override this routine to
1172 /// provide different behavior.
1173 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1174 SourceLocation OpLoc,
1175 ExprArg Callee,
1176 ExprArg First,
1177 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001178
1179 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001180 /// reinterpret_cast.
1181 ///
1182 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001183 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001184 /// Subclasses may override this routine to provide different behavior.
1185 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1186 Stmt::StmtClass Class,
1187 SourceLocation LAngleLoc,
1188 QualType T,
1189 SourceLocation RAngleLoc,
1190 SourceLocation LParenLoc,
1191 ExprArg SubExpr,
1192 SourceLocation RParenLoc) {
1193 switch (Class) {
1194 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001195 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1196 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 move(SubExpr), RParenLoc);
1198
1199 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001200 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1201 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001203
Douglas Gregora16548e2009-08-11 05:31:07 +00001204 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001205 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1206 RAngleLoc, LParenLoc,
1207 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001208 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001209
Douglas Gregora16548e2009-08-11 05:31:07 +00001210 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001211 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1212 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 default:
1216 assert(false && "Invalid C++ named cast");
1217 break;
1218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 return getSema().ExprError();
1221 }
Mike Stump11289f42009-09-09 15:08:12 +00001222
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// \brief Build a new C++ static_cast expression.
1224 ///
1225 /// By default, performs semantic analysis to build the new expression.
1226 /// Subclasses may override this routine to provide different behavior.
1227 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1228 SourceLocation LAngleLoc,
1229 QualType T,
1230 SourceLocation RAngleLoc,
1231 SourceLocation LParenLoc,
1232 ExprArg SubExpr,
1233 SourceLocation RParenLoc) {
1234 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001235 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 LParenLoc, move(SubExpr), RParenLoc);
1237 }
1238
1239 /// \brief Build a new C++ dynamic_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 RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1244 SourceLocation LAngleLoc,
1245 QualType T,
1246 SourceLocation RAngleLoc,
1247 SourceLocation LParenLoc,
1248 ExprArg SubExpr,
1249 SourceLocation RParenLoc) {
1250 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001251 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001252 LParenLoc, move(SubExpr), RParenLoc);
1253 }
1254
1255 /// \brief Build a new C++ reinterpret_cast expression.
1256 ///
1257 /// By default, performs semantic analysis to build the new expression.
1258 /// Subclasses may override this routine to provide different behavior.
1259 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1260 SourceLocation LAngleLoc,
1261 QualType T,
1262 SourceLocation RAngleLoc,
1263 SourceLocation LParenLoc,
1264 ExprArg SubExpr,
1265 SourceLocation RParenLoc) {
1266 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1267 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1268 LParenLoc, move(SubExpr), RParenLoc);
1269 }
1270
1271 /// \brief Build a new C++ const_cast expression.
1272 ///
1273 /// By default, performs semantic analysis to build the new expression.
1274 /// Subclasses may override this routine to provide different behavior.
1275 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1276 SourceLocation LAngleLoc,
1277 QualType T,
1278 SourceLocation RAngleLoc,
1279 SourceLocation LParenLoc,
1280 ExprArg SubExpr,
1281 SourceLocation RParenLoc) {
1282 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001283 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001284 LParenLoc, move(SubExpr), RParenLoc);
1285 }
Mike Stump11289f42009-09-09 15:08:12 +00001286
Douglas Gregora16548e2009-08-11 05:31:07 +00001287 /// \brief Build a new C++ functional-style cast expression.
1288 ///
1289 /// By default, performs semantic analysis to build the new expression.
1290 /// Subclasses may override this routine to provide different behavior.
1291 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1292 QualType T,
1293 SourceLocation LParenLoc,
1294 ExprArg SubExpr,
1295 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001296 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1298 T.getAsOpaquePtr(),
1299 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001300 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001301 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 RParenLoc);
1303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregora16548e2009-08-11 05:31:07 +00001305 /// \brief Build a new C++ typeid(type) expression.
1306 ///
1307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
1309 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1310 SourceLocation LParenLoc,
1311 QualType T,
1312 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001313 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001314 T.getAsOpaquePtr(), RParenLoc);
1315 }
Mike Stump11289f42009-09-09 15:08:12 +00001316
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// \brief Build a new C++ typeid(expr) expression.
1318 ///
1319 /// By default, performs semantic analysis to build the new expression.
1320 /// Subclasses may override this routine to provide different behavior.
1321 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1322 SourceLocation LParenLoc,
1323 ExprArg Operand,
1324 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001325 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1327 RParenLoc);
1328 if (Result.isInvalid())
1329 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001330
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1332 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001333 }
1334
Douglas Gregora16548e2009-08-11 05:31:07 +00001335 /// \brief Build a new C++ "this" expression.
1336 ///
1337 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001338 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001339 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001340 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 QualType ThisType) {
1342 return getSema().Owned(
1343 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1344 }
1345
1346 /// \brief Build a new C++ throw expression.
1347 ///
1348 /// By default, performs semantic analysis to build the new expression.
1349 /// Subclasses may override this routine to provide different behavior.
1350 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1351 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1352 }
1353
1354 /// \brief Build a new C++ default-argument expression.
1355 ///
1356 /// By default, builds a new default-argument expression, which does not
1357 /// require any semantic analysis. Subclasses may override this routine to
1358 /// provide different behavior.
1359 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001360 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 }
1362
1363 /// \brief Build a new C++ zero-initialization expression.
1364 ///
1365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001367 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 SourceLocation LParenLoc,
1369 QualType T,
1370 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001371 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1372 T.getAsOpaquePtr(), LParenLoc,
1373 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 0, RParenLoc);
1375 }
Mike Stump11289f42009-09-09 15:08:12 +00001376
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 /// \brief Build a new C++ conditional declaration expression.
1378 ///
1379 /// By default, performs semantic analysis to build the new expression.
1380 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001381 OwningExprResult RebuildCXXConditionDeclExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 SourceLocation EqLoc,
1383 VarDecl *Var) {
1384 return SemaRef.Owned(new (SemaRef.Context) CXXConditionDeclExpr(StartLoc,
1385 EqLoc,
1386 Var));
1387 }
Mike Stump11289f42009-09-09 15:08:12 +00001388
Douglas Gregora16548e2009-08-11 05:31:07 +00001389 /// \brief Build a new C++ "new" expression.
1390 ///
1391 /// By default, performs semantic analysis to build the new expression.
1392 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001393 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 bool UseGlobal,
1395 SourceLocation PlacementLParen,
1396 MultiExprArg PlacementArgs,
1397 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001398 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 QualType AllocType,
1400 SourceLocation TypeLoc,
1401 SourceRange TypeRange,
1402 ExprArg ArraySize,
1403 SourceLocation ConstructorLParen,
1404 MultiExprArg ConstructorArgs,
1405 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001406 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001407 PlacementLParen,
1408 move(PlacementArgs),
1409 PlacementRParen,
1410 ParenTypeId,
1411 AllocType,
1412 TypeLoc,
1413 TypeRange,
1414 move(ArraySize),
1415 ConstructorLParen,
1416 move(ConstructorArgs),
1417 ConstructorRParen);
1418 }
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 /// \brief Build a new C++ "delete" expression.
1421 ///
1422 /// By default, performs semantic analysis to build the new expression.
1423 /// Subclasses may override this routine to provide different behavior.
1424 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1425 bool IsGlobalDelete,
1426 bool IsArrayForm,
1427 ExprArg Operand) {
1428 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1429 move(Operand));
1430 }
Mike Stump11289f42009-09-09 15:08:12 +00001431
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 /// \brief Build a new unary type trait 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 RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1437 SourceLocation StartLoc,
1438 SourceLocation LParenLoc,
1439 QualType T,
1440 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001441 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 T.getAsOpaquePtr(), RParenLoc);
1443 }
1444
Mike Stump11289f42009-09-09 15:08:12 +00001445 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 /// expression.
1447 ///
1448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001450 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 SourceRange QualifierRange,
1452 DeclarationName Name,
1453 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001454 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001455 CXXScopeSpec SS;
1456 SS.setRange(QualifierRange);
1457 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001458
1459 if (TemplateArgs)
1460 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1461 *TemplateArgs);
1462
1463 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 }
1465
1466 /// \brief Build a new template-id expression.
1467 ///
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001470 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1471 LookupResult &R,
1472 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001473 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001474 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 }
1476
1477 /// \brief Build a new object-construction expression.
1478 ///
1479 /// By default, performs semantic analysis to build the new expression.
1480 /// Subclasses may override this routine to provide different behavior.
1481 OwningExprResult RebuildCXXConstructExpr(QualType T,
1482 CXXConstructorDecl *Constructor,
1483 bool IsElidable,
1484 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001485 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1486 SourceLocation(),
1487 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001488 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001489 }
1490
1491 /// \brief Build a new object-construction expression.
1492 ///
1493 /// By default, performs semantic analysis to build the new expression.
1494 /// Subclasses may override this routine to provide different behavior.
1495 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1496 QualType T,
1497 SourceLocation LParenLoc,
1498 MultiExprArg Args,
1499 SourceLocation *Commas,
1500 SourceLocation RParenLoc) {
1501 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1502 T.getAsOpaquePtr(),
1503 LParenLoc,
1504 move(Args),
1505 Commas,
1506 RParenLoc);
1507 }
1508
1509 /// \brief Build a new object-construction expression.
1510 ///
1511 /// By default, performs semantic analysis to build the new expression.
1512 /// Subclasses may override this routine to provide different behavior.
1513 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1514 QualType T,
1515 SourceLocation LParenLoc,
1516 MultiExprArg Args,
1517 SourceLocation *Commas,
1518 SourceLocation RParenLoc) {
1519 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1520 /*FIXME*/LParenLoc),
1521 T.getAsOpaquePtr(),
1522 LParenLoc,
1523 move(Args),
1524 Commas,
1525 RParenLoc);
1526 }
Mike Stump11289f42009-09-09 15:08:12 +00001527
Douglas Gregora16548e2009-08-11 05:31:07 +00001528 /// \brief Build a new member reference expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001532 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 bool IsArrow,
1534 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001535 NestedNameSpecifier *Qualifier,
1536 SourceRange QualifierRange,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001538 SourceLocation MemberLoc,
1539 NamedDecl *FirstQualifierInScope) {
Douglas Gregor2168a9f2009-08-11 15:56:57 +00001540 OwningExprResult Base = move(BaseE);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001544 SS.setRange(QualifierRange);
1545 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001546
Douglas Gregor308047d2009-09-09 00:23:06 +00001547 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 move(Base), OperatorLoc, OpKind,
Douglas Gregorf14b46f2009-08-31 20:00:26 +00001549 MemberLoc,
1550 Name,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001551 /*FIXME?*/Sema::DeclPtrTy::make((Decl*)0),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001552 &SS,
1553 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001554 }
1555
Douglas Gregor308047d2009-09-09 00:23:06 +00001556 /// \brief Build a new member reference expression with explicit template
1557 /// arguments.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001561 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
Douglas Gregor308047d2009-09-09 00:23:06 +00001562 bool IsArrow,
1563 SourceLocation OperatorLoc,
1564 NestedNameSpecifier *Qualifier,
1565 SourceRange QualifierRange,
1566 TemplateName Template,
1567 SourceLocation TemplateNameLoc,
1568 NamedDecl *FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00001569 const TemplateArgumentListInfo &TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001570 OwningExprResult Base = move(BaseE);
1571 tok::TokenKind OpKind = IsArrow? tok::arrow : tok::period;
Mike Stump11289f42009-09-09 15:08:12 +00001572
Douglas Gregor308047d2009-09-09 00:23:06 +00001573 CXXScopeSpec SS;
1574 SS.setRange(QualifierRange);
1575 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregor308047d2009-09-09 00:23:06 +00001577 // FIXME: We're going to end up looking up the template based on its name,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001578 // twice! Also, duplicates part of Sema::BuildMemberAccessExpr.
Douglas Gregor308047d2009-09-09 00:23:06 +00001579 DeclarationName Name;
1580 if (TemplateDecl *ActualTemplate = Template.getAsTemplateDecl())
1581 Name = ActualTemplate->getDeclName();
Mike Stump11289f42009-09-09 15:08:12 +00001582 else if (OverloadedFunctionDecl *Ovl
Douglas Gregor308047d2009-09-09 00:23:06 +00001583 = Template.getAsOverloadedFunctionDecl())
1584 Name = Ovl->getDeclName();
Douglas Gregor71395fa2009-11-04 00:56:37 +00001585 else {
1586 DependentTemplateName *DTN = Template.getAsDependentTemplateName();
1587 if (DTN->isIdentifier())
1588 Name = DTN->getIdentifier();
1589 else
1590 Name = SemaRef.Context.DeclarationNames.getCXXOperatorName(
1591 DTN->getOperator());
1592 }
John McCall6b51f282009-11-23 01:53:49 +00001593 return SemaRef.BuildMemberReferenceExpr(/*Scope=*/0, move(Base),
1594 OperatorLoc, OpKind,
1595 TemplateNameLoc, Name,
1596 &TemplateArgs,
1597 Sema::DeclPtrTy(), &SS);
Douglas Gregor308047d2009-09-09 00:23:06 +00001598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new Objective-C @encode expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1605 QualType T,
1606 SourceLocation RParenLoc) {
1607 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1608 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001609 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001610
1611 /// \brief Build a new Objective-C protocol expression.
1612 ///
1613 /// By default, performs semantic analysis to build the new expression.
1614 /// Subclasses may override this routine to provide different behavior.
1615 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1616 SourceLocation AtLoc,
1617 SourceLocation ProtoLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation RParenLoc) {
1620 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1621 Protocol->getIdentifier(),
1622 AtLoc,
1623 ProtoLoc,
1624 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001625 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 }
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 /// \brief Build a new shuffle vector expression.
1629 ///
1630 /// By default, performs semantic analysis to build the new expression.
1631 /// Subclasses may override this routine to provide different behavior.
1632 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1633 MultiExprArg SubExprs,
1634 SourceLocation RParenLoc) {
1635 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001636 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1638 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1639 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1640 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 // Build a reference to the __builtin_shufflevector builtin
1643 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001644 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001646 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001648
1649 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 unsigned NumSubExprs = SubExprs.size();
1651 Expr **Subs = (Expr **)SubExprs.release();
1652 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1653 Subs, NumSubExprs,
1654 Builtin->getResultType(),
1655 RParenLoc);
1656 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001657
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 // Type-check the __builtin_shufflevector expression.
1659 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1660 if (Result.isInvalid())
1661 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001662
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001664 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001666};
Douglas Gregora16548e2009-08-11 05:31:07 +00001667
Douglas Gregorebe10102009-08-20 07:17:43 +00001668template<typename Derived>
1669Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1670 if (!S)
1671 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregorebe10102009-08-20 07:17:43 +00001673 switch (S->getStmtClass()) {
1674 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001675
Douglas Gregorebe10102009-08-20 07:17:43 +00001676 // Transform individual statement nodes
1677#define STMT(Node, Parent) \
1678 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1679#define EXPR(Node, Parent)
1680#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001681
Douglas Gregorebe10102009-08-20 07:17:43 +00001682 // Transform expressions by calling TransformExpr.
1683#define STMT(Node, Parent)
1684#define EXPR(Node, Parent) case Stmt::Node##Class:
1685#include "clang/AST/StmtNodes.def"
1686 {
1687 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1688 if (E.isInvalid())
1689 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001690
Douglas Gregor07eae022009-11-13 18:34:26 +00001691 return getSema().ActOnExprStmt(getSema().FullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001692 }
Mike Stump11289f42009-09-09 15:08:12 +00001693 }
1694
Douglas Gregorebe10102009-08-20 07:17:43 +00001695 return SemaRef.Owned(S->Retain());
1696}
Mike Stump11289f42009-09-09 15:08:12 +00001697
1698
Douglas Gregore922c772009-08-04 22:27:00 +00001699template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00001700Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E,
1701 bool isAddressOfOperand) {
1702 if (!E)
1703 return SemaRef.Owned(E);
1704
1705 switch (E->getStmtClass()) {
1706 case Stmt::NoStmtClass: break;
1707#define STMT(Node, Parent) case Stmt::Node##Class: break;
1708#define EXPR(Node, Parent) \
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00001709 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E), \
1710 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001711#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001712 }
1713
Douglas Gregora16548e2009-08-11 05:31:07 +00001714 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001715}
1716
1717template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001718NestedNameSpecifier *
1719TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001721 QualType ObjectType,
1722 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001723 if (!NNS)
1724 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001725
Douglas Gregorebe10102009-08-20 07:17:43 +00001726 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 NestedNameSpecifier *Prefix = NNS->getPrefix();
1728 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001729 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001730 ObjectType,
1731 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001732 if (!Prefix)
1733 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001734
1735 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001736 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001737 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001738 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001739 }
Mike Stump11289f42009-09-09 15:08:12 +00001740
Douglas Gregor1135c352009-08-06 05:28:30 +00001741 switch (NNS->getKind()) {
1742 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001743 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001744 "Identifier nested-name-specifier with no prefix or object type");
1745 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1746 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001747 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001748
1749 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001750 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001751 ObjectType,
1752 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001753
Douglas Gregor1135c352009-08-06 05:28:30 +00001754 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001755 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001756 = cast_or_null<NamespaceDecl>(
1757 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001758 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001759 Prefix == NNS->getPrefix() &&
1760 NS == NNS->getAsNamespace())
1761 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001762
Douglas Gregor1135c352009-08-06 05:28:30 +00001763 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1764 }
Mike Stump11289f42009-09-09 15:08:12 +00001765
Douglas Gregor1135c352009-08-06 05:28:30 +00001766 case NestedNameSpecifier::Global:
1767 // There is no meaningful transformation that one could perform on the
1768 // global scope.
1769 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001770
Douglas Gregor1135c352009-08-06 05:28:30 +00001771 case NestedNameSpecifier::TypeSpecWithTemplate:
1772 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001773 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001774 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001775 if (T.isNull())
1776 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001777
Douglas Gregor1135c352009-08-06 05:28:30 +00001778 if (!getDerived().AlwaysRebuild() &&
1779 Prefix == NNS->getPrefix() &&
1780 T == QualType(NNS->getAsType(), 0))
1781 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001782
1783 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1784 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001785 T);
1786 }
1787 }
Mike Stump11289f42009-09-09 15:08:12 +00001788
Douglas Gregor1135c352009-08-06 05:28:30 +00001789 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001790 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001791}
1792
1793template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001794DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001795TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001796 SourceLocation Loc,
1797 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001798 if (!Name)
1799 return Name;
1800
1801 switch (Name.getNameKind()) {
1802 case DeclarationName::Identifier:
1803 case DeclarationName::ObjCZeroArgSelector:
1804 case DeclarationName::ObjCOneArgSelector:
1805 case DeclarationName::ObjCMultiArgSelector:
1806 case DeclarationName::CXXOperatorName:
1807 case DeclarationName::CXXUsingDirective:
1808 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregorf816bd72009-09-03 22:13:48 +00001810 case DeclarationName::CXXConstructorName:
1811 case DeclarationName::CXXDestructorName:
1812 case DeclarationName::CXXConversionFunctionName: {
1813 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001814 QualType T;
1815 if (!ObjectType.isNull() &&
1816 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1817 TemplateSpecializationType *SpecType
1818 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1819 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1820 } else
1821 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001822 if (T.isNull())
1823 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001824
Douglas Gregorf816bd72009-09-03 22:13:48 +00001825 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001826 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001827 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829 }
1830
Douglas Gregorf816bd72009-09-03 22:13:48 +00001831 return DeclarationName();
1832}
1833
1834template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001835TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001836TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1837 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001838 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001839 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001840 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1841 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1842 if (!NNS)
1843 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001844
Douglas Gregor71dc5092009-08-06 06:41:21 +00001845 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001846 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1848 if (!TransTemplate)
1849 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001850
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 if (!getDerived().AlwaysRebuild() &&
1852 NNS == QTN->getQualifier() &&
1853 TransTemplate == Template)
1854 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001855
Douglas Gregor71dc5092009-08-06 06:41:21 +00001856 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1857 TransTemplate);
1858 }
Mike Stump11289f42009-09-09 15:08:12 +00001859
John McCalle66edc12009-11-24 19:00:30 +00001860 // These should be getting filtered out before they make it into the AST.
1861 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001862 }
Mike Stump11289f42009-09-09 15:08:12 +00001863
Douglas Gregor71dc5092009-08-06 06:41:21 +00001864 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001865 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001866 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1867 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001868 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001869 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001870
Douglas Gregor71dc5092009-08-06 06:41:21 +00001871 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001872 NNS == DTN->getQualifier() &&
1873 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001874 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001875
Douglas Gregor71395fa2009-11-04 00:56:37 +00001876 if (DTN->isIdentifier())
1877 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1878 ObjectType);
1879
1880 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1881 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001882 }
Mike Stump11289f42009-09-09 15:08:12 +00001883
Douglas Gregor71dc5092009-08-06 06:41:21 +00001884 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001885 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001886 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1887 if (!TransTemplate)
1888 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001889
Douglas Gregor71dc5092009-08-06 06:41:21 +00001890 if (!getDerived().AlwaysRebuild() &&
1891 TransTemplate == Template)
1892 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001893
Douglas Gregor71dc5092009-08-06 06:41:21 +00001894 return TemplateName(TransTemplate);
1895 }
Mike Stump11289f42009-09-09 15:08:12 +00001896
John McCalle66edc12009-11-24 19:00:30 +00001897 // These should be getting filtered out before they reach the AST.
1898 assert(false && "overloaded function decl survived to here");
1899 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001900}
1901
1902template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001903void TreeTransform<Derived>::InventTemplateArgumentLoc(
1904 const TemplateArgument &Arg,
1905 TemplateArgumentLoc &Output) {
1906 SourceLocation Loc = getDerived().getBaseLocation();
1907 switch (Arg.getKind()) {
1908 case TemplateArgument::Null:
1909 llvm::llvm_unreachable("null template argument in TreeTransform");
1910 break;
1911
1912 case TemplateArgument::Type:
1913 Output = TemplateArgumentLoc(Arg,
1914 SemaRef.Context.getTrivialDeclaratorInfo(Arg.getAsType(), Loc));
1915
1916 break;
1917
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001918 case TemplateArgument::Template:
1919 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1920 break;
1921
John McCall0ad16662009-10-29 08:12:44 +00001922 case TemplateArgument::Expression:
1923 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1924 break;
1925
1926 case TemplateArgument::Declaration:
1927 case TemplateArgument::Integral:
1928 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001929 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001930 break;
1931 }
1932}
1933
1934template<typename Derived>
1935bool TreeTransform<Derived>::TransformTemplateArgument(
1936 const TemplateArgumentLoc &Input,
1937 TemplateArgumentLoc &Output) {
1938 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001939 switch (Arg.getKind()) {
1940 case TemplateArgument::Null:
1941 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001942 Output = Input;
1943 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregore922c772009-08-04 22:27:00 +00001945 case TemplateArgument::Type: {
John McCall0ad16662009-10-29 08:12:44 +00001946 DeclaratorInfo *DI = Input.getSourceDeclaratorInfo();
1947 if (DI == NULL)
1948 DI = InventDeclaratorInfo(Input.getArgument().getAsType());
1949
1950 DI = getDerived().TransformType(DI);
1951 if (!DI) return true;
1952
1953 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1954 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001955 }
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregore922c772009-08-04 22:27:00 +00001957 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001958 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001959 DeclarationName Name;
1960 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1961 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001962 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001963 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001964 if (!D) return true;
1965
John McCall0d07eb32009-10-29 18:45:58 +00001966 Expr *SourceExpr = Input.getSourceDeclExpression();
1967 if (SourceExpr) {
1968 EnterExpressionEvaluationContext Unevaluated(getSema(),
1969 Action::Unevaluated);
1970 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1971 if (E.isInvalid())
1972 SourceExpr = NULL;
1973 else {
1974 SourceExpr = E.takeAs<Expr>();
1975 SourceExpr->Retain();
1976 }
1977 }
1978
1979 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001980 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001981 }
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001983 case TemplateArgument::Template: {
1984 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1985 TemplateName Template
1986 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1987 if (Template.isNull())
1988 return true;
1989
1990 Output = TemplateArgumentLoc(TemplateArgument(Template),
1991 Input.getTemplateQualifierRange(),
1992 Input.getTemplateNameLoc());
1993 return false;
1994 }
1995
Douglas Gregore922c772009-08-04 22:27:00 +00001996 case TemplateArgument::Expression: {
1997 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001998 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001999 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002000
John McCall0ad16662009-10-29 08:12:44 +00002001 Expr *InputExpr = Input.getSourceExpression();
2002 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2003
2004 Sema::OwningExprResult E
2005 = getDerived().TransformExpr(InputExpr);
2006 if (E.isInvalid()) return true;
2007
2008 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002009 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002010 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2011 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002012 }
Mike Stump11289f42009-09-09 15:08:12 +00002013
Douglas Gregore922c772009-08-04 22:27:00 +00002014 case TemplateArgument::Pack: {
2015 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2016 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002017 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002018 AEnd = Arg.pack_end();
2019 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002020
John McCall0ad16662009-10-29 08:12:44 +00002021 // FIXME: preserve source information here when we start
2022 // caring about parameter packs.
2023
John McCall0d07eb32009-10-29 18:45:58 +00002024 TemplateArgumentLoc InputArg;
2025 TemplateArgumentLoc OutputArg;
2026 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2027 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002028 return true;
2029
John McCall0d07eb32009-10-29 18:45:58 +00002030 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002031 }
2032 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002033 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002034 true);
John McCall0d07eb32009-10-29 18:45:58 +00002035 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002036 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002037 }
2038 }
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregore922c772009-08-04 22:27:00 +00002040 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002041 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002042}
2043
Douglas Gregord6ff3322009-08-04 16:50:30 +00002044//===----------------------------------------------------------------------===//
2045// Type transformation
2046//===----------------------------------------------------------------------===//
2047
2048template<typename Derived>
2049QualType TreeTransform<Derived>::TransformType(QualType T) {
2050 if (getDerived().AlreadyTransformed(T))
2051 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002052
John McCall550e0c22009-10-21 00:40:46 +00002053 // Temporary workaround. All of these transformations should
2054 // eventually turn into transformations on TypeLocs.
2055 DeclaratorInfo *DI = getSema().Context.CreateDeclaratorInfo(T);
John McCallde889892009-10-21 00:44:26 +00002056 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002057
2058 DeclaratorInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002059
John McCall550e0c22009-10-21 00:40:46 +00002060 if (!NewDI)
2061 return QualType();
2062
2063 return NewDI->getType();
2064}
2065
2066template<typename Derived>
2067DeclaratorInfo *TreeTransform<Derived>::TransformType(DeclaratorInfo *DI) {
2068 if (getDerived().AlreadyTransformed(DI->getType()))
2069 return DI;
2070
2071 TypeLocBuilder TLB;
2072
2073 TypeLoc TL = DI->getTypeLoc();
2074 TLB.reserve(TL.getFullDataSize());
2075
2076 QualType Result = getDerived().TransformType(TLB, TL);
2077 if (Result.isNull())
2078 return 0;
2079
2080 return TLB.getDeclaratorInfo(SemaRef.Context, Result);
2081}
2082
2083template<typename Derived>
2084QualType
2085TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2086 switch (T.getTypeLocClass()) {
2087#define ABSTRACT_TYPELOC(CLASS, PARENT)
2088#define TYPELOC(CLASS, PARENT) \
2089 case TypeLoc::CLASS: \
2090 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2091#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002092 }
Mike Stump11289f42009-09-09 15:08:12 +00002093
John McCall550e0c22009-10-21 00:40:46 +00002094 llvm::llvm_unreachable("unhandled type loc!");
2095 return QualType();
2096}
2097
2098/// FIXME: By default, this routine adds type qualifiers only to types
2099/// that can have qualifiers, and silently suppresses those qualifiers
2100/// that are not permitted (e.g., qualifiers on reference or function
2101/// types). This is the right thing for template instantiation, but
2102/// probably not for other clients.
2103template<typename Derived>
2104QualType
2105TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2106 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002107 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002108
2109 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2110 if (Result.isNull())
2111 return QualType();
2112
2113 // Silently suppress qualifiers if the result type can't be qualified.
2114 // FIXME: this is the right thing for template instantiation, but
2115 // probably not for other clients.
2116 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002117 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002118
John McCall550e0c22009-10-21 00:40:46 +00002119 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2120
2121 TLB.push<QualifiedTypeLoc>(Result);
2122
2123 // No location information to preserve.
2124
2125 return Result;
2126}
2127
2128template <class TyLoc> static inline
2129QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2130 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2131 NewT.setNameLoc(T.getNameLoc());
2132 return T.getType();
2133}
2134
2135// Ugly metaprogramming macros because I couldn't be bothered to make
2136// the equivalent template version work.
2137#define TransformPointerLikeType(TypeClass) do { \
2138 QualType PointeeType \
2139 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2140 if (PointeeType.isNull()) \
2141 return QualType(); \
2142 \
2143 QualType Result = TL.getType(); \
2144 if (getDerived().AlwaysRebuild() || \
2145 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002146 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2147 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002148 if (Result.isNull()) \
2149 return QualType(); \
2150 } \
2151 \
2152 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2153 NewT.setSigilLoc(TL.getSigilLoc()); \
2154 \
2155 return Result; \
2156} while(0)
2157
John McCall550e0c22009-10-21 00:40:46 +00002158template<typename Derived>
2159QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2160 BuiltinTypeLoc T) {
2161 return TransformTypeSpecType(TLB, T);
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>
Mike Stump11289f42009-09-09 15:08:12 +00002165QualType
John McCall550e0c22009-10-21 00:40:46 +00002166TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2167 FixedWidthIntTypeLoc T) {
2168 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002169}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002170
Douglas Gregord6ff3322009-08-04 16:50:30 +00002171template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002172QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2173 ComplexTypeLoc T) {
2174 // FIXME: recurse?
2175 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002176}
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregord6ff3322009-08-04 16:50:30 +00002178template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002179QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2180 PointerTypeLoc TL) {
2181 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002182}
Mike Stump11289f42009-09-09 15:08:12 +00002183
2184template<typename Derived>
2185QualType
John McCall550e0c22009-10-21 00:40:46 +00002186TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2187 BlockPointerTypeLoc TL) {
2188 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002189}
2190
John McCall70dd5f62009-10-30 00:06:24 +00002191/// Transforms a reference type. Note that somewhat paradoxically we
2192/// don't care whether the type itself is an l-value type or an r-value
2193/// type; we only care if the type was *written* as an l-value type
2194/// or an r-value type.
2195template<typename Derived>
2196QualType
2197TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2198 ReferenceTypeLoc TL) {
2199 const ReferenceType *T = TL.getTypePtr();
2200
2201 // Note that this works with the pointee-as-written.
2202 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2203 if (PointeeType.isNull())
2204 return QualType();
2205
2206 QualType Result = TL.getType();
2207 if (getDerived().AlwaysRebuild() ||
2208 PointeeType != T->getPointeeTypeAsWritten()) {
2209 Result = getDerived().RebuildReferenceType(PointeeType,
2210 T->isSpelledAsLValue(),
2211 TL.getSigilLoc());
2212 if (Result.isNull())
2213 return QualType();
2214 }
2215
2216 // r-value references can be rebuilt as l-value references.
2217 ReferenceTypeLoc NewTL;
2218 if (isa<LValueReferenceType>(Result))
2219 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2220 else
2221 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2222 NewTL.setSigilLoc(TL.getSigilLoc());
2223
2224 return Result;
2225}
2226
Mike Stump11289f42009-09-09 15:08:12 +00002227template<typename Derived>
2228QualType
John McCall550e0c22009-10-21 00:40:46 +00002229TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2230 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002231 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002232}
2233
Mike Stump11289f42009-09-09 15:08:12 +00002234template<typename Derived>
2235QualType
John McCall550e0c22009-10-21 00:40:46 +00002236TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2237 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002238 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002239}
Mike Stump11289f42009-09-09 15:08:12 +00002240
Douglas Gregord6ff3322009-08-04 16:50:30 +00002241template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002242QualType
John McCall550e0c22009-10-21 00:40:46 +00002243TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2244 MemberPointerTypeLoc TL) {
2245 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,
2276 ConstantArrayTypeLoc TL) {
2277 ConstantArrayType *T = TL.getTypePtr();
2278 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002279 if (ElementType.isNull())
2280 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002281
John McCall550e0c22009-10-21 00:40:46 +00002282 QualType Result = TL.getType();
2283 if (getDerived().AlwaysRebuild() ||
2284 ElementType != T->getElementType()) {
2285 Result = getDerived().RebuildConstantArrayType(ElementType,
2286 T->getSizeModifier(),
2287 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002288 T->getIndexTypeCVRQualifiers(),
2289 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002290 if (Result.isNull())
2291 return QualType();
2292 }
2293
2294 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2295 NewTL.setLBracketLoc(TL.getLBracketLoc());
2296 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002297
John McCall550e0c22009-10-21 00:40:46 +00002298 Expr *Size = TL.getSizeExpr();
2299 if (Size) {
2300 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2301 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2302 }
2303 NewTL.setSizeExpr(Size);
2304
2305 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002306}
Mike Stump11289f42009-09-09 15:08:12 +00002307
Douglas Gregord6ff3322009-08-04 16:50:30 +00002308template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002309QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002310 TypeLocBuilder &TLB,
2311 IncompleteArrayTypeLoc TL) {
2312 IncompleteArrayType *T = TL.getTypePtr();
2313 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002314 if (ElementType.isNull())
2315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCall550e0c22009-10-21 00:40:46 +00002317 QualType Result = TL.getType();
2318 if (getDerived().AlwaysRebuild() ||
2319 ElementType != T->getElementType()) {
2320 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002321 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002322 T->getIndexTypeCVRQualifiers(),
2323 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002324 if (Result.isNull())
2325 return QualType();
2326 }
2327
2328 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2329 NewTL.setLBracketLoc(TL.getLBracketLoc());
2330 NewTL.setRBracketLoc(TL.getRBracketLoc());
2331 NewTL.setSizeExpr(0);
2332
2333 return Result;
2334}
2335
2336template<typename Derived>
2337QualType
2338TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2339 VariableArrayTypeLoc TL) {
2340 VariableArrayType *T = TL.getTypePtr();
2341 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2342 if (ElementType.isNull())
2343 return QualType();
2344
2345 // Array bounds are not potentially evaluated contexts
2346 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2347
2348 Sema::OwningExprResult SizeResult
2349 = getDerived().TransformExpr(T->getSizeExpr());
2350 if (SizeResult.isInvalid())
2351 return QualType();
2352
2353 Expr *Size = static_cast<Expr*>(SizeResult.get());
2354
2355 QualType Result = TL.getType();
2356 if (getDerived().AlwaysRebuild() ||
2357 ElementType != T->getElementType() ||
2358 Size != T->getSizeExpr()) {
2359 Result = getDerived().RebuildVariableArrayType(ElementType,
2360 T->getSizeModifier(),
2361 move(SizeResult),
2362 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002363 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002364 if (Result.isNull())
2365 return QualType();
2366 }
2367 else SizeResult.take();
2368
2369 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2370 NewTL.setLBracketLoc(TL.getLBracketLoc());
2371 NewTL.setRBracketLoc(TL.getRBracketLoc());
2372 NewTL.setSizeExpr(Size);
2373
2374 return Result;
2375}
2376
2377template<typename Derived>
2378QualType
2379TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2380 DependentSizedArrayTypeLoc TL) {
2381 DependentSizedArrayType *T = TL.getTypePtr();
2382 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2383 if (ElementType.isNull())
2384 return QualType();
2385
2386 // Array bounds are not potentially evaluated contexts
2387 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2388
2389 Sema::OwningExprResult SizeResult
2390 = getDerived().TransformExpr(T->getSizeExpr());
2391 if (SizeResult.isInvalid())
2392 return QualType();
2393
2394 Expr *Size = static_cast<Expr*>(SizeResult.get());
2395
2396 QualType Result = TL.getType();
2397 if (getDerived().AlwaysRebuild() ||
2398 ElementType != T->getElementType() ||
2399 Size != T->getSizeExpr()) {
2400 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2401 T->getSizeModifier(),
2402 move(SizeResult),
2403 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002404 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002405 if (Result.isNull())
2406 return QualType();
2407 }
2408 else SizeResult.take();
2409
2410 // We might have any sort of array type now, but fortunately they
2411 // all have the same location layout.
2412 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2413 NewTL.setLBracketLoc(TL.getLBracketLoc());
2414 NewTL.setRBracketLoc(TL.getRBracketLoc());
2415 NewTL.setSizeExpr(Size);
2416
2417 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002418}
Mike Stump11289f42009-09-09 15:08:12 +00002419
2420template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002421QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002422 TypeLocBuilder &TLB,
2423 DependentSizedExtVectorTypeLoc TL) {
2424 DependentSizedExtVectorType *T = TL.getTypePtr();
2425
2426 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002427 QualType ElementType = getDerived().TransformType(T->getElementType());
2428 if (ElementType.isNull())
2429 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002430
Douglas Gregore922c772009-08-04 22:27:00 +00002431 // Vector sizes are not potentially evaluated contexts
2432 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2433
Douglas Gregord6ff3322009-08-04 16:50:30 +00002434 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2435 if (Size.isInvalid())
2436 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002437
John McCall550e0c22009-10-21 00:40:46 +00002438 QualType Result = TL.getType();
2439 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002440 ElementType != T->getElementType() ||
2441 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002442 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002443 move(Size),
2444 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002445 if (Result.isNull())
2446 return QualType();
2447 }
2448 else Size.take();
2449
2450 // Result might be dependent or not.
2451 if (isa<DependentSizedExtVectorType>(Result)) {
2452 DependentSizedExtVectorTypeLoc NewTL
2453 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2454 NewTL.setNameLoc(TL.getNameLoc());
2455 } else {
2456 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2457 NewTL.setNameLoc(TL.getNameLoc());
2458 }
2459
2460 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002461}
Mike Stump11289f42009-09-09 15:08:12 +00002462
2463template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002464QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2465 VectorTypeLoc TL) {
2466 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002467 QualType ElementType = getDerived().TransformType(T->getElementType());
2468 if (ElementType.isNull())
2469 return QualType();
2470
John McCall550e0c22009-10-21 00:40:46 +00002471 QualType Result = TL.getType();
2472 if (getDerived().AlwaysRebuild() ||
2473 ElementType != T->getElementType()) {
2474 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2475 if (Result.isNull())
2476 return QualType();
2477 }
2478
2479 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2480 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002481
John McCall550e0c22009-10-21 00:40:46 +00002482 return Result;
2483}
2484
2485template<typename Derived>
2486QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2487 ExtVectorTypeLoc TL) {
2488 VectorType *T = TL.getTypePtr();
2489 QualType ElementType = getDerived().TransformType(T->getElementType());
2490 if (ElementType.isNull())
2491 return QualType();
2492
2493 QualType Result = TL.getType();
2494 if (getDerived().AlwaysRebuild() ||
2495 ElementType != T->getElementType()) {
2496 Result = getDerived().RebuildExtVectorType(ElementType,
2497 T->getNumElements(),
2498 /*FIXME*/ SourceLocation());
2499 if (Result.isNull())
2500 return QualType();
2501 }
2502
2503 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2504 NewTL.setNameLoc(TL.getNameLoc());
2505
2506 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002507}
Mike Stump11289f42009-09-09 15:08:12 +00002508
2509template<typename Derived>
2510QualType
John McCall550e0c22009-10-21 00:40:46 +00002511TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2512 FunctionProtoTypeLoc TL) {
2513 FunctionProtoType *T = TL.getTypePtr();
2514 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002515 if (ResultType.isNull())
2516 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002517
John McCall550e0c22009-10-21 00:40:46 +00002518 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002519 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002520 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2521 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2522 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002523
John McCall550e0c22009-10-21 00:40:46 +00002524 QualType NewType;
2525 ParmVarDecl *NewParm;
2526
2527 if (OldParm) {
2528 DeclaratorInfo *OldDI = OldParm->getDeclaratorInfo();
2529 assert(OldDI->getType() == T->getArgType(i));
2530
2531 DeclaratorInfo *NewDI = getDerived().TransformType(OldDI);
2532 if (!NewDI)
2533 return QualType();
2534
2535 if (NewDI == OldDI)
2536 NewParm = OldParm;
2537 else
2538 NewParm = ParmVarDecl::Create(SemaRef.Context,
2539 OldParm->getDeclContext(),
2540 OldParm->getLocation(),
2541 OldParm->getIdentifier(),
2542 NewDI->getType(),
2543 NewDI,
2544 OldParm->getStorageClass(),
2545 /* DefArg */ NULL);
2546 NewType = NewParm->getType();
2547
2548 // Deal with the possibility that we don't have a parameter
2549 // declaration for this parameter.
2550 } else {
2551 NewParm = 0;
2552
2553 QualType OldType = T->getArgType(i);
2554 NewType = getDerived().TransformType(OldType);
2555 if (NewType.isNull())
2556 return QualType();
2557 }
2558
2559 ParamTypes.push_back(NewType);
2560 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002561 }
Mike Stump11289f42009-09-09 15:08:12 +00002562
John McCall550e0c22009-10-21 00:40:46 +00002563 QualType Result = TL.getType();
2564 if (getDerived().AlwaysRebuild() ||
2565 ResultType != T->getResultType() ||
2566 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2567 Result = getDerived().RebuildFunctionProtoType(ResultType,
2568 ParamTypes.data(),
2569 ParamTypes.size(),
2570 T->isVariadic(),
2571 T->getTypeQuals());
2572 if (Result.isNull())
2573 return QualType();
2574 }
Mike Stump11289f42009-09-09 15:08:12 +00002575
John McCall550e0c22009-10-21 00:40:46 +00002576 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2577 NewTL.setLParenLoc(TL.getLParenLoc());
2578 NewTL.setRParenLoc(TL.getRParenLoc());
2579 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2580 NewTL.setArg(i, ParamDecls[i]);
2581
2582 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583}
Mike Stump11289f42009-09-09 15:08:12 +00002584
Douglas Gregord6ff3322009-08-04 16:50:30 +00002585template<typename Derived>
2586QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002587 TypeLocBuilder &TLB,
2588 FunctionNoProtoTypeLoc TL) {
2589 FunctionNoProtoType *T = TL.getTypePtr();
2590 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2591 if (ResultType.isNull())
2592 return QualType();
2593
2594 QualType Result = TL.getType();
2595 if (getDerived().AlwaysRebuild() ||
2596 ResultType != T->getResultType())
2597 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2598
2599 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2600 NewTL.setLParenLoc(TL.getLParenLoc());
2601 NewTL.setRParenLoc(TL.getRParenLoc());
2602
2603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604}
Mike Stump11289f42009-09-09 15:08:12 +00002605
Douglas Gregord6ff3322009-08-04 16:50:30 +00002606template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002607QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2608 TypedefTypeLoc TL) {
2609 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002610 TypedefDecl *Typedef
2611 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2612 if (!Typedef)
2613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
2617 Typedef != T->getDecl()) {
2618 Result = getDerived().RebuildTypedefType(Typedef);
2619 if (Result.isNull())
2620 return QualType();
2621 }
Mike Stump11289f42009-09-09 15:08:12 +00002622
John McCall550e0c22009-10-21 00:40:46 +00002623 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2624 NewTL.setNameLoc(TL.getNameLoc());
2625
2626 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627}
Mike Stump11289f42009-09-09 15:08:12 +00002628
Douglas Gregord6ff3322009-08-04 16:50:30 +00002629template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002630QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2631 TypeOfExprTypeLoc TL) {
2632 TypeOfExprType *T = TL.getTypePtr();
2633
Douglas Gregore922c772009-08-04 22:27:00 +00002634 // typeof expressions are not potentially evaluated contexts
2635 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002636
Douglas Gregord6ff3322009-08-04 16:50:30 +00002637 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2638 if (E.isInvalid())
2639 return QualType();
2640
John McCall550e0c22009-10-21 00:40:46 +00002641 QualType Result = TL.getType();
2642 if (getDerived().AlwaysRebuild() ||
2643 E.get() != T->getUnderlyingExpr()) {
2644 Result = getDerived().RebuildTypeOfExprType(move(E));
2645 if (Result.isNull())
2646 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002647 }
John McCall550e0c22009-10-21 00:40:46 +00002648 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002649
John McCall550e0c22009-10-21 00:40:46 +00002650 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2651 NewTL.setNameLoc(TL.getNameLoc());
2652
2653 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002654}
Mike Stump11289f42009-09-09 15:08:12 +00002655
2656template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002657QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2658 TypeOfTypeLoc TL) {
2659 TypeOfType *T = TL.getTypePtr();
2660
2661 // FIXME: should be an inner type, or at least have a DeclaratorInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2663 if (Underlying.isNull())
2664 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002665
John McCall550e0c22009-10-21 00:40:46 +00002666 QualType Result = TL.getType();
2667 if (getDerived().AlwaysRebuild() ||
2668 Underlying != T->getUnderlyingType()) {
2669 Result = getDerived().RebuildTypeOfType(Underlying);
2670 if (Result.isNull())
2671 return QualType();
2672 }
Mike Stump11289f42009-09-09 15:08:12 +00002673
John McCall550e0c22009-10-21 00:40:46 +00002674 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2675 NewTL.setNameLoc(TL.getNameLoc());
2676
2677 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678}
Mike Stump11289f42009-09-09 15:08:12 +00002679
2680template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002681QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2682 DecltypeTypeLoc TL) {
2683 DecltypeType *T = TL.getTypePtr();
2684
Douglas Gregore922c772009-08-04 22:27:00 +00002685 // decltype expressions are not potentially evaluated contexts
2686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002687
Douglas Gregord6ff3322009-08-04 16:50:30 +00002688 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2689 if (E.isInvalid())
2690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002691
John McCall550e0c22009-10-21 00:40:46 +00002692 QualType Result = TL.getType();
2693 if (getDerived().AlwaysRebuild() ||
2694 E.get() != T->getUnderlyingExpr()) {
2695 Result = getDerived().RebuildDecltypeType(move(E));
2696 if (Result.isNull())
2697 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002698 }
John McCall550e0c22009-10-21 00:40:46 +00002699 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002700
John McCall550e0c22009-10-21 00:40:46 +00002701 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2702 NewTL.setNameLoc(TL.getNameLoc());
2703
2704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002705}
2706
2707template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002708QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2709 RecordTypeLoc TL) {
2710 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002711 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002712 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002713 if (!Record)
2714 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002715
John McCall550e0c22009-10-21 00:40:46 +00002716 QualType Result = TL.getType();
2717 if (getDerived().AlwaysRebuild() ||
2718 Record != T->getDecl()) {
2719 Result = getDerived().RebuildRecordType(Record);
2720 if (Result.isNull())
2721 return QualType();
2722 }
Mike Stump11289f42009-09-09 15:08:12 +00002723
John McCall550e0c22009-10-21 00:40:46 +00002724 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2725 NewTL.setNameLoc(TL.getNameLoc());
2726
2727 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002728}
Mike Stump11289f42009-09-09 15:08:12 +00002729
2730template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002731QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2732 EnumTypeLoc TL) {
2733 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002734 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002735 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002736 if (!Enum)
2737 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002738
John McCall550e0c22009-10-21 00:40:46 +00002739 QualType Result = TL.getType();
2740 if (getDerived().AlwaysRebuild() ||
2741 Enum != T->getDecl()) {
2742 Result = getDerived().RebuildEnumType(Enum);
2743 if (Result.isNull())
2744 return QualType();
2745 }
Mike Stump11289f42009-09-09 15:08:12 +00002746
John McCall550e0c22009-10-21 00:40:46 +00002747 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2748 NewTL.setNameLoc(TL.getNameLoc());
2749
2750 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002751}
John McCallfcc33b02009-09-05 00:15:47 +00002752
2753template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002754QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2755 ElaboratedTypeLoc TL) {
2756 ElaboratedType *T = TL.getTypePtr();
2757
2758 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002759 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2760 if (Underlying.isNull())
2761 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002762
John McCall550e0c22009-10-21 00:40:46 +00002763 QualType Result = TL.getType();
2764 if (getDerived().AlwaysRebuild() ||
2765 Underlying != T->getUnderlyingType()) {
2766 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2767 if (Result.isNull())
2768 return QualType();
2769 }
Mike Stump11289f42009-09-09 15:08:12 +00002770
John McCall550e0c22009-10-21 00:40:46 +00002771 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2772 NewTL.setNameLoc(TL.getNameLoc());
2773
2774 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002775}
Mike Stump11289f42009-09-09 15:08:12 +00002776
2777
Douglas Gregord6ff3322009-08-04 16:50:30 +00002778template<typename Derived>
2779QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002780 TypeLocBuilder &TLB,
2781 TemplateTypeParmTypeLoc TL) {
2782 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002783}
2784
Mike Stump11289f42009-09-09 15:08:12 +00002785template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002786QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002787 TypeLocBuilder &TLB,
2788 SubstTemplateTypeParmTypeLoc TL) {
2789 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002790}
2791
2792template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002793inline QualType
2794TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002795 TypeLocBuilder &TLB,
2796 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002797 return TransformTemplateSpecializationType(TLB, TL, QualType());
2798}
John McCall550e0c22009-10-21 00:40:46 +00002799
John McCall0ad16662009-10-29 08:12:44 +00002800template<typename Derived>
2801QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2802 const TemplateSpecializationType *TST,
2803 QualType ObjectType) {
2804 // FIXME: this entire method is a temporary workaround; callers
2805 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002806
John McCall0ad16662009-10-29 08:12:44 +00002807 // Fake up a TemplateSpecializationTypeLoc.
2808 TypeLocBuilder TLB;
2809 TemplateSpecializationTypeLoc TL
2810 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2811
John McCall0d07eb32009-10-29 18:45:58 +00002812 SourceLocation BaseLoc = getDerived().getBaseLocation();
2813
2814 TL.setTemplateNameLoc(BaseLoc);
2815 TL.setLAngleLoc(BaseLoc);
2816 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002817 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2818 const TemplateArgument &TA = TST->getArg(i);
2819 TemplateArgumentLoc TAL;
2820 getDerived().InventTemplateArgumentLoc(TA, TAL);
2821 TL.setArgLocInfo(i, TAL.getLocInfo());
2822 }
2823
2824 TypeLocBuilder IgnoredTLB;
2825 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002826}
2827
2828template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002829QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002830 TypeLocBuilder &TLB,
2831 TemplateSpecializationTypeLoc TL,
2832 QualType ObjectType) {
2833 const TemplateSpecializationType *T = TL.getTypePtr();
2834
Mike Stump11289f42009-09-09 15:08:12 +00002835 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002836 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 if (Template.isNull())
2838 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002839
John McCall6b51f282009-11-23 01:53:49 +00002840 TemplateArgumentListInfo NewTemplateArgs;
2841 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2842 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2843
2844 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2845 TemplateArgumentLoc Loc;
2846 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002847 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002848 NewTemplateArgs.addArgument(Loc);
2849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
John McCall0ad16662009-10-29 08:12:44 +00002851 // FIXME: maybe don't rebuild if all the template arguments are the same.
2852
2853 QualType Result =
2854 getDerived().RebuildTemplateSpecializationType(Template,
2855 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002856 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002857
2858 if (!Result.isNull()) {
2859 TemplateSpecializationTypeLoc NewTL
2860 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2861 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2862 NewTL.setLAngleLoc(TL.getLAngleLoc());
2863 NewTL.setRAngleLoc(TL.getRAngleLoc());
2864 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2865 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002866 }
Mike Stump11289f42009-09-09 15:08:12 +00002867
John McCall0ad16662009-10-29 08:12:44 +00002868 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002869}
Mike Stump11289f42009-09-09 15:08:12 +00002870
2871template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002872QualType
2873TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2874 QualifiedNameTypeLoc TL) {
2875 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002876 NestedNameSpecifier *NNS
2877 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2878 SourceRange());
2879 if (!NNS)
2880 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002881
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882 QualType Named = getDerived().TransformType(T->getNamedType());
2883 if (Named.isNull())
2884 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002885
John McCall550e0c22009-10-21 00:40:46 +00002886 QualType Result = TL.getType();
2887 if (getDerived().AlwaysRebuild() ||
2888 NNS != T->getQualifier() ||
2889 Named != T->getNamedType()) {
2890 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2891 if (Result.isNull())
2892 return QualType();
2893 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002894
John McCall550e0c22009-10-21 00:40:46 +00002895 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2896 NewTL.setNameLoc(TL.getNameLoc());
2897
2898 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899}
Mike Stump11289f42009-09-09 15:08:12 +00002900
2901template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002902QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2903 TypenameTypeLoc TL) {
2904 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002905
2906 /* FIXME: preserve source information better than this */
2907 SourceRange SR(TL.getNameLoc());
2908
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002910 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002911 if (!NNS)
2912 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002913
John McCall550e0c22009-10-21 00:40:46 +00002914 QualType Result;
2915
Douglas Gregord6ff3322009-08-04 16:50:30 +00002916 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002917 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918 = getDerived().TransformType(QualType(TemplateId, 0));
2919 if (NewTemplateId.isNull())
2920 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002921
Douglas Gregord6ff3322009-08-04 16:50:30 +00002922 if (!getDerived().AlwaysRebuild() &&
2923 NNS == T->getQualifier() &&
2924 NewTemplateId == QualType(TemplateId, 0))
2925 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002926
John McCall550e0c22009-10-21 00:40:46 +00002927 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2928 } else {
John McCall0ad16662009-10-29 08:12:44 +00002929 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002930 }
John McCall550e0c22009-10-21 00:40:46 +00002931 if (Result.isNull())
2932 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933
John McCall550e0c22009-10-21 00:40:46 +00002934 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2935 NewTL.setNameLoc(TL.getNameLoc());
2936
2937 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002938}
Mike Stump11289f42009-09-09 15:08:12 +00002939
Douglas Gregord6ff3322009-08-04 16:50:30 +00002940template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002941QualType
2942TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2943 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002944 assert(false && "TransformObjCInterfaceType unimplemented");
2945 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946}
Mike Stump11289f42009-09-09 15:08:12 +00002947
2948template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002949QualType
2950TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2951 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002952 assert(false && "TransformObjCObjectPointerType unimplemented");
2953 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002954}
2955
Douglas Gregord6ff3322009-08-04 16:50:30 +00002956//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002957// Statement transformation
2958//===----------------------------------------------------------------------===//
2959template<typename Derived>
2960Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002961TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2962 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002963}
2964
2965template<typename Derived>
2966Sema::OwningStmtResult
2967TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2968 return getDerived().TransformCompoundStmt(S, false);
2969}
2970
2971template<typename Derived>
2972Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002973TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002974 bool IsStmtExpr) {
2975 bool SubStmtChanged = false;
2976 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2977 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2978 B != BEnd; ++B) {
2979 OwningStmtResult Result = getDerived().TransformStmt(*B);
2980 if (Result.isInvalid())
2981 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002982
Douglas Gregorebe10102009-08-20 07:17:43 +00002983 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2984 Statements.push_back(Result.takeAs<Stmt>());
2985 }
Mike Stump11289f42009-09-09 15:08:12 +00002986
Douglas Gregorebe10102009-08-20 07:17:43 +00002987 if (!getDerived().AlwaysRebuild() &&
2988 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002989 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002990
2991 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2992 move_arg(Statements),
2993 S->getRBracLoc(),
2994 IsStmtExpr);
2995}
Mike Stump11289f42009-09-09 15:08:12 +00002996
Douglas Gregorebe10102009-08-20 07:17:43 +00002997template<typename Derived>
2998Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002999TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003000 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3001 {
3002 // The case value expressions are not potentially evaluated.
3003 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003004
Eli Friedman06577382009-11-19 03:14:00 +00003005 // Transform the left-hand case value.
3006 LHS = getDerived().TransformExpr(S->getLHS());
3007 if (LHS.isInvalid())
3008 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003009
Eli Friedman06577382009-11-19 03:14:00 +00003010 // Transform the right-hand case value (for the GNU case-range extension).
3011 RHS = getDerived().TransformExpr(S->getRHS());
3012 if (RHS.isInvalid())
3013 return SemaRef.StmtError();
3014 }
Mike Stump11289f42009-09-09 15:08:12 +00003015
Douglas Gregorebe10102009-08-20 07:17:43 +00003016 // Build the case statement.
3017 // Case statements are always rebuilt so that they will attached to their
3018 // transformed switch statement.
3019 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3020 move(LHS),
3021 S->getEllipsisLoc(),
3022 move(RHS),
3023 S->getColonLoc());
3024 if (Case.isInvalid())
3025 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003026
Douglas Gregorebe10102009-08-20 07:17:43 +00003027 // Transform the statement following the case
3028 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3029 if (SubStmt.isInvalid())
3030 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003031
Douglas Gregorebe10102009-08-20 07:17:43 +00003032 // Attach the body to the case statement
3033 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3034}
3035
3036template<typename Derived>
3037Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003038TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003039 // Transform the statement following the default case
3040 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3041 if (SubStmt.isInvalid())
3042 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003043
Douglas Gregorebe10102009-08-20 07:17:43 +00003044 // Default statements are always rebuilt
3045 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3046 move(SubStmt));
3047}
Mike Stump11289f42009-09-09 15:08:12 +00003048
Douglas Gregorebe10102009-08-20 07:17:43 +00003049template<typename Derived>
3050Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003051TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003052 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3053 if (SubStmt.isInvalid())
3054 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003055
Douglas Gregorebe10102009-08-20 07:17:43 +00003056 // FIXME: Pass the real colon location in.
3057 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3058 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3059 move(SubStmt));
3060}
Mike Stump11289f42009-09-09 15:08:12 +00003061
Douglas Gregorebe10102009-08-20 07:17:43 +00003062template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003063Sema::OwningStmtResult
3064TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003065 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003066 OwningExprResult Cond(SemaRef);
3067 VarDecl *ConditionVar = 0;
3068 if (S->getConditionVariable()) {
3069 ConditionVar
3070 = cast_or_null<VarDecl>(
3071 getDerived().TransformDefinition(S->getConditionVariable()));
3072 if (!ConditionVar)
3073 return SemaRef.StmtError();
3074
3075 Cond = getSema().CheckConditionVariable(ConditionVar);
3076 } else
3077 Cond = getDerived().TransformExpr(S->getCond());
3078
Douglas Gregorebe10102009-08-20 07:17:43 +00003079 if (Cond.isInvalid())
3080 return SemaRef.StmtError();
Douglas Gregor633caca2009-11-23 23:44:04 +00003081
Douglas Gregorebe10102009-08-20 07:17:43 +00003082 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003083
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 // Transform the "then" branch.
3085 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3086 if (Then.isInvalid())
3087 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003088
Douglas Gregorebe10102009-08-20 07:17:43 +00003089 // Transform the "else" branch.
3090 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3091 if (Else.isInvalid())
3092 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003093
Douglas Gregorebe10102009-08-20 07:17:43 +00003094 if (!getDerived().AlwaysRebuild() &&
3095 FullCond->get() == S->getCond() &&
3096 Then.get() == S->getThen() &&
3097 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003098 return SemaRef.Owned(S->Retain());
3099
Douglas Gregorebe10102009-08-20 07:17:43 +00003100 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003101 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003102}
3103
3104template<typename Derived>
3105Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003106TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003107 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003108 OwningExprResult Cond(SemaRef);
3109 VarDecl *ConditionVar = 0;
3110 if (S->getConditionVariable()) {
3111 ConditionVar
3112 = cast_or_null<VarDecl>(
3113 getDerived().TransformDefinition(S->getConditionVariable()));
3114 if (!ConditionVar)
3115 return SemaRef.StmtError();
3116
3117 Cond = getSema().CheckConditionVariable(ConditionVar);
3118 } else
3119 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorebe10102009-08-20 07:17:43 +00003120 if (Cond.isInvalid())
3121 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003122
Douglas Gregorebe10102009-08-20 07:17:43 +00003123 // Rebuild the switch statement.
3124 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(move(Cond));
3125 if (Switch.isInvalid())
3126 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003127
Douglas Gregorebe10102009-08-20 07:17:43 +00003128 // Transform the body of the switch statement.
3129 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3130 if (Body.isInvalid())
3131 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003132
Douglas Gregorebe10102009-08-20 07:17:43 +00003133 // Complete the switch statement.
3134 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3135 move(Body));
3136}
Mike Stump11289f42009-09-09 15:08:12 +00003137
Douglas Gregorebe10102009-08-20 07:17:43 +00003138template<typename Derived>
3139Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003140TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003141 // Transform the condition
3142 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3143 if (Cond.isInvalid())
3144 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003145
Douglas Gregorebe10102009-08-20 07:17:43 +00003146 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003147
Douglas Gregorebe10102009-08-20 07:17:43 +00003148 // Transform the body
3149 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3150 if (Body.isInvalid())
3151 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003152
Douglas Gregorebe10102009-08-20 07:17:43 +00003153 if (!getDerived().AlwaysRebuild() &&
3154 FullCond->get() == S->getCond() &&
3155 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003156 return SemaRef.Owned(S->Retain());
3157
Douglas Gregorebe10102009-08-20 07:17:43 +00003158 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
3159}
Mike Stump11289f42009-09-09 15:08:12 +00003160
Douglas Gregorebe10102009-08-20 07:17:43 +00003161template<typename Derived>
3162Sema::OwningStmtResult
3163TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3164 // Transform the condition
3165 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3166 if (Cond.isInvalid())
3167 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003168
Douglas Gregorebe10102009-08-20 07:17:43 +00003169 // Transform the body
3170 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3171 if (Body.isInvalid())
3172 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003173
Douglas Gregorebe10102009-08-20 07:17:43 +00003174 if (!getDerived().AlwaysRebuild() &&
3175 Cond.get() == S->getCond() &&
3176 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003177 return SemaRef.Owned(S->Retain());
3178
Douglas Gregorebe10102009-08-20 07:17:43 +00003179 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3180 /*FIXME:*/S->getWhileLoc(), move(Cond),
3181 S->getRParenLoc());
3182}
Mike Stump11289f42009-09-09 15:08:12 +00003183
Douglas Gregorebe10102009-08-20 07:17:43 +00003184template<typename Derived>
3185Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003186TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003187 // Transform the initialization statement
3188 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3189 if (Init.isInvalid())
3190 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003191
Douglas Gregorebe10102009-08-20 07:17:43 +00003192 // Transform the condition
3193 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3194 if (Cond.isInvalid())
3195 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 // Transform the increment
3198 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3199 if (Inc.isInvalid())
3200 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003201
Douglas Gregorebe10102009-08-20 07:17:43 +00003202 // Transform the body
3203 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3204 if (Body.isInvalid())
3205 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003206
Douglas Gregorebe10102009-08-20 07:17:43 +00003207 if (!getDerived().AlwaysRebuild() &&
3208 Init.get() == S->getInit() &&
3209 Cond.get() == S->getCond() &&
3210 Inc.get() == S->getInc() &&
3211 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003212 return SemaRef.Owned(S->Retain());
3213
Douglas Gregorebe10102009-08-20 07:17:43 +00003214 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3215 move(Init), move(Cond), move(Inc),
3216 S->getRParenLoc(), move(Body));
3217}
3218
3219template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003220Sema::OwningStmtResult
3221TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003222 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003223 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003224 S->getLabel());
3225}
3226
3227template<typename Derived>
3228Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003229TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3231 if (Target.isInvalid())
3232 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003233
Douglas Gregorebe10102009-08-20 07:17:43 +00003234 if (!getDerived().AlwaysRebuild() &&
3235 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003236 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003237
3238 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3239 move(Target));
3240}
3241
3242template<typename Derived>
3243Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003244TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3245 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003246}
Mike Stump11289f42009-09-09 15:08:12 +00003247
Douglas Gregorebe10102009-08-20 07:17:43 +00003248template<typename Derived>
3249Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003250TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3251 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003252}
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregorebe10102009-08-20 07:17:43 +00003254template<typename Derived>
3255Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003256TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003257 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3258 if (Result.isInvalid())
3259 return SemaRef.StmtError();
3260
Mike Stump11289f42009-09-09 15:08:12 +00003261 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003262 // to tell whether the return type of the function has changed.
3263 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3264}
Mike Stump11289f42009-09-09 15:08:12 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266template<typename Derived>
3267Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003268TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003269 bool DeclChanged = false;
3270 llvm::SmallVector<Decl *, 4> Decls;
3271 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3272 D != DEnd; ++D) {
3273 Decl *Transformed = getDerived().TransformDefinition(*D);
3274 if (!Transformed)
3275 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003276
Douglas Gregorebe10102009-08-20 07:17:43 +00003277 if (Transformed != *D)
3278 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003279
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 Decls.push_back(Transformed);
3281 }
Mike Stump11289f42009-09-09 15:08:12 +00003282
Douglas Gregorebe10102009-08-20 07:17:43 +00003283 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003284 return SemaRef.Owned(S->Retain());
3285
3286 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 S->getStartLoc(), S->getEndLoc());
3288}
Mike Stump11289f42009-09-09 15:08:12 +00003289
Douglas Gregorebe10102009-08-20 07:17:43 +00003290template<typename Derived>
3291Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003292TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003293 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003294 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003295}
3296
3297template<typename Derived>
3298Sema::OwningStmtResult
3299TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3300 // FIXME: Implement!
3301 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003302 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003303}
3304
3305
3306template<typename Derived>
3307Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003308TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003309 // FIXME: Implement this
3310 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003311 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003312}
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314template<typename Derived>
3315Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003316TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 // FIXME: Implement this
3318 assert(false && "Cannot transform an Objective-C @catch statement");
3319 return SemaRef.Owned(S->Retain());
3320}
Mike Stump11289f42009-09-09 15:08:12 +00003321
Douglas Gregorebe10102009-08-20 07:17:43 +00003322template<typename Derived>
3323Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003324TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003325 // FIXME: Implement this
3326 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003327 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003328}
Mike Stump11289f42009-09-09 15:08:12 +00003329
Douglas Gregorebe10102009-08-20 07:17:43 +00003330template<typename Derived>
3331Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003332TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003333 // FIXME: Implement this
3334 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003335 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003336}
Mike Stump11289f42009-09-09 15:08:12 +00003337
Douglas Gregorebe10102009-08-20 07:17:43 +00003338template<typename Derived>
3339Sema::OwningStmtResult
3340TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003341 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // FIXME: Implement this
3343 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003344 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003345}
3346
3347template<typename Derived>
3348Sema::OwningStmtResult
3349TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003350 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003351 // FIXME: Implement this
3352 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003353 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003354}
3355
3356
3357template<typename Derived>
3358Sema::OwningStmtResult
3359TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3360 // Transform the exception declaration, if any.
3361 VarDecl *Var = 0;
3362 if (S->getExceptionDecl()) {
3363 VarDecl *ExceptionDecl = S->getExceptionDecl();
3364 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3365 ExceptionDecl->getDeclName());
3366
3367 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3368 if (T.isNull())
3369 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003370
Douglas Gregorebe10102009-08-20 07:17:43 +00003371 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3372 T,
3373 ExceptionDecl->getDeclaratorInfo(),
3374 ExceptionDecl->getIdentifier(),
3375 ExceptionDecl->getLocation(),
3376 /*FIXME: Inaccurate*/
3377 SourceRange(ExceptionDecl->getLocation()));
3378 if (!Var || Var->isInvalidDecl()) {
3379 if (Var)
3380 Var->Destroy(SemaRef.Context);
3381 return SemaRef.StmtError();
3382 }
3383 }
Mike Stump11289f42009-09-09 15:08:12 +00003384
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 // Transform the actual exception handler.
3386 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3387 if (Handler.isInvalid()) {
3388 if (Var)
3389 Var->Destroy(SemaRef.Context);
3390 return SemaRef.StmtError();
3391 }
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregorebe10102009-08-20 07:17:43 +00003393 if (!getDerived().AlwaysRebuild() &&
3394 !Var &&
3395 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003396 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003397
3398 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3399 Var,
3400 move(Handler));
3401}
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403template<typename Derived>
3404Sema::OwningStmtResult
3405TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3406 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003407 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003408 = getDerived().TransformCompoundStmt(S->getTryBlock());
3409 if (TryBlock.isInvalid())
3410 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003411
Douglas Gregorebe10102009-08-20 07:17:43 +00003412 // Transform the handlers.
3413 bool HandlerChanged = false;
3414 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3415 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003416 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003417 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3418 if (Handler.isInvalid())
3419 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregorebe10102009-08-20 07:17:43 +00003421 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3422 Handlers.push_back(Handler.takeAs<Stmt>());
3423 }
Mike Stump11289f42009-09-09 15:08:12 +00003424
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 if (!getDerived().AlwaysRebuild() &&
3426 TryBlock.get() == S->getTryBlock() &&
3427 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003428 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003429
3430 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003431 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003432}
Mike Stump11289f42009-09-09 15:08:12 +00003433
Douglas Gregorebe10102009-08-20 07:17:43 +00003434//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003435// Expression transformation
3436//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003437template<typename Derived>
3438Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003439TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3440 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003441 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003442}
Mike Stump11289f42009-09-09 15:08:12 +00003443
3444template<typename Derived>
3445Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003446TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3447 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003448 NestedNameSpecifier *Qualifier = 0;
3449 if (E->getQualifier()) {
3450 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3451 E->getQualifierRange());
3452 if (!Qualifier)
3453 return SemaRef.ExprError();
3454 }
3455
Mike Stump11289f42009-09-09 15:08:12 +00003456 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003457 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3458 if (!ND)
3459 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003460
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003461 if (!getDerived().AlwaysRebuild() &&
3462 Qualifier == E->getQualifier() &&
3463 ND == E->getDecl() &&
3464 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003465 return SemaRef.Owned(E->Retain());
3466
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003467 // FIXME: We're losing the explicit template arguments in this transformation.
3468
John McCall0ad16662009-10-29 08:12:44 +00003469 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003470 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003471 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3472 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003473 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003474 }
3475
3476 // FIXME: Pass the qualifier/qualifier range along.
3477 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003478 ND, E->getLocation(),
3479 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003480}
Mike Stump11289f42009-09-09 15:08:12 +00003481
Douglas Gregora16548e2009-08-11 05:31:07 +00003482template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003483Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003484TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3485 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003486 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003487}
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregora16548e2009-08-11 05:31:07 +00003489template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003490Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003491TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3492 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003493 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003494}
Mike Stump11289f42009-09-09 15:08:12 +00003495
Douglas Gregora16548e2009-08-11 05:31:07 +00003496template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003497Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003498TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3499 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003500 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003501}
Mike Stump11289f42009-09-09 15:08:12 +00003502
Douglas Gregora16548e2009-08-11 05:31:07 +00003503template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003504Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003505TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3506 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003507 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003508}
Mike Stump11289f42009-09-09 15:08:12 +00003509
Douglas Gregora16548e2009-08-11 05:31:07 +00003510template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003511Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003512TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3513 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003514 return SemaRef.Owned(E->Retain());
3515}
3516
3517template<typename Derived>
3518Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003519TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3520 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003521 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3522 if (SubExpr.isInvalid())
3523 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregora16548e2009-08-11 05:31:07 +00003525 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003526 return SemaRef.Owned(E->Retain());
3527
3528 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003529 E->getRParen());
3530}
3531
Mike Stump11289f42009-09-09 15:08:12 +00003532template<typename Derived>
3533Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003534TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3535 bool isAddressOfOperand) {
3536 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3537 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003538 if (SubExpr.isInvalid())
3539 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003540
Douglas Gregora16548e2009-08-11 05:31:07 +00003541 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003542 return SemaRef.Owned(E->Retain());
3543
Douglas Gregora16548e2009-08-11 05:31:07 +00003544 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3545 E->getOpcode(),
3546 move(SubExpr));
3547}
Mike Stump11289f42009-09-09 15:08:12 +00003548
Douglas Gregora16548e2009-08-11 05:31:07 +00003549template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003550Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003551TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3552 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003553 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003554 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003555
John McCall4c98fd82009-11-04 07:28:41 +00003556 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3557 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003558 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003559
John McCall4c98fd82009-11-04 07:28:41 +00003560 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003561 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003562
John McCall4c98fd82009-11-04 07:28:41 +00003563 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003564 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003565 E->getSourceRange());
3566 }
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregora16548e2009-08-11 05:31:07 +00003568 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003569 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003570 // C++0x [expr.sizeof]p1:
3571 // The operand is either an expression, which is an unevaluated operand
3572 // [...]
3573 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003574
Douglas Gregora16548e2009-08-11 05:31:07 +00003575 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3576 if (SubExpr.isInvalid())
3577 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregora16548e2009-08-11 05:31:07 +00003579 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3580 return SemaRef.Owned(E->Retain());
3581 }
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregora16548e2009-08-11 05:31:07 +00003583 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3584 E->isSizeOf(),
3585 E->getSourceRange());
3586}
Mike Stump11289f42009-09-09 15:08:12 +00003587
Douglas Gregora16548e2009-08-11 05:31:07 +00003588template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003589Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003590TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3591 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003592 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3593 if (LHS.isInvalid())
3594 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003595
Douglas Gregora16548e2009-08-11 05:31:07 +00003596 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3597 if (RHS.isInvalid())
3598 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003599
3600
Douglas Gregora16548e2009-08-11 05:31:07 +00003601 if (!getDerived().AlwaysRebuild() &&
3602 LHS.get() == E->getLHS() &&
3603 RHS.get() == E->getRHS())
3604 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregora16548e2009-08-11 05:31:07 +00003606 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3607 /*FIXME:*/E->getLHS()->getLocStart(),
3608 move(RHS),
3609 E->getRBracketLoc());
3610}
Mike Stump11289f42009-09-09 15:08:12 +00003611
3612template<typename Derived>
3613Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003614TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3615 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003616 // Transform the callee.
3617 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3618 if (Callee.isInvalid())
3619 return SemaRef.ExprError();
3620
3621 // Transform arguments.
3622 bool ArgChanged = false;
3623 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3624 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3625 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3626 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3627 if (Arg.isInvalid())
3628 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003629
Douglas Gregora16548e2009-08-11 05:31:07 +00003630 // FIXME: Wrong source location information for the ','.
3631 FakeCommaLocs.push_back(
3632 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003633
3634 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003635 Args.push_back(Arg.takeAs<Expr>());
3636 }
Mike Stump11289f42009-09-09 15:08:12 +00003637
Douglas Gregora16548e2009-08-11 05:31:07 +00003638 if (!getDerived().AlwaysRebuild() &&
3639 Callee.get() == E->getCallee() &&
3640 !ArgChanged)
3641 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003642
Douglas Gregora16548e2009-08-11 05:31:07 +00003643 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003644 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003645 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3646 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3647 move_arg(Args),
3648 FakeCommaLocs.data(),
3649 E->getRParenLoc());
3650}
Mike Stump11289f42009-09-09 15:08:12 +00003651
3652template<typename Derived>
3653Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003654TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3655 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3657 if (Base.isInvalid())
3658 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003659
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003660 NestedNameSpecifier *Qualifier = 0;
3661 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003662 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003663 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3664 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003665 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003666 return SemaRef.ExprError();
3667 }
Mike Stump11289f42009-09-09 15:08:12 +00003668
3669 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003670 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3671 if (!Member)
3672 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003673
Douglas Gregora16548e2009-08-11 05:31:07 +00003674 if (!getDerived().AlwaysRebuild() &&
3675 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003676 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003677 Member == E->getMemberDecl() &&
3678 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003679 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003680
John McCall6b51f282009-11-23 01:53:49 +00003681 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003682 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003683 TransArgs.setLAngleLoc(E->getLAngleLoc());
3684 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003685 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003686 TemplateArgumentLoc Loc;
3687 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003688 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003689 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003690 }
3691 }
3692
Douglas Gregora16548e2009-08-11 05:31:07 +00003693 // FIXME: Bogus source location for the operator
3694 SourceLocation FakeOperatorLoc
3695 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3696
3697 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3698 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003699 Qualifier,
3700 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003701 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003702 Member,
John McCall6b51f282009-11-23 01:53:49 +00003703 (E->hasExplicitTemplateArgumentList()
3704 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003705 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003706}
Mike Stump11289f42009-09-09 15:08:12 +00003707
Douglas Gregora16548e2009-08-11 05:31:07 +00003708template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003709Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003710TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3711 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003712 assert(false && "Cannot transform abstract class");
3713 return SemaRef.Owned(E->Retain());
3714}
3715
3716template<typename Derived>
3717Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003718TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3719 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003720 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3721 if (LHS.isInvalid())
3722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003723
Douglas Gregora16548e2009-08-11 05:31:07 +00003724 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3725 if (RHS.isInvalid())
3726 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003727
Douglas Gregora16548e2009-08-11 05:31:07 +00003728 if (!getDerived().AlwaysRebuild() &&
3729 LHS.get() == E->getLHS() &&
3730 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003731 return SemaRef.Owned(E->Retain());
3732
Douglas Gregora16548e2009-08-11 05:31:07 +00003733 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3734 move(LHS), move(RHS));
3735}
3736
Mike Stump11289f42009-09-09 15:08:12 +00003737template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003738Sema::OwningExprResult
3739TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003740 CompoundAssignOperator *E,
3741 bool isAddressOfOperand) {
3742 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003743}
Mike Stump11289f42009-09-09 15:08:12 +00003744
Douglas Gregora16548e2009-08-11 05:31:07 +00003745template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003746Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003747TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3748 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003749 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3750 if (Cond.isInvalid())
3751 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregora16548e2009-08-11 05:31:07 +00003753 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3754 if (LHS.isInvalid())
3755 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003756
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3758 if (RHS.isInvalid())
3759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 if (!getDerived().AlwaysRebuild() &&
3762 Cond.get() == E->getCond() &&
3763 LHS.get() == E->getLHS() &&
3764 RHS.get() == E->getRHS())
3765 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003766
3767 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003768 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003769 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003770 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003771 move(RHS));
3772}
Mike Stump11289f42009-09-09 15:08:12 +00003773
3774template<typename Derived>
3775Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003776TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3777 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003778 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3779
3780 // FIXME: Will we ever have type information here? It seems like we won't,
3781 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 QualType T = getDerived().TransformType(E->getType());
3783 if (T.isNull())
3784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003785
Douglas Gregora16548e2009-08-11 05:31:07 +00003786 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3787 if (SubExpr.isInvalid())
3788 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003789
Douglas Gregora16548e2009-08-11 05:31:07 +00003790 if (!getDerived().AlwaysRebuild() &&
3791 T == E->getType() &&
3792 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003793 return SemaRef.Owned(E->Retain());
3794
Douglas Gregora16548e2009-08-11 05:31:07 +00003795 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003796 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003797 E->isLvalueCast());
3798}
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregora16548e2009-08-11 05:31:07 +00003800template<typename Derived>
3801Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003802TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3803 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003804 assert(false && "Cannot transform abstract class");
3805 return SemaRef.Owned(E->Retain());
3806}
3807
3808template<typename Derived>
3809Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003810TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3811 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003812 QualType T;
3813 {
3814 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003815 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003816 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3817 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003818
Douglas Gregora16548e2009-08-11 05:31:07 +00003819 T = getDerived().TransformType(E->getTypeAsWritten());
3820 if (T.isNull())
3821 return SemaRef.ExprError();
3822 }
Mike Stump11289f42009-09-09 15:08:12 +00003823
Douglas Gregora16548e2009-08-11 05:31:07 +00003824 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3825 if (SubExpr.isInvalid())
3826 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregora16548e2009-08-11 05:31:07 +00003828 if (!getDerived().AlwaysRebuild() &&
3829 T == E->getTypeAsWritten() &&
3830 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003831 return SemaRef.Owned(E->Retain());
3832
Douglas Gregora16548e2009-08-11 05:31:07 +00003833 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3834 E->getRParenLoc(),
3835 move(SubExpr));
3836}
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003839Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003840TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3841 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003842 QualType T;
3843 {
3844 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003845 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003846 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3847 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849 T = getDerived().TransformType(E->getType());
3850 if (T.isNull())
3851 return SemaRef.ExprError();
3852 }
Mike Stump11289f42009-09-09 15:08:12 +00003853
Douglas Gregora16548e2009-08-11 05:31:07 +00003854 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3855 if (Init.isInvalid())
3856 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 if (!getDerived().AlwaysRebuild() &&
3859 T == E->getType() &&
3860 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003861 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003862
3863 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3864 /*FIXME:*/E->getInitializer()->getLocEnd(),
3865 move(Init));
3866}
Mike Stump11289f42009-09-09 15:08:12 +00003867
Douglas Gregora16548e2009-08-11 05:31:07 +00003868template<typename Derived>
3869Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003870TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3871 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003872 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3873 if (Base.isInvalid())
3874 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003875
Douglas Gregora16548e2009-08-11 05:31:07 +00003876 if (!getDerived().AlwaysRebuild() &&
3877 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003878 return SemaRef.Owned(E->Retain());
3879
Douglas Gregora16548e2009-08-11 05:31:07 +00003880 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003881 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003882 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3883 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3884 E->getAccessorLoc(),
3885 E->getAccessor());
3886}
Mike Stump11289f42009-09-09 15:08:12 +00003887
Douglas Gregora16548e2009-08-11 05:31:07 +00003888template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003889Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003890TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3891 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003892 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003893
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3895 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3896 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3897 if (Init.isInvalid())
3898 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003899
Douglas Gregora16548e2009-08-11 05:31:07 +00003900 InitChanged = InitChanged || Init.get() != E->getInit(I);
3901 Inits.push_back(Init.takeAs<Expr>());
3902 }
Mike Stump11289f42009-09-09 15:08:12 +00003903
Douglas Gregora16548e2009-08-11 05:31:07 +00003904 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003905 return SemaRef.Owned(E->Retain());
3906
Douglas Gregora16548e2009-08-11 05:31:07 +00003907 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003908 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003909}
Mike Stump11289f42009-09-09 15:08:12 +00003910
Douglas Gregora16548e2009-08-11 05:31:07 +00003911template<typename Derived>
3912Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003913TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3914 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003915 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregorebe10102009-08-20 07:17:43 +00003917 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003918 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3919 if (Init.isInvalid())
3920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregorebe10102009-08-20 07:17:43 +00003922 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003923 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3924 bool ExprChanged = false;
3925 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3926 DEnd = E->designators_end();
3927 D != DEnd; ++D) {
3928 if (D->isFieldDesignator()) {
3929 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3930 D->getDotLoc(),
3931 D->getFieldLoc()));
3932 continue;
3933 }
Mike Stump11289f42009-09-09 15:08:12 +00003934
Douglas Gregora16548e2009-08-11 05:31:07 +00003935 if (D->isArrayDesignator()) {
3936 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3937 if (Index.isInvalid())
3938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003939
3940 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003941 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003942
Douglas Gregora16548e2009-08-11 05:31:07 +00003943 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3944 ArrayExprs.push_back(Index.release());
3945 continue;
3946 }
Mike Stump11289f42009-09-09 15:08:12 +00003947
Douglas Gregora16548e2009-08-11 05:31:07 +00003948 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003949 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3951 if (Start.isInvalid())
3952 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3955 if (End.isInvalid())
3956 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003957
3958 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 End.get(),
3960 D->getLBracketLoc(),
3961 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003962
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3964 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregora16548e2009-08-11 05:31:07 +00003966 ArrayExprs.push_back(Start.release());
3967 ArrayExprs.push_back(End.release());
3968 }
Mike Stump11289f42009-09-09 15:08:12 +00003969
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 if (!getDerived().AlwaysRebuild() &&
3971 Init.get() == E->getInit() &&
3972 !ExprChanged)
3973 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003974
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3976 E->getEqualOrColonLoc(),
3977 E->usesGNUSyntax(), move(Init));
3978}
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregora16548e2009-08-11 05:31:07 +00003980template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003981Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003982TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003983 ImplicitValueInitExpr *E,
3984 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003985 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3986
3987 // FIXME: Will we ever have proper type location here? Will we actually
3988 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003989 QualType T = getDerived().TransformType(E->getType());
3990 if (T.isNull())
3991 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003992
Douglas Gregora16548e2009-08-11 05:31:07 +00003993 if (!getDerived().AlwaysRebuild() &&
3994 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003995 return SemaRef.Owned(E->Retain());
3996
Douglas Gregora16548e2009-08-11 05:31:07 +00003997 return getDerived().RebuildImplicitValueInitExpr(T);
3998}
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004001Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004002TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4003 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 // FIXME: Do we want the type as written?
4005 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004006
Douglas Gregora16548e2009-08-11 05:31:07 +00004007 {
4008 // FIXME: Source location isn't quite accurate.
4009 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4010 T = getDerived().TransformType(E->getType());
4011 if (T.isNull())
4012 return SemaRef.ExprError();
4013 }
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4016 if (SubExpr.isInvalid())
4017 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004018
Douglas Gregora16548e2009-08-11 05:31:07 +00004019 if (!getDerived().AlwaysRebuild() &&
4020 T == E->getType() &&
4021 SubExpr.get() == E->getSubExpr())
4022 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004023
Douglas Gregora16548e2009-08-11 05:31:07 +00004024 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4025 T, E->getRParenLoc());
4026}
4027
4028template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004029Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004030TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4031 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004032 bool ArgumentChanged = false;
4033 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4034 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4035 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4036 if (Init.isInvalid())
4037 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004038
Douglas Gregora16548e2009-08-11 05:31:07 +00004039 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4040 Inits.push_back(Init.takeAs<Expr>());
4041 }
Mike Stump11289f42009-09-09 15:08:12 +00004042
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4044 move_arg(Inits),
4045 E->getRParenLoc());
4046}
Mike Stump11289f42009-09-09 15:08:12 +00004047
Douglas Gregora16548e2009-08-11 05:31:07 +00004048/// \brief Transform an address-of-label expression.
4049///
4050/// By default, the transformation of an address-of-label expression always
4051/// rebuilds the expression, so that the label identifier can be resolved to
4052/// the corresponding label statement by semantic analysis.
4053template<typename Derived>
4054Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004055TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4056 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004057 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4058 E->getLabel());
4059}
Mike Stump11289f42009-09-09 15:08:12 +00004060
4061template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004062Sema::OwningExprResult
4063TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4064 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004065 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4067 if (SubStmt.isInvalid())
4068 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004069
Douglas Gregora16548e2009-08-11 05:31:07 +00004070 if (!getDerived().AlwaysRebuild() &&
4071 SubStmt.get() == E->getSubStmt())
4072 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004073
4074 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004075 move(SubStmt),
4076 E->getRParenLoc());
4077}
Mike Stump11289f42009-09-09 15:08:12 +00004078
Douglas Gregora16548e2009-08-11 05:31:07 +00004079template<typename Derived>
4080Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004081TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4082 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 QualType T1, T2;
4084 {
4085 // FIXME: Source location isn't quite accurate.
4086 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004087
Douglas Gregora16548e2009-08-11 05:31:07 +00004088 T1 = getDerived().TransformType(E->getArgType1());
4089 if (T1.isNull())
4090 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004091
Douglas Gregora16548e2009-08-11 05:31:07 +00004092 T2 = getDerived().TransformType(E->getArgType2());
4093 if (T2.isNull())
4094 return SemaRef.ExprError();
4095 }
4096
4097 if (!getDerived().AlwaysRebuild() &&
4098 T1 == E->getArgType1() &&
4099 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004100 return SemaRef.Owned(E->Retain());
4101
Douglas Gregora16548e2009-08-11 05:31:07 +00004102 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4103 T1, T2, E->getRParenLoc());
4104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
Douglas Gregora16548e2009-08-11 05:31:07 +00004106template<typename Derived>
4107Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004108TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4109 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004110 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4111 if (Cond.isInvalid())
4112 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004113
Douglas Gregora16548e2009-08-11 05:31:07 +00004114 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4115 if (LHS.isInvalid())
4116 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004117
Douglas Gregora16548e2009-08-11 05:31:07 +00004118 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4119 if (RHS.isInvalid())
4120 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 if (!getDerived().AlwaysRebuild() &&
4123 Cond.get() == E->getCond() &&
4124 LHS.get() == E->getLHS() &&
4125 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004126 return SemaRef.Owned(E->Retain());
4127
Douglas Gregora16548e2009-08-11 05:31:07 +00004128 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4129 move(Cond), move(LHS), move(RHS),
4130 E->getRParenLoc());
4131}
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004134Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004135TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4136 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004137 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004138}
4139
4140template<typename Derived>
4141Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004142TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4143 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004144 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4145 if (Callee.isInvalid())
4146 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004147
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004148 OwningExprResult First
4149 = getDerived().TransformExpr(E->getArg(0),
4150 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 if (First.isInvalid())
4152 return SemaRef.ExprError();
4153
4154 OwningExprResult Second(SemaRef);
4155 if (E->getNumArgs() == 2) {
4156 Second = getDerived().TransformExpr(E->getArg(1));
4157 if (Second.isInvalid())
4158 return SemaRef.ExprError();
4159 }
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161 if (!getDerived().AlwaysRebuild() &&
4162 Callee.get() == E->getCallee() &&
4163 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004164 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4165 return SemaRef.Owned(E->Retain());
4166
Douglas Gregora16548e2009-08-11 05:31:07 +00004167 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4168 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004169 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 move(First),
4171 move(Second));
4172}
Mike Stump11289f42009-09-09 15:08:12 +00004173
Douglas Gregora16548e2009-08-11 05:31:07 +00004174template<typename Derived>
4175Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004176TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4177 bool isAddressOfOperand) {
4178 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004179}
Mike Stump11289f42009-09-09 15:08:12 +00004180
Douglas Gregora16548e2009-08-11 05:31:07 +00004181template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004182Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004183TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4184 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 QualType ExplicitTy;
4186 {
4187 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004188 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4190 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4193 if (ExplicitTy.isNull())
4194 return SemaRef.ExprError();
4195 }
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregora16548e2009-08-11 05:31:07 +00004197 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4198 if (SubExpr.isInvalid())
4199 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004200
Douglas Gregora16548e2009-08-11 05:31:07 +00004201 if (!getDerived().AlwaysRebuild() &&
4202 ExplicitTy == E->getTypeAsWritten() &&
4203 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004204 return SemaRef.Owned(E->Retain());
4205
Douglas Gregora16548e2009-08-11 05:31:07 +00004206 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004207 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4209 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4210 SourceLocation FakeRParenLoc
4211 = SemaRef.PP.getLocForEndOfToken(
4212 E->getSubExpr()->getSourceRange().getEnd());
4213 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004214 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004215 FakeLAngleLoc,
4216 ExplicitTy,
4217 FakeRAngleLoc,
4218 FakeRAngleLoc,
4219 move(SubExpr),
4220 FakeRParenLoc);
4221}
Mike Stump11289f42009-09-09 15:08:12 +00004222
Douglas Gregora16548e2009-08-11 05:31:07 +00004223template<typename Derived>
4224Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004225TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4226 bool isAddressOfOperand) {
4227 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
4230template<typename Derived>
4231Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004232TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4233 bool isAddressOfOperand) {
4234 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004235}
4236
Douglas Gregora16548e2009-08-11 05:31:07 +00004237template<typename Derived>
4238Sema::OwningExprResult
4239TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004240 CXXReinterpretCastExpr *E,
4241 bool isAddressOfOperand) {
4242 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004243}
Mike Stump11289f42009-09-09 15:08:12 +00004244
Douglas Gregora16548e2009-08-11 05:31:07 +00004245template<typename Derived>
4246Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004247TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4248 bool isAddressOfOperand) {
4249 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004250}
Mike Stump11289f42009-09-09 15:08:12 +00004251
Douglas Gregora16548e2009-08-11 05:31:07 +00004252template<typename Derived>
4253Sema::OwningExprResult
4254TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004255 CXXFunctionalCastExpr *E,
4256 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004257 QualType ExplicitTy;
4258 {
4259 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004260
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4262 if (ExplicitTy.isNull())
4263 return SemaRef.ExprError();
4264 }
Mike Stump11289f42009-09-09 15:08:12 +00004265
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4267 if (SubExpr.isInvalid())
4268 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004269
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 if (!getDerived().AlwaysRebuild() &&
4271 ExplicitTy == E->getTypeAsWritten() &&
4272 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004273 return SemaRef.Owned(E->Retain());
4274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 // FIXME: The end of the type's source range is wrong
4276 return getDerived().RebuildCXXFunctionalCastExpr(
4277 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4278 ExplicitTy,
4279 /*FIXME:*/E->getSubExpr()->getLocStart(),
4280 move(SubExpr),
4281 E->getRParenLoc());
4282}
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284template<typename Derived>
4285Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004286TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4287 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 if (E->isTypeOperand()) {
4289 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 QualType T = getDerived().TransformType(E->getTypeOperand());
4292 if (T.isNull())
4293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() &&
4296 T == E->getTypeOperand())
4297 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4300 /*FIXME:*/E->getLocStart(),
4301 T,
4302 E->getLocEnd());
4303 }
Mike Stump11289f42009-09-09 15:08:12 +00004304
Douglas Gregora16548e2009-08-11 05:31:07 +00004305 // We don't know whether the expression is potentially evaluated until
4306 // after we perform semantic analysis, so the expression is potentially
4307 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004308 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004309 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4312 if (SubExpr.isInvalid())
4313 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 if (!getDerived().AlwaysRebuild() &&
4316 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004317 return SemaRef.Owned(E->Retain());
4318
Douglas Gregora16548e2009-08-11 05:31:07 +00004319 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4320 /*FIXME:*/E->getLocStart(),
4321 move(SubExpr),
4322 E->getLocEnd());
4323}
4324
4325template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004326Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004327TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4328 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004329 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004330}
Mike Stump11289f42009-09-09 15:08:12 +00004331
Douglas Gregora16548e2009-08-11 05:31:07 +00004332template<typename Derived>
4333Sema::OwningExprResult
4334TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004335 CXXNullPtrLiteralExpr *E,
4336 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004337 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004338}
Mike Stump11289f42009-09-09 15:08:12 +00004339
Douglas Gregora16548e2009-08-11 05:31:07 +00004340template<typename Derived>
4341Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004342TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4343 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004345
Douglas Gregora16548e2009-08-11 05:31:07 +00004346 QualType T = getDerived().TransformType(E->getType());
4347 if (T.isNull())
4348 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350 if (!getDerived().AlwaysRebuild() &&
4351 T == E->getType())
4352 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004353
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4355}
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregora16548e2009-08-11 05:31:07 +00004357template<typename Derived>
4358Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004359TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4360 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4362 if (SubExpr.isInvalid())
4363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 if (!getDerived().AlwaysRebuild() &&
4366 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004367 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004368
4369 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4370}
Mike Stump11289f42009-09-09 15:08:12 +00004371
Douglas Gregora16548e2009-08-11 05:31:07 +00004372template<typename Derived>
4373Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004374TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4375 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004376 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4378 if (!Param)
4379 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 if (getDerived().AlwaysRebuild() &&
4382 Param == E->getParam())
4383 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004384
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 return getDerived().RebuildCXXDefaultArgExpr(Param);
4386}
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388template<typename Derived>
4389Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004390TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4391 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4393
4394 QualType T = getDerived().TransformType(E->getType());
4395 if (T.isNull())
4396 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 if (!getDerived().AlwaysRebuild() &&
4399 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004400 return SemaRef.Owned(E->Retain());
4401
4402 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 /*FIXME:*/E->getTypeBeginLoc(),
4404 T,
4405 E->getRParenLoc());
4406}
Mike Stump11289f42009-09-09 15:08:12 +00004407
Douglas Gregora16548e2009-08-11 05:31:07 +00004408template<typename Derived>
4409Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004410TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E,
4411 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004412 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00004413 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 if (!Var)
4415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004418 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00004419 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004420
4421 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004422 /*FIXME:*/E->getStartLoc(),
4423 Var);
4424}
Mike Stump11289f42009-09-09 15:08:12 +00004425
Douglas Gregora16548e2009-08-11 05:31:07 +00004426template<typename Derived>
4427Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004428TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4429 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 // Transform the type that we're allocating
4431 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4432 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4433 if (AllocType.isNull())
4434 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004435
Douglas Gregora16548e2009-08-11 05:31:07 +00004436 // Transform the size of the array we're allocating (if any).
4437 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4438 if (ArraySize.isInvalid())
4439 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004440
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 // Transform the placement arguments (if any).
4442 bool ArgumentChanged = false;
4443 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4444 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4445 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4446 if (Arg.isInvalid())
4447 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004448
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4450 PlacementArgs.push_back(Arg.take());
4451 }
Mike Stump11289f42009-09-09 15:08:12 +00004452
Douglas Gregorebe10102009-08-20 07:17:43 +00004453 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004454 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4455 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4456 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4457 if (Arg.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4461 ConstructorArgs.push_back(Arg.take());
4462 }
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464 if (!getDerived().AlwaysRebuild() &&
4465 AllocType == E->getAllocatedType() &&
4466 ArraySize.get() == E->getArraySize() &&
4467 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004468 return SemaRef.Owned(E->Retain());
4469
Douglas Gregora16548e2009-08-11 05:31:07 +00004470 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4471 E->isGlobalNew(),
4472 /*FIXME:*/E->getLocStart(),
4473 move_arg(PlacementArgs),
4474 /*FIXME:*/E->getLocStart(),
4475 E->isParenTypeId(),
4476 AllocType,
4477 /*FIXME:*/E->getLocStart(),
4478 /*FIXME:*/SourceRange(),
4479 move(ArraySize),
4480 /*FIXME:*/E->getLocStart(),
4481 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004482 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004483}
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485template<typename Derived>
4486Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004487TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4488 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4490 if (Operand.isInvalid())
4491 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004492
Douglas Gregora16548e2009-08-11 05:31:07 +00004493 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004494 Operand.get() == E->getArgument())
4495 return SemaRef.Owned(E->Retain());
4496
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4498 E->isGlobalDelete(),
4499 E->isArrayForm(),
4500 move(Operand));
4501}
Mike Stump11289f42009-09-09 15:08:12 +00004502
Douglas Gregora16548e2009-08-11 05:31:07 +00004503template<typename Derived>
4504Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004505TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004506 CXXPseudoDestructorExpr *E,
4507 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004508 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4509 if (Base.isInvalid())
4510 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregorad8a3362009-09-04 17:36:40 +00004512 NestedNameSpecifier *Qualifier
4513 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4514 E->getQualifierRange());
4515 if (E->getQualifier() && !Qualifier)
4516 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004517
Douglas Gregorad8a3362009-09-04 17:36:40 +00004518 QualType DestroyedType;
4519 {
4520 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4521 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4522 if (DestroyedType.isNull())
4523 return SemaRef.ExprError();
4524 }
Mike Stump11289f42009-09-09 15:08:12 +00004525
Douglas Gregorad8a3362009-09-04 17:36:40 +00004526 if (!getDerived().AlwaysRebuild() &&
4527 Base.get() == E->getBase() &&
4528 Qualifier == E->getQualifier() &&
4529 DestroyedType == E->getDestroyedType())
4530 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004531
Douglas Gregorad8a3362009-09-04 17:36:40 +00004532 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4533 E->getOperatorLoc(),
4534 E->isArrow(),
4535 E->getDestroyedTypeLoc(),
4536 DestroyedType,
4537 Qualifier,
4538 E->getQualifierRange());
4539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregorad8a3362009-09-04 17:36:40 +00004541template<typename Derived>
4542Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004543TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCalle66edc12009-11-24 19:00:30 +00004544 UnresolvedLookupExpr *Old,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004545 bool isAddressOfOperand) {
John McCalle66edc12009-11-24 19:00:30 +00004546 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4547
4548 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4549 Sema::LookupOrdinaryName);
4550
4551 // Transform all the decls.
4552 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4553 E = Old->decls_end(); I != E; ++I) {
4554 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4555 if (!InstD)
4556 return SemaRef.ExprError();
4557
4558 // Expand using declarations.
4559 if (isa<UsingDecl>(InstD)) {
4560 UsingDecl *UD = cast<UsingDecl>(InstD);
4561 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4562 E = UD->shadow_end(); I != E; ++I)
4563 R.addDecl(*I);
4564 continue;
4565 }
4566
4567 R.addDecl(InstD);
4568 }
4569
4570 // Resolve a kind, but don't do any further analysis. If it's
4571 // ambiguous, the callee needs to deal with it.
4572 R.resolveKind();
4573
4574 // Rebuild the nested-name qualifier, if present.
4575 CXXScopeSpec SS;
4576 NestedNameSpecifier *Qualifier = 0;
4577 if (Old->getQualifier()) {
4578 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4579 Old->getQualifierRange());
4580 if (!Qualifier)
4581 return SemaRef.ExprError();
4582
4583 SS.setScopeRep(Qualifier);
4584 SS.setRange(Old->getQualifierRange());
4585 }
4586
4587 // If we have no template arguments, it's a normal declaration name.
4588 if (!Old->hasExplicitTemplateArgs())
4589 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4590
4591 // If we have template arguments, rebuild them, then rebuild the
4592 // templateid expression.
4593 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4594 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4595 TemplateArgumentLoc Loc;
4596 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4597 return SemaRef.ExprError();
4598 TransArgs.addArgument(Loc);
4599 }
4600
4601 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4602 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004603}
Mike Stump11289f42009-09-09 15:08:12 +00004604
Douglas Gregora16548e2009-08-11 05:31:07 +00004605template<typename Derived>
4606Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004607TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4608 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004610
Douglas Gregora16548e2009-08-11 05:31:07 +00004611 QualType T = getDerived().TransformType(E->getQueriedType());
4612 if (T.isNull())
4613 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004614
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 if (!getDerived().AlwaysRebuild() &&
4616 T == E->getQueriedType())
4617 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 // FIXME: Bad location information
4620 SourceLocation FakeLParenLoc
4621 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004622
4623 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 E->getLocStart(),
4625 /*FIXME:*/FakeLParenLoc,
4626 T,
4627 E->getLocEnd());
4628}
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregora16548e2009-08-11 05:31:07 +00004630template<typename Derived>
4631Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004632TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4633 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004634 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004636 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4637 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 if (!NNS)
4639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004640
4641 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004642 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4643 if (!Name)
4644 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004645
John McCalle66edc12009-11-24 19:00:30 +00004646 if (!E->hasExplicitTemplateArgs()) {
4647 if (!getDerived().AlwaysRebuild() &&
4648 NNS == E->getQualifier() &&
4649 Name == E->getDeclName())
4650 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004651
John McCalle66edc12009-11-24 19:00:30 +00004652 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4653 E->getQualifierRange(),
4654 Name, E->getLocation(),
4655 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004656 }
John McCall6b51f282009-11-23 01:53:49 +00004657
4658 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004660 TemplateArgumentLoc Loc;
4661 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004663 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004664 }
4665
John McCalle66edc12009-11-24 19:00:30 +00004666 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4667 E->getQualifierRange(),
4668 Name, E->getLocation(),
4669 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004670}
4671
4672template<typename Derived>
4673Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004674TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4675 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4677
4678 QualType T = getDerived().TransformType(E->getType());
4679 if (T.isNull())
4680 return SemaRef.ExprError();
4681
4682 CXXConstructorDecl *Constructor
4683 = cast_or_null<CXXConstructorDecl>(
4684 getDerived().TransformDecl(E->getConstructor()));
4685 if (!Constructor)
4686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 bool ArgumentChanged = false;
4689 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004690 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004691 ArgEnd = E->arg_end();
4692 Arg != ArgEnd; ++Arg) {
4693 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4694 if (TransArg.isInvalid())
4695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4698 Args.push_back(TransArg.takeAs<Expr>());
4699 }
4700
4701 if (!getDerived().AlwaysRebuild() &&
4702 T == E->getType() &&
4703 Constructor == E->getConstructor() &&
4704 !ArgumentChanged)
4705 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4708 move_arg(Args));
4709}
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregora16548e2009-08-11 05:31:07 +00004711/// \brief Transform a C++ temporary-binding expression.
4712///
Mike Stump11289f42009-09-09 15:08:12 +00004713/// The transformation of a temporary-binding expression always attempts to
4714/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004715/// subexpression itself did not change, because the temporary variable itself
4716/// must be unique.
4717template<typename Derived>
4718Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004719TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4720 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004721 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4722 if (SubExpr.isInvalid())
4723 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004724
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4726}
Mike Stump11289f42009-09-09 15:08:12 +00004727
4728/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004729/// be destroyed after the expression is evaluated.
4730///
Mike Stump11289f42009-09-09 15:08:12 +00004731/// The transformation of a full expression always attempts to build a new
4732/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004733/// subexpression itself did not change, because it will need to capture the
4734/// the new temporary variables introduced in the subexpression.
4735template<typename Derived>
4736Sema::OwningExprResult
4737TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004738 CXXExprWithTemporaries *E,
4739 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4741 if (SubExpr.isInvalid())
4742 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004743
Douglas Gregora16548e2009-08-11 05:31:07 +00004744 return SemaRef.Owned(
4745 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4746 E->shouldDestroyTemporaries()));
4747}
Mike Stump11289f42009-09-09 15:08:12 +00004748
Douglas Gregora16548e2009-08-11 05:31:07 +00004749template<typename Derived>
4750Sema::OwningExprResult
4751TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004752 CXXTemporaryObjectExpr *E,
4753 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004754 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4755 QualType T = getDerived().TransformType(E->getType());
4756 if (T.isNull())
4757 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 CXXConstructorDecl *Constructor
4760 = cast_or_null<CXXConstructorDecl>(
4761 getDerived().TransformDecl(E->getConstructor()));
4762 if (!Constructor)
4763 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 bool ArgumentChanged = false;
4766 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4767 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004768 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004769 ArgEnd = E->arg_end();
4770 Arg != ArgEnd; ++Arg) {
4771 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4772 if (TransArg.isInvalid())
4773 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4776 Args.push_back((Expr *)TransArg.release());
4777 }
Mike Stump11289f42009-09-09 15:08:12 +00004778
Douglas Gregora16548e2009-08-11 05:31:07 +00004779 if (!getDerived().AlwaysRebuild() &&
4780 T == E->getType() &&
4781 Constructor == E->getConstructor() &&
4782 !ArgumentChanged)
4783 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 // FIXME: Bogus location information
4786 SourceLocation CommaLoc;
4787 if (Args.size() > 1) {
4788 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004789 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4791 }
4792 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4793 T,
4794 /*FIXME:*/E->getTypeBeginLoc(),
4795 move_arg(Args),
4796 &CommaLoc,
4797 E->getLocEnd());
4798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800template<typename Derived>
4801Sema::OwningExprResult
4802TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004803 CXXUnresolvedConstructExpr *E,
4804 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004805 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4806 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4807 if (T.isNull())
4808 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004809
Douglas Gregora16548e2009-08-11 05:31:07 +00004810 bool ArgumentChanged = false;
4811 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4812 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4813 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4814 ArgEnd = E->arg_end();
4815 Arg != ArgEnd; ++Arg) {
4816 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4817 if (TransArg.isInvalid())
4818 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004819
Douglas Gregora16548e2009-08-11 05:31:07 +00004820 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4821 FakeCommaLocs.push_back(
4822 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4823 Args.push_back(TransArg.takeAs<Expr>());
4824 }
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregora16548e2009-08-11 05:31:07 +00004826 if (!getDerived().AlwaysRebuild() &&
4827 T == E->getTypeAsWritten() &&
4828 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004829 return SemaRef.Owned(E->Retain());
4830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 // FIXME: we're faking the locations of the commas
4832 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4833 T,
4834 E->getLParenLoc(),
4835 move_arg(Args),
4836 FakeCommaLocs.data(),
4837 E->getRParenLoc());
4838}
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840template<typename Derived>
4841Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004842TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4843 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004844 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004845 // Transform the base of the expression.
4846 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4847 if (Base.isInvalid())
4848 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004849
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004850 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004851 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004852 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004853 E->getOperatorLoc(),
4854 E->isArrow()? tok::arrow : tok::period,
4855 ObjectType);
4856 if (Base.isInvalid())
4857 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004858
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004859 // Transform the first part of the nested-name-specifier that qualifies
4860 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004861 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004862 = getDerived().TransformFirstQualifierInScope(
4863 E->getFirstQualifierFoundInScope(),
4864 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004866 NestedNameSpecifier *Qualifier = 0;
4867 if (E->getQualifier()) {
4868 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4869 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004870 QualType::getFromOpaquePtr(ObjectType),
4871 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004872 if (!Qualifier)
4873 return SemaRef.ExprError();
4874 }
Mike Stump11289f42009-09-09 15:08:12 +00004875
4876 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004877 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4878 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004879 if (!Name)
4880 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregor308047d2009-09-09 00:23:06 +00004882 if (!E->hasExplicitTemplateArgumentList()) {
4883 // This is a reference to a member without an explicitly-specified
4884 // template argument list. Optimize for this common case.
4885 if (!getDerived().AlwaysRebuild() &&
4886 Base.get() == E->getBase() &&
4887 Qualifier == E->getQualifier() &&
4888 Name == E->getMember() &&
4889 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004890 return SemaRef.Owned(E->Retain());
4891
John McCall8cd78132009-11-19 22:55:06 +00004892 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00004893 E->isArrow(),
4894 E->getOperatorLoc(),
4895 Qualifier,
4896 E->getQualifierRange(),
4897 Name,
4898 E->getMemberLoc(),
4899 FirstQualifierInScope);
4900 }
4901
4902 // FIXME: This is an ugly hack, which forces the same template name to
4903 // be looked up multiple times. Yuck!
Douglas Gregor71395fa2009-11-04 00:56:37 +00004904 TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName());
4905 TemplateName OrigTemplateName;
4906 if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
4907 OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II);
4908 else
4909 OrigTemplateName
4910 = SemaRef.Context.getDependentTemplateName(0,
4911 Name.getCXXOverloadedOperator());
Mike Stump11289f42009-09-09 15:08:12 +00004912
4913 TemplateName Template
4914 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004915 QualType::getFromOpaquePtr(ObjectType));
4916 if (Template.isNull())
4917 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004918
John McCall6b51f282009-11-23 01:53:49 +00004919 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004920 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004921 TemplateArgumentLoc Loc;
4922 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004923 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004924 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004925 }
Mike Stump11289f42009-09-09 15:08:12 +00004926
John McCall8cd78132009-11-19 22:55:06 +00004927 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregora16548e2009-08-11 05:31:07 +00004928 E->isArrow(),
4929 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004930 Qualifier,
4931 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004932 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004933 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004934 FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00004935 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004936}
4937
4938template<typename Derived>
4939Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004940TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
4941 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004942 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004943}
4944
Mike Stump11289f42009-09-09 15:08:12 +00004945template<typename Derived>
4946Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004947TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
4948 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 // FIXME: poor source location
4950 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4951 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4952 if (EncodedType.isNull())
4953 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004954
Douglas Gregora16548e2009-08-11 05:31:07 +00004955 if (!getDerived().AlwaysRebuild() &&
4956 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004957 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004958
4959 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4960 EncodedType,
4961 E->getRParenLoc());
4962}
Mike Stump11289f42009-09-09 15:08:12 +00004963
Douglas Gregora16548e2009-08-11 05:31:07 +00004964template<typename Derived>
4965Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004966TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
4967 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 // FIXME: Implement this!
4969 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004970 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004971}
4972
Mike Stump11289f42009-09-09 15:08:12 +00004973template<typename Derived>
4974Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004975TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
4976 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004977 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004978}
4979
Mike Stump11289f42009-09-09 15:08:12 +00004980template<typename Derived>
4981Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004982TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
4983 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004984 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004985 = cast_or_null<ObjCProtocolDecl>(
4986 getDerived().TransformDecl(E->getProtocol()));
4987 if (!Protocol)
4988 return SemaRef.ExprError();
4989
4990 if (!getDerived().AlwaysRebuild() &&
4991 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00004992 return SemaRef.Owned(E->Retain());
4993
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 return getDerived().RebuildObjCProtocolExpr(Protocol,
4995 E->getAtLoc(),
4996 /*FIXME:*/E->getAtLoc(),
4997 /*FIXME:*/E->getAtLoc(),
4998 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004999
Douglas Gregora16548e2009-08-11 05:31:07 +00005000}
5001
Mike Stump11289f42009-09-09 15:08:12 +00005002template<typename Derived>
5003Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005004TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
5005 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005006 // FIXME: Implement this!
5007 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005008 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005009}
5010
Mike Stump11289f42009-09-09 15:08:12 +00005011template<typename Derived>
5012Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005013TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
5014 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 // FIXME: Implement this!
5016 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005017 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005018}
5019
Mike Stump11289f42009-09-09 15:08:12 +00005020template<typename Derived>
5021Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005022TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005023 ObjCImplicitSetterGetterRefExpr *E,
5024 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 // FIXME: Implement this!
5026 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005027 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005028}
5029
Mike Stump11289f42009-09-09 15:08:12 +00005030template<typename Derived>
5031Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005032TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5033 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 // FIXME: Implement this!
5035 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005036 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005037}
5038
Mike Stump11289f42009-09-09 15:08:12 +00005039template<typename Derived>
5040Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005041TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5042 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005043 // FIXME: Implement this!
5044 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005045 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005046}
5047
Mike Stump11289f42009-09-09 15:08:12 +00005048template<typename Derived>
5049Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005050TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5051 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 bool ArgumentChanged = false;
5053 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5054 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5055 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5056 if (SubExpr.isInvalid())
5057 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005058
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5060 SubExprs.push_back(SubExpr.takeAs<Expr>());
5061 }
Mike Stump11289f42009-09-09 15:08:12 +00005062
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 if (!getDerived().AlwaysRebuild() &&
5064 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005065 return SemaRef.Owned(E->Retain());
5066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5068 move_arg(SubExprs),
5069 E->getRParenLoc());
5070}
5071
Mike Stump11289f42009-09-09 15:08:12 +00005072template<typename Derived>
5073Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005074TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5075 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005076 // FIXME: Implement this!
5077 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005078 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005079}
5080
Mike Stump11289f42009-09-09 15:08:12 +00005081template<typename Derived>
5082Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005083TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5084 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005085 // FIXME: Implement this!
5086 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005087 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005088}
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005091// Type reconstruction
5092//===----------------------------------------------------------------------===//
5093
Mike Stump11289f42009-09-09 15:08:12 +00005094template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005095QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5096 SourceLocation Star) {
5097 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005098 getDerived().getBaseEntity());
5099}
5100
Mike Stump11289f42009-09-09 15:08:12 +00005101template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005102QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5103 SourceLocation Star) {
5104 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005105 getDerived().getBaseEntity());
5106}
5107
Mike Stump11289f42009-09-09 15:08:12 +00005108template<typename Derived>
5109QualType
John McCall70dd5f62009-10-30 00:06:24 +00005110TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5111 bool WrittenAsLValue,
5112 SourceLocation Sigil) {
5113 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5114 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005115}
5116
5117template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005118QualType
John McCall70dd5f62009-10-30 00:06:24 +00005119TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5120 QualType ClassType,
5121 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005122 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005123 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005124}
5125
5126template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005127QualType
John McCall70dd5f62009-10-30 00:06:24 +00005128TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5129 SourceLocation Sigil) {
5130 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005131 getDerived().getBaseEntity());
5132}
5133
5134template<typename Derived>
5135QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005136TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5137 ArrayType::ArraySizeModifier SizeMod,
5138 const llvm::APInt *Size,
5139 Expr *SizeExpr,
5140 unsigned IndexTypeQuals,
5141 SourceRange BracketsRange) {
5142 if (SizeExpr || !Size)
5143 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5144 IndexTypeQuals, BracketsRange,
5145 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005146
5147 QualType Types[] = {
5148 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5149 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5150 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005151 };
5152 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5153 QualType SizeType;
5154 for (unsigned I = 0; I != NumTypes; ++I)
5155 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5156 SizeType = Types[I];
5157 break;
5158 }
Mike Stump11289f42009-09-09 15:08:12 +00005159
Douglas Gregord6ff3322009-08-04 16:50:30 +00005160 if (SizeType.isNull())
5161 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregord6ff3322009-08-04 16:50:30 +00005163 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005164 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005165 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005166 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005167}
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005170QualType
5171TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005172 ArrayType::ArraySizeModifier SizeMod,
5173 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005174 unsigned IndexTypeQuals,
5175 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005176 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005177 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005178}
5179
5180template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005181QualType
Mike Stump11289f42009-09-09 15:08:12 +00005182TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005183 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005184 unsigned IndexTypeQuals,
5185 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005186 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005187 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005188}
Mike Stump11289f42009-09-09 15:08:12 +00005189
Douglas Gregord6ff3322009-08-04 16:50:30 +00005190template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005191QualType
5192TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005193 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005194 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005195 unsigned IndexTypeQuals,
5196 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005197 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005198 SizeExpr.takeAs<Expr>(),
5199 IndexTypeQuals, BracketsRange);
5200}
5201
5202template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005203QualType
5204TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005205 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005206 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005207 unsigned IndexTypeQuals,
5208 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005209 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005210 SizeExpr.takeAs<Expr>(),
5211 IndexTypeQuals, BracketsRange);
5212}
5213
5214template<typename Derived>
5215QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5216 unsigned NumElements) {
5217 // FIXME: semantic checking!
5218 return SemaRef.Context.getVectorType(ElementType, NumElements);
5219}
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221template<typename Derived>
5222QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5223 unsigned NumElements,
5224 SourceLocation AttributeLoc) {
5225 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5226 NumElements, true);
5227 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005228 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005229 AttributeLoc);
5230 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5231 AttributeLoc);
5232}
Mike Stump11289f42009-09-09 15:08:12 +00005233
Douglas Gregord6ff3322009-08-04 16:50:30 +00005234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005235QualType
5236TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005237 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005238 SourceLocation AttributeLoc) {
5239 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5240}
Mike Stump11289f42009-09-09 15:08:12 +00005241
Douglas Gregord6ff3322009-08-04 16:50:30 +00005242template<typename Derived>
5243QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005244 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005246 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005247 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005248 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249 Quals,
5250 getDerived().getBaseLocation(),
5251 getDerived().getBaseEntity());
5252}
Mike Stump11289f42009-09-09 15:08:12 +00005253
Douglas Gregord6ff3322009-08-04 16:50:30 +00005254template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005255QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5256 return SemaRef.Context.getFunctionNoProtoType(T);
5257}
5258
5259template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005260QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005261 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5262}
5263
5264template<typename Derived>
5265QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5266 return SemaRef.Context.getTypeOfType(Underlying);
5267}
5268
5269template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005270QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005271 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5272}
5273
5274template<typename Derived>
5275QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005276 TemplateName Template,
5277 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005278 const TemplateArgumentListInfo &TemplateArgs) {
5279 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005280}
Mike Stump11289f42009-09-09 15:08:12 +00005281
Douglas Gregor1135c352009-08-06 05:28:30 +00005282template<typename Derived>
5283NestedNameSpecifier *
5284TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5285 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005286 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005287 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005288 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005289 CXXScopeSpec SS;
5290 // FIXME: The source location information is all wrong.
5291 SS.setRange(Range);
5292 SS.setScopeRep(Prefix);
5293 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005294 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005295 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005296 ObjectType,
5297 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005298 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005299}
5300
5301template<typename Derived>
5302NestedNameSpecifier *
5303TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5304 SourceRange Range,
5305 NamespaceDecl *NS) {
5306 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5307}
5308
5309template<typename Derived>
5310NestedNameSpecifier *
5311TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5312 SourceRange Range,
5313 bool TemplateKW,
5314 QualType T) {
5315 if (T->isDependentType() || T->isRecordType() ||
5316 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005317 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005318 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5319 T.getTypePtr());
5320 }
Mike Stump11289f42009-09-09 15:08:12 +00005321
Douglas Gregor1135c352009-08-06 05:28:30 +00005322 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5323 return 0;
5324}
Mike Stump11289f42009-09-09 15:08:12 +00005325
Douglas Gregor71dc5092009-08-06 06:41:21 +00005326template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005327TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005328TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5329 bool TemplateKW,
5330 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005331 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005332 Template);
5333}
5334
5335template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005336TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005337TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005338 const IdentifierInfo &II,
5339 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005340 CXXScopeSpec SS;
5341 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005342 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005343 UnqualifiedId Name;
5344 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005345 return getSema().ActOnDependentTemplateName(
5346 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005347 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005348 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005349 ObjectType.getAsOpaquePtr(),
5350 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005351 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005352}
Mike Stump11289f42009-09-09 15:08:12 +00005353
Douglas Gregora16548e2009-08-11 05:31:07 +00005354template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005355TemplateName
5356TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5357 OverloadedOperatorKind Operator,
5358 QualType ObjectType) {
5359 CXXScopeSpec SS;
5360 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5361 SS.setScopeRep(Qualifier);
5362 UnqualifiedId Name;
5363 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5364 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5365 Operator, SymbolLocations);
5366 return getSema().ActOnDependentTemplateName(
5367 /*FIXME:*/getDerived().getBaseLocation(),
5368 SS,
5369 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005370 ObjectType.getAsOpaquePtr(),
5371 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005372 .template getAsVal<TemplateName>();
5373}
5374
5375template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005376Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005377TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5378 SourceLocation OpLoc,
5379 ExprArg Callee,
5380 ExprArg First,
5381 ExprArg Second) {
5382 Expr *FirstExpr = (Expr *)First.get();
5383 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005384 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005385 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005386
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005388 if (Op == OO_Subscript) {
5389 if (!FirstExpr->getType()->isOverloadableType() &&
5390 !SecondExpr->getType()->isOverloadableType())
5391 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005392 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005393 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005394 } else if (Op == OO_Arrow) {
5395 // -> is never a builtin operation.
5396 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005397 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 if (!FirstExpr->getType()->isOverloadableType()) {
5399 // The argument is not of overloadable type, so try to create a
5400 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005401 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005402 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5405 }
5406 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005407 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005408 !SecondExpr->getType()->isOverloadableType()) {
5409 // Neither of the arguments is an overloadable type, so try to
5410 // create a built-in binary operation.
5411 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005412 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5414 if (Result.isInvalid())
5415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregora16548e2009-08-11 05:31:07 +00005417 First.release();
5418 Second.release();
5419 return move(Result);
5420 }
5421 }
Mike Stump11289f42009-09-09 15:08:12 +00005422
5423 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 // used during overload resolution.
5425 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005426
John McCalld14a8642009-11-21 08:51:07 +00005427 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5428 assert(ULE->requiresADL());
5429
5430 // FIXME: Do we have to check
5431 // IsAcceptableNonMemberOperatorCandidate for each of these?
5432 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5433 E = ULE->decls_end(); I != E; ++I)
5434 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5435 } else {
5436 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5437 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5438 }
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregora16548e2009-08-11 05:31:07 +00005440 // Add any functions found via argument-dependent lookup.
5441 Expr *Args[2] = { FirstExpr, SecondExpr };
5442 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005443 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005444 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005445 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5446 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005447
Douglas Gregora16548e2009-08-11 05:31:07 +00005448 // Create the overloaded operator invocation for unary operators.
5449 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005450 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5452 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5453 }
Mike Stump11289f42009-09-09 15:08:12 +00005454
Sebastian Redladba46e2009-10-29 20:17:01 +00005455 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005456 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5457 OpLoc,
5458 move(First),
5459 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005460
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005462 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005463 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005464 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005465 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5466 if (Result.isInvalid())
5467 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005468
Douglas Gregora16548e2009-08-11 05:31:07 +00005469 First.release();
5470 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005471 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005472}
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregord6ff3322009-08-04 16:50:30 +00005474} // end namespace clang
5475
5476#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H