blob: 202e16e31e36d18fa6d5a7317c7968f6572af449 [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
Douglas Gregor680f8612009-11-24 21:15:44 +00003142 OwningExprResult Cond(SemaRef);
3143 VarDecl *ConditionVar = 0;
3144 if (S->getConditionVariable()) {
3145 ConditionVar
3146 = cast_or_null<VarDecl>(
3147 getDerived().TransformDefinition(S->getConditionVariable()));
3148 if (!ConditionVar)
3149 return SemaRef.StmtError();
3150
3151 Cond = getSema().CheckConditionVariable(ConditionVar);
3152 } else
3153 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorebe10102009-08-20 07:17:43 +00003154 if (Cond.isInvalid())
3155 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003156
Douglas Gregorebe10102009-08-20 07:17:43 +00003157 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003158
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 // Transform the body
3160 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3161 if (Body.isInvalid())
3162 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003163
Douglas Gregorebe10102009-08-20 07:17:43 +00003164 if (!getDerived().AlwaysRebuild() &&
3165 FullCond->get() == S->getCond() &&
3166 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003167 return SemaRef.Owned(S->Retain());
3168
Douglas Gregorebe10102009-08-20 07:17:43 +00003169 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, move(Body));
3170}
Mike Stump11289f42009-09-09 15:08:12 +00003171
Douglas Gregorebe10102009-08-20 07:17:43 +00003172template<typename Derived>
3173Sema::OwningStmtResult
3174TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3175 // Transform the condition
3176 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3177 if (Cond.isInvalid())
3178 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003179
Douglas Gregorebe10102009-08-20 07:17:43 +00003180 // Transform the body
3181 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3182 if (Body.isInvalid())
3183 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003184
Douglas Gregorebe10102009-08-20 07:17:43 +00003185 if (!getDerived().AlwaysRebuild() &&
3186 Cond.get() == S->getCond() &&
3187 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003188 return SemaRef.Owned(S->Retain());
3189
Douglas Gregorebe10102009-08-20 07:17:43 +00003190 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3191 /*FIXME:*/S->getWhileLoc(), move(Cond),
3192 S->getRParenLoc());
3193}
Mike Stump11289f42009-09-09 15:08:12 +00003194
Douglas Gregorebe10102009-08-20 07:17:43 +00003195template<typename Derived>
3196Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003197TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003198 // Transform the initialization statement
3199 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3200 if (Init.isInvalid())
3201 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003202
Douglas Gregorebe10102009-08-20 07:17:43 +00003203 // Transform the condition
3204 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3205 if (Cond.isInvalid())
3206 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003207
Douglas Gregorebe10102009-08-20 07:17:43 +00003208 // Transform the increment
3209 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3210 if (Inc.isInvalid())
3211 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregorebe10102009-08-20 07:17:43 +00003213 // Transform the body
3214 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3215 if (Body.isInvalid())
3216 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003217
Douglas Gregorebe10102009-08-20 07:17:43 +00003218 if (!getDerived().AlwaysRebuild() &&
3219 Init.get() == S->getInit() &&
3220 Cond.get() == S->getCond() &&
3221 Inc.get() == S->getInc() &&
3222 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003223 return SemaRef.Owned(S->Retain());
3224
Douglas Gregorebe10102009-08-20 07:17:43 +00003225 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
3226 move(Init), move(Cond), move(Inc),
3227 S->getRParenLoc(), move(Body));
3228}
3229
3230template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003231Sema::OwningStmtResult
3232TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003233 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003234 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 S->getLabel());
3236}
3237
3238template<typename Derived>
3239Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003240TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003241 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3242 if (Target.isInvalid())
3243 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003244
Douglas Gregorebe10102009-08-20 07:17:43 +00003245 if (!getDerived().AlwaysRebuild() &&
3246 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003247 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003248
3249 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3250 move(Target));
3251}
3252
3253template<typename Derived>
3254Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003255TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3256 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003257}
Mike Stump11289f42009-09-09 15:08:12 +00003258
Douglas Gregorebe10102009-08-20 07:17:43 +00003259template<typename Derived>
3260Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003261TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3262 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003263}
Mike Stump11289f42009-09-09 15:08:12 +00003264
Douglas Gregorebe10102009-08-20 07:17:43 +00003265template<typename Derived>
3266Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003267TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3269 if (Result.isInvalid())
3270 return SemaRef.StmtError();
3271
Mike Stump11289f42009-09-09 15:08:12 +00003272 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003273 // to tell whether the return type of the function has changed.
3274 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3275}
Mike Stump11289f42009-09-09 15:08:12 +00003276
Douglas Gregorebe10102009-08-20 07:17:43 +00003277template<typename Derived>
3278Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003279TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 bool DeclChanged = false;
3281 llvm::SmallVector<Decl *, 4> Decls;
3282 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3283 D != DEnd; ++D) {
3284 Decl *Transformed = getDerived().TransformDefinition(*D);
3285 if (!Transformed)
3286 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003287
Douglas Gregorebe10102009-08-20 07:17:43 +00003288 if (Transformed != *D)
3289 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003290
Douglas Gregorebe10102009-08-20 07:17:43 +00003291 Decls.push_back(Transformed);
3292 }
Mike Stump11289f42009-09-09 15:08:12 +00003293
Douglas Gregorebe10102009-08-20 07:17:43 +00003294 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003295 return SemaRef.Owned(S->Retain());
3296
3297 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 S->getStartLoc(), S->getEndLoc());
3299}
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301template<typename Derived>
3302Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003303TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003304 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003305 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003306}
3307
3308template<typename Derived>
3309Sema::OwningStmtResult
3310TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3311 // FIXME: Implement!
3312 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003313 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003314}
3315
3316
3317template<typename Derived>
3318Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003319TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003320 // FIXME: Implement this
3321 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003322 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003323}
Mike Stump11289f42009-09-09 15:08:12 +00003324
Douglas Gregorebe10102009-08-20 07:17:43 +00003325template<typename Derived>
3326Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003327TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003328 // FIXME: Implement this
3329 assert(false && "Cannot transform an Objective-C @catch statement");
3330 return SemaRef.Owned(S->Retain());
3331}
Mike Stump11289f42009-09-09 15:08:12 +00003332
Douglas Gregorebe10102009-08-20 07:17:43 +00003333template<typename Derived>
3334Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003335TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003336 // FIXME: Implement this
3337 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003338 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003339}
Mike Stump11289f42009-09-09 15:08:12 +00003340
Douglas Gregorebe10102009-08-20 07:17:43 +00003341template<typename Derived>
3342Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003343TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003344 // FIXME: Implement this
3345 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003346 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003347}
Mike Stump11289f42009-09-09 15:08:12 +00003348
Douglas Gregorebe10102009-08-20 07:17:43 +00003349template<typename Derived>
3350Sema::OwningStmtResult
3351TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003352 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003353 // FIXME: Implement this
3354 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003355 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003356}
3357
3358template<typename Derived>
3359Sema::OwningStmtResult
3360TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003361 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003362 // FIXME: Implement this
3363 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003364 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003365}
3366
3367
3368template<typename Derived>
3369Sema::OwningStmtResult
3370TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3371 // Transform the exception declaration, if any.
3372 VarDecl *Var = 0;
3373 if (S->getExceptionDecl()) {
3374 VarDecl *ExceptionDecl = S->getExceptionDecl();
3375 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3376 ExceptionDecl->getDeclName());
3377
3378 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3379 if (T.isNull())
3380 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003381
Douglas Gregorebe10102009-08-20 07:17:43 +00003382 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3383 T,
3384 ExceptionDecl->getDeclaratorInfo(),
3385 ExceptionDecl->getIdentifier(),
3386 ExceptionDecl->getLocation(),
3387 /*FIXME: Inaccurate*/
3388 SourceRange(ExceptionDecl->getLocation()));
3389 if (!Var || Var->isInvalidDecl()) {
3390 if (Var)
3391 Var->Destroy(SemaRef.Context);
3392 return SemaRef.StmtError();
3393 }
3394 }
Mike Stump11289f42009-09-09 15:08:12 +00003395
Douglas Gregorebe10102009-08-20 07:17:43 +00003396 // Transform the actual exception handler.
3397 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3398 if (Handler.isInvalid()) {
3399 if (Var)
3400 Var->Destroy(SemaRef.Context);
3401 return SemaRef.StmtError();
3402 }
Mike Stump11289f42009-09-09 15:08:12 +00003403
Douglas Gregorebe10102009-08-20 07:17:43 +00003404 if (!getDerived().AlwaysRebuild() &&
3405 !Var &&
3406 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003407 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003408
3409 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3410 Var,
3411 move(Handler));
3412}
Mike Stump11289f42009-09-09 15:08:12 +00003413
Douglas Gregorebe10102009-08-20 07:17:43 +00003414template<typename Derived>
3415Sema::OwningStmtResult
3416TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3417 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003418 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003419 = getDerived().TransformCompoundStmt(S->getTryBlock());
3420 if (TryBlock.isInvalid())
3421 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003422
Douglas Gregorebe10102009-08-20 07:17:43 +00003423 // Transform the handlers.
3424 bool HandlerChanged = false;
3425 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3426 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003427 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003428 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3429 if (Handler.isInvalid())
3430 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003431
Douglas Gregorebe10102009-08-20 07:17:43 +00003432 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3433 Handlers.push_back(Handler.takeAs<Stmt>());
3434 }
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436 if (!getDerived().AlwaysRebuild() &&
3437 TryBlock.get() == S->getTryBlock() &&
3438 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003439 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003440
3441 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003442 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003443}
Mike Stump11289f42009-09-09 15:08:12 +00003444
Douglas Gregorebe10102009-08-20 07:17:43 +00003445//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003446// Expression transformation
3447//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003448template<typename Derived>
3449Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003450TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E,
3451 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003452 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003453}
Mike Stump11289f42009-09-09 15:08:12 +00003454
3455template<typename Derived>
3456Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003457TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E,
3458 bool isAddressOfOperand) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003459 NestedNameSpecifier *Qualifier = 0;
3460 if (E->getQualifier()) {
3461 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3462 E->getQualifierRange());
3463 if (!Qualifier)
3464 return SemaRef.ExprError();
3465 }
3466
Mike Stump11289f42009-09-09 15:08:12 +00003467 NamedDecl *ND
Douglas Gregora16548e2009-08-11 05:31:07 +00003468 = dyn_cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getDecl()));
3469 if (!ND)
3470 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003471
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003472 if (!getDerived().AlwaysRebuild() &&
3473 Qualifier == E->getQualifier() &&
3474 ND == E->getDecl() &&
3475 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003476 return SemaRef.Owned(E->Retain());
3477
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003478 // FIXME: We're losing the explicit template arguments in this transformation.
3479
John McCall0ad16662009-10-29 08:12:44 +00003480 llvm::SmallVector<TemplateArgumentLoc, 4> TransArgs(E->getNumTemplateArgs());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003481 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall0ad16662009-10-29 08:12:44 +00003482 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I],
3483 TransArgs[I]))
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003484 return SemaRef.ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003485 }
3486
3487 // FIXME: Pass the qualifier/qualifier range along.
3488 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003489 ND, E->getLocation(),
3490 isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003491}
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregora16548e2009-08-11 05:31:07 +00003493template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003494Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003495TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E,
3496 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003497 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003498}
Mike Stump11289f42009-09-09 15:08:12 +00003499
Douglas Gregora16548e2009-08-11 05:31:07 +00003500template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003501Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003502TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E,
3503 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003504 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003505}
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregora16548e2009-08-11 05:31:07 +00003507template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003508Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003509TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E,
3510 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003511 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003512}
Mike Stump11289f42009-09-09 15:08:12 +00003513
Douglas Gregora16548e2009-08-11 05:31:07 +00003514template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003515Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003516TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E,
3517 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003518 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003519}
Mike Stump11289f42009-09-09 15:08:12 +00003520
Douglas Gregora16548e2009-08-11 05:31:07 +00003521template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003522Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003523TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E,
3524 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003525 return SemaRef.Owned(E->Retain());
3526}
3527
3528template<typename Derived>
3529Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003530TreeTransform<Derived>::TransformParenExpr(ParenExpr *E,
3531 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003532 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3533 if (SubExpr.isInvalid())
3534 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregora16548e2009-08-11 05:31:07 +00003536 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003537 return SemaRef.Owned(E->Retain());
3538
3539 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003540 E->getRParen());
3541}
3542
Mike Stump11289f42009-09-09 15:08:12 +00003543template<typename Derived>
3544Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003545TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E,
3546 bool isAddressOfOperand) {
3547 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr(),
3548 E->getOpcode() == UnaryOperator::AddrOf);
Douglas Gregora16548e2009-08-11 05:31:07 +00003549 if (SubExpr.isInvalid())
3550 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003551
Douglas Gregora16548e2009-08-11 05:31:07 +00003552 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003553 return SemaRef.Owned(E->Retain());
3554
Douglas Gregora16548e2009-08-11 05:31:07 +00003555 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3556 E->getOpcode(),
3557 move(SubExpr));
3558}
Mike Stump11289f42009-09-09 15:08:12 +00003559
Douglas Gregora16548e2009-08-11 05:31:07 +00003560template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003561Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003562TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E,
3563 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003564 if (E->isArgumentType()) {
John McCall4c98fd82009-11-04 07:28:41 +00003565 DeclaratorInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003566
John McCall4c98fd82009-11-04 07:28:41 +00003567 DeclaratorInfo *NewT = getDerived().TransformType(OldT);
3568 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003569 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003570
John McCall4c98fd82009-11-04 07:28:41 +00003571 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003572 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003573
John McCall4c98fd82009-11-04 07:28:41 +00003574 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003575 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003576 E->getSourceRange());
3577 }
Mike Stump11289f42009-09-09 15:08:12 +00003578
Douglas Gregora16548e2009-08-11 05:31:07 +00003579 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003580 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003581 // C++0x [expr.sizeof]p1:
3582 // The operand is either an expression, which is an unevaluated operand
3583 // [...]
3584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregora16548e2009-08-11 05:31:07 +00003586 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3587 if (SubExpr.isInvalid())
3588 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003589
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3591 return SemaRef.Owned(E->Retain());
3592 }
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregora16548e2009-08-11 05:31:07 +00003594 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3595 E->isSizeOf(),
3596 E->getSourceRange());
3597}
Mike Stump11289f42009-09-09 15:08:12 +00003598
Douglas Gregora16548e2009-08-11 05:31:07 +00003599template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003600Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003601TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E,
3602 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003603 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3604 if (LHS.isInvalid())
3605 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003606
Douglas Gregora16548e2009-08-11 05:31:07 +00003607 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3608 if (RHS.isInvalid())
3609 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003610
3611
Douglas Gregora16548e2009-08-11 05:31:07 +00003612 if (!getDerived().AlwaysRebuild() &&
3613 LHS.get() == E->getLHS() &&
3614 RHS.get() == E->getRHS())
3615 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregora16548e2009-08-11 05:31:07 +00003617 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3618 /*FIXME:*/E->getLHS()->getLocStart(),
3619 move(RHS),
3620 E->getRBracketLoc());
3621}
Mike Stump11289f42009-09-09 15:08:12 +00003622
3623template<typename Derived>
3624Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003625TreeTransform<Derived>::TransformCallExpr(CallExpr *E,
3626 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003627 // Transform the callee.
3628 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3629 if (Callee.isInvalid())
3630 return SemaRef.ExprError();
3631
3632 // Transform arguments.
3633 bool ArgChanged = false;
3634 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3635 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3636 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3637 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3638 if (Arg.isInvalid())
3639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003640
Douglas Gregora16548e2009-08-11 05:31:07 +00003641 // FIXME: Wrong source location information for the ','.
3642 FakeCommaLocs.push_back(
3643 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003644
3645 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003646 Args.push_back(Arg.takeAs<Expr>());
3647 }
Mike Stump11289f42009-09-09 15:08:12 +00003648
Douglas Gregora16548e2009-08-11 05:31:07 +00003649 if (!getDerived().AlwaysRebuild() &&
3650 Callee.get() == E->getCallee() &&
3651 !ArgChanged)
3652 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregora16548e2009-08-11 05:31:07 +00003654 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003655 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3657 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3658 move_arg(Args),
3659 FakeCommaLocs.data(),
3660 E->getRParenLoc());
3661}
Mike Stump11289f42009-09-09 15:08:12 +00003662
3663template<typename Derived>
3664Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003665TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E,
3666 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003667 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3668 if (Base.isInvalid())
3669 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003670
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003671 NestedNameSpecifier *Qualifier = 0;
3672 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003673 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003674 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3675 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003676 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003677 return SemaRef.ExprError();
3678 }
Mike Stump11289f42009-09-09 15:08:12 +00003679
3680 NamedDecl *Member
Douglas Gregora16548e2009-08-11 05:31:07 +00003681 = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getMemberDecl()));
3682 if (!Member)
3683 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregora16548e2009-08-11 05:31:07 +00003685 if (!getDerived().AlwaysRebuild() &&
3686 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003687 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003688 Member == E->getMemberDecl() &&
3689 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003690 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003691
John McCall6b51f282009-11-23 01:53:49 +00003692 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003693 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003694 TransArgs.setLAngleLoc(E->getLAngleLoc());
3695 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003696 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003697 TemplateArgumentLoc Loc;
3698 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003699 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003700 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003701 }
3702 }
3703
Douglas Gregora16548e2009-08-11 05:31:07 +00003704 // FIXME: Bogus source location for the operator
3705 SourceLocation FakeOperatorLoc
3706 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3707
3708 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3709 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003710 Qualifier,
3711 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003712 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003713 Member,
John McCall6b51f282009-11-23 01:53:49 +00003714 (E->hasExplicitTemplateArgumentList()
3715 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003716 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003717}
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregora16548e2009-08-11 05:31:07 +00003719template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003720Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003721TreeTransform<Derived>::TransformCastExpr(CastExpr *E,
3722 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003723 assert(false && "Cannot transform abstract class");
3724 return SemaRef.Owned(E->Retain());
3725}
3726
3727template<typename Derived>
3728Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003729TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E,
3730 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003731 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3732 if (LHS.isInvalid())
3733 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregora16548e2009-08-11 05:31:07 +00003735 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3736 if (RHS.isInvalid())
3737 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003738
Douglas Gregora16548e2009-08-11 05:31:07 +00003739 if (!getDerived().AlwaysRebuild() &&
3740 LHS.get() == E->getLHS() &&
3741 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003742 return SemaRef.Owned(E->Retain());
3743
Douglas Gregora16548e2009-08-11 05:31:07 +00003744 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3745 move(LHS), move(RHS));
3746}
3747
Mike Stump11289f42009-09-09 15:08:12 +00003748template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003749Sema::OwningExprResult
3750TreeTransform<Derived>::TransformCompoundAssignOperator(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003751 CompoundAssignOperator *E,
3752 bool isAddressOfOperand) {
3753 return getDerived().TransformBinaryOperator(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00003754}
Mike Stump11289f42009-09-09 15:08:12 +00003755
Douglas Gregora16548e2009-08-11 05:31:07 +00003756template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003757Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003758TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E,
3759 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003760 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3761 if (Cond.isInvalid())
3762 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003763
Douglas Gregora16548e2009-08-11 05:31:07 +00003764 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3765 if (LHS.isInvalid())
3766 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003767
Douglas Gregora16548e2009-08-11 05:31:07 +00003768 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3769 if (RHS.isInvalid())
3770 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003771
Douglas Gregora16548e2009-08-11 05:31:07 +00003772 if (!getDerived().AlwaysRebuild() &&
3773 Cond.get() == E->getCond() &&
3774 LHS.get() == E->getLHS() &&
3775 RHS.get() == E->getRHS())
3776 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003777
3778 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003779 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003780 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003781 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003782 move(RHS));
3783}
Mike Stump11289f42009-09-09 15:08:12 +00003784
3785template<typename Derived>
3786Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003787TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E,
3788 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003789 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3790
3791 // FIXME: Will we ever have type information here? It seems like we won't,
3792 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 QualType T = getDerived().TransformType(E->getType());
3794 if (T.isNull())
3795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3798 if (SubExpr.isInvalid())
3799 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003800
Douglas Gregora16548e2009-08-11 05:31:07 +00003801 if (!getDerived().AlwaysRebuild() &&
3802 T == E->getType() &&
3803 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003804 return SemaRef.Owned(E->Retain());
3805
Douglas Gregora16548e2009-08-11 05:31:07 +00003806 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003807 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003808 E->isLvalueCast());
3809}
Mike Stump11289f42009-09-09 15:08:12 +00003810
Douglas Gregora16548e2009-08-11 05:31:07 +00003811template<typename Derived>
3812Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003813TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E,
3814 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00003815 assert(false && "Cannot transform abstract class");
3816 return SemaRef.Owned(E->Retain());
3817}
3818
3819template<typename Derived>
3820Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003821TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E,
3822 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003823 QualType T;
3824 {
3825 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003826 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003827 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3828 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003829
Douglas Gregora16548e2009-08-11 05:31:07 +00003830 T = getDerived().TransformType(E->getTypeAsWritten());
3831 if (T.isNull())
3832 return SemaRef.ExprError();
3833 }
Mike Stump11289f42009-09-09 15:08:12 +00003834
Douglas Gregora16548e2009-08-11 05:31:07 +00003835 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3836 if (SubExpr.isInvalid())
3837 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003838
Douglas Gregora16548e2009-08-11 05:31:07 +00003839 if (!getDerived().AlwaysRebuild() &&
3840 T == E->getTypeAsWritten() &&
3841 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003842 return SemaRef.Owned(E->Retain());
3843
Douglas Gregora16548e2009-08-11 05:31:07 +00003844 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3845 E->getRParenLoc(),
3846 move(SubExpr));
3847}
Mike Stump11289f42009-09-09 15:08:12 +00003848
Douglas Gregora16548e2009-08-11 05:31:07 +00003849template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003850Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003851TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E,
3852 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 QualType T;
3854 {
3855 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003856 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003857 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3858 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003859
Douglas Gregora16548e2009-08-11 05:31:07 +00003860 T = getDerived().TransformType(E->getType());
3861 if (T.isNull())
3862 return SemaRef.ExprError();
3863 }
Mike Stump11289f42009-09-09 15:08:12 +00003864
Douglas Gregora16548e2009-08-11 05:31:07 +00003865 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3866 if (Init.isInvalid())
3867 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregora16548e2009-08-11 05:31:07 +00003869 if (!getDerived().AlwaysRebuild() &&
3870 T == E->getType() &&
3871 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003872 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003873
3874 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3875 /*FIXME:*/E->getInitializer()->getLocEnd(),
3876 move(Init));
3877}
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879template<typename Derived>
3880Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003881TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E,
3882 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003883 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3884 if (Base.isInvalid())
3885 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003886
Douglas Gregora16548e2009-08-11 05:31:07 +00003887 if (!getDerived().AlwaysRebuild() &&
3888 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003889 return SemaRef.Owned(E->Retain());
3890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003892 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003893 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3894 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3895 E->getAccessorLoc(),
3896 E->getAccessor());
3897}
Mike Stump11289f42009-09-09 15:08:12 +00003898
Douglas Gregora16548e2009-08-11 05:31:07 +00003899template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003900Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003901TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E,
3902 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003903 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregora16548e2009-08-11 05:31:07 +00003905 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3906 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3907 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3908 if (Init.isInvalid())
3909 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003910
Douglas Gregora16548e2009-08-11 05:31:07 +00003911 InitChanged = InitChanged || Init.get() != E->getInit(I);
3912 Inits.push_back(Init.takeAs<Expr>());
3913 }
Mike Stump11289f42009-09-09 15:08:12 +00003914
Douglas Gregora16548e2009-08-11 05:31:07 +00003915 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003916 return SemaRef.Owned(E->Retain());
3917
Douglas Gregora16548e2009-08-11 05:31:07 +00003918 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003919 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003920}
Mike Stump11289f42009-09-09 15:08:12 +00003921
Douglas Gregora16548e2009-08-11 05:31:07 +00003922template<typename Derived>
3923Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003924TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E,
3925 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003926 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003927
Douglas Gregorebe10102009-08-20 07:17:43 +00003928 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3930 if (Init.isInvalid())
3931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003932
Douglas Gregorebe10102009-08-20 07:17:43 +00003933 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003934 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3935 bool ExprChanged = false;
3936 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3937 DEnd = E->designators_end();
3938 D != DEnd; ++D) {
3939 if (D->isFieldDesignator()) {
3940 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3941 D->getDotLoc(),
3942 D->getFieldLoc()));
3943 continue;
3944 }
Mike Stump11289f42009-09-09 15:08:12 +00003945
Douglas Gregora16548e2009-08-11 05:31:07 +00003946 if (D->isArrayDesignator()) {
3947 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3948 if (Index.isInvalid())
3949 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003950
3951 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003952 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003953
Douglas Gregora16548e2009-08-11 05:31:07 +00003954 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3955 ArrayExprs.push_back(Index.release());
3956 continue;
3957 }
Mike Stump11289f42009-09-09 15:08:12 +00003958
Douglas Gregora16548e2009-08-11 05:31:07 +00003959 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003960 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003961 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3962 if (Start.isInvalid())
3963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003964
Douglas Gregora16548e2009-08-11 05:31:07 +00003965 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3966 if (End.isInvalid())
3967 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003968
3969 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 End.get(),
3971 D->getLBracketLoc(),
3972 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003973
Douglas Gregora16548e2009-08-11 05:31:07 +00003974 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3975 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003976
Douglas Gregora16548e2009-08-11 05:31:07 +00003977 ArrayExprs.push_back(Start.release());
3978 ArrayExprs.push_back(End.release());
3979 }
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981 if (!getDerived().AlwaysRebuild() &&
3982 Init.get() == E->getInit() &&
3983 !ExprChanged)
3984 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003985
Douglas Gregora16548e2009-08-11 05:31:07 +00003986 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3987 E->getEqualOrColonLoc(),
3988 E->usesGNUSyntax(), move(Init));
3989}
Mike Stump11289f42009-09-09 15:08:12 +00003990
Douglas Gregora16548e2009-08-11 05:31:07 +00003991template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003992Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003993TreeTransform<Derived>::TransformImplicitValueInitExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00003994 ImplicitValueInitExpr *E,
3995 bool isAddressOfOperand) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003996 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3997
3998 // FIXME: Will we ever have proper type location here? Will we actually
3999 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 QualType T = getDerived().TransformType(E->getType());
4001 if (T.isNull())
4002 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004003
Douglas Gregora16548e2009-08-11 05:31:07 +00004004 if (!getDerived().AlwaysRebuild() &&
4005 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004006 return SemaRef.Owned(E->Retain());
4007
Douglas Gregora16548e2009-08-11 05:31:07 +00004008 return getDerived().RebuildImplicitValueInitExpr(T);
4009}
Mike Stump11289f42009-09-09 15:08:12 +00004010
Douglas Gregora16548e2009-08-11 05:31:07 +00004011template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004012Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004013TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E,
4014 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004015 // FIXME: Do we want the type as written?
4016 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 {
4019 // FIXME: Source location isn't quite accurate.
4020 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4021 T = getDerived().TransformType(E->getType());
4022 if (T.isNull())
4023 return SemaRef.ExprError();
4024 }
Mike Stump11289f42009-09-09 15:08:12 +00004025
Douglas Gregora16548e2009-08-11 05:31:07 +00004026 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4027 if (SubExpr.isInvalid())
4028 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004029
Douglas Gregora16548e2009-08-11 05:31:07 +00004030 if (!getDerived().AlwaysRebuild() &&
4031 T == E->getType() &&
4032 SubExpr.get() == E->getSubExpr())
4033 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004034
Douglas Gregora16548e2009-08-11 05:31:07 +00004035 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4036 T, E->getRParenLoc());
4037}
4038
4039template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004040Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004041TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E,
4042 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004043 bool ArgumentChanged = false;
4044 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4045 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4046 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4047 if (Init.isInvalid())
4048 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004049
Douglas Gregora16548e2009-08-11 05:31:07 +00004050 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4051 Inits.push_back(Init.takeAs<Expr>());
4052 }
Mike Stump11289f42009-09-09 15:08:12 +00004053
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4055 move_arg(Inits),
4056 E->getRParenLoc());
4057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregora16548e2009-08-11 05:31:07 +00004059/// \brief Transform an address-of-label expression.
4060///
4061/// By default, the transformation of an address-of-label expression always
4062/// rebuilds the expression, so that the label identifier can be resolved to
4063/// the corresponding label statement by semantic analysis.
4064template<typename Derived>
4065Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004066TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E,
4067 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004068 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4069 E->getLabel());
4070}
Mike Stump11289f42009-09-09 15:08:12 +00004071
4072template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004073Sema::OwningExprResult
4074TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E,
4075 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004076 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004077 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4078 if (SubStmt.isInvalid())
4079 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregora16548e2009-08-11 05:31:07 +00004081 if (!getDerived().AlwaysRebuild() &&
4082 SubStmt.get() == E->getSubStmt())
4083 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004084
4085 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004086 move(SubStmt),
4087 E->getRParenLoc());
4088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregora16548e2009-08-11 05:31:07 +00004090template<typename Derived>
4091Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004092TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E,
4093 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004094 QualType T1, T2;
4095 {
4096 // FIXME: Source location isn't quite accurate.
4097 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004098
Douglas Gregora16548e2009-08-11 05:31:07 +00004099 T1 = getDerived().TransformType(E->getArgType1());
4100 if (T1.isNull())
4101 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004102
Douglas Gregora16548e2009-08-11 05:31:07 +00004103 T2 = getDerived().TransformType(E->getArgType2());
4104 if (T2.isNull())
4105 return SemaRef.ExprError();
4106 }
4107
4108 if (!getDerived().AlwaysRebuild() &&
4109 T1 == E->getArgType1() &&
4110 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004111 return SemaRef.Owned(E->Retain());
4112
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4114 T1, T2, E->getRParenLoc());
4115}
Mike Stump11289f42009-09-09 15:08:12 +00004116
Douglas Gregora16548e2009-08-11 05:31:07 +00004117template<typename Derived>
4118Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004119TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E,
4120 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004121 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4122 if (Cond.isInvalid())
4123 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregora16548e2009-08-11 05:31:07 +00004125 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4126 if (LHS.isInvalid())
4127 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004128
Douglas Gregora16548e2009-08-11 05:31:07 +00004129 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4130 if (RHS.isInvalid())
4131 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133 if (!getDerived().AlwaysRebuild() &&
4134 Cond.get() == E->getCond() &&
4135 LHS.get() == E->getLHS() &&
4136 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004137 return SemaRef.Owned(E->Retain());
4138
Douglas Gregora16548e2009-08-11 05:31:07 +00004139 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4140 move(Cond), move(LHS), move(RHS),
4141 E->getRParenLoc());
4142}
Mike Stump11289f42009-09-09 15:08:12 +00004143
Douglas Gregora16548e2009-08-11 05:31:07 +00004144template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004145Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004146TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E,
4147 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004149}
4150
4151template<typename Derived>
4152Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004153TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E,
4154 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004155 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4156 if (Callee.isInvalid())
4157 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004159 OwningExprResult First
4160 = getDerived().TransformExpr(E->getArg(0),
4161 E->getNumArgs() == 1 && E->getOperator() == OO_Amp);
Douglas Gregora16548e2009-08-11 05:31:07 +00004162 if (First.isInvalid())
4163 return SemaRef.ExprError();
4164
4165 OwningExprResult Second(SemaRef);
4166 if (E->getNumArgs() == 2) {
4167 Second = getDerived().TransformExpr(E->getArg(1));
4168 if (Second.isInvalid())
4169 return SemaRef.ExprError();
4170 }
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 if (!getDerived().AlwaysRebuild() &&
4173 Callee.get() == E->getCallee() &&
4174 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004175 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4176 return SemaRef.Owned(E->Retain());
4177
Douglas Gregora16548e2009-08-11 05:31:07 +00004178 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4179 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004180 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 move(First),
4182 move(Second));
4183}
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregora16548e2009-08-11 05:31:07 +00004185template<typename Derived>
4186Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004187TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E,
4188 bool isAddressOfOperand) {
4189 return getDerived().TransformCallExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004190}
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004193Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004194TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E,
4195 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 QualType ExplicitTy;
4197 {
4198 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004199 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004200 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4201 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004202
Douglas Gregora16548e2009-08-11 05:31:07 +00004203 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4204 if (ExplicitTy.isNull())
4205 return SemaRef.ExprError();
4206 }
Mike Stump11289f42009-09-09 15:08:12 +00004207
Douglas Gregora16548e2009-08-11 05:31:07 +00004208 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4209 if (SubExpr.isInvalid())
4210 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004211
Douglas Gregora16548e2009-08-11 05:31:07 +00004212 if (!getDerived().AlwaysRebuild() &&
4213 ExplicitTy == E->getTypeAsWritten() &&
4214 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004215 return SemaRef.Owned(E->Retain());
4216
Douglas Gregora16548e2009-08-11 05:31:07 +00004217 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004218 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4220 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4221 SourceLocation FakeRParenLoc
4222 = SemaRef.PP.getLocForEndOfToken(
4223 E->getSubExpr()->getSourceRange().getEnd());
4224 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004225 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 FakeLAngleLoc,
4227 ExplicitTy,
4228 FakeRAngleLoc,
4229 FakeRAngleLoc,
4230 move(SubExpr),
4231 FakeRParenLoc);
4232}
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234template<typename Derived>
4235Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004236TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E,
4237 bool isAddressOfOperand) {
4238 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004239}
Mike Stump11289f42009-09-09 15:08:12 +00004240
4241template<typename Derived>
4242Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004243TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E,
4244 bool isAddressOfOperand) {
4245 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Mike Stump11289f42009-09-09 15:08:12 +00004246}
4247
Douglas Gregora16548e2009-08-11 05:31:07 +00004248template<typename Derived>
4249Sema::OwningExprResult
4250TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004251 CXXReinterpretCastExpr *E,
4252 bool isAddressOfOperand) {
4253 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
Douglas Gregora16548e2009-08-11 05:31:07 +00004256template<typename Derived>
4257Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004258TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E,
4259 bool isAddressOfOperand) {
4260 return getDerived().TransformCXXNamedCastExpr(E, isAddressOfOperand);
Douglas Gregora16548e2009-08-11 05:31:07 +00004261}
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263template<typename Derived>
4264Sema::OwningExprResult
4265TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004266 CXXFunctionalCastExpr *E,
4267 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004268 QualType ExplicitTy;
4269 {
4270 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004271
Douglas Gregora16548e2009-08-11 05:31:07 +00004272 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4273 if (ExplicitTy.isNull())
4274 return SemaRef.ExprError();
4275 }
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4278 if (SubExpr.isInvalid())
4279 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 if (!getDerived().AlwaysRebuild() &&
4282 ExplicitTy == E->getTypeAsWritten() &&
4283 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004284 return SemaRef.Owned(E->Retain());
4285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 // FIXME: The end of the type's source range is wrong
4287 return getDerived().RebuildCXXFunctionalCastExpr(
4288 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4289 ExplicitTy,
4290 /*FIXME:*/E->getSubExpr()->getLocStart(),
4291 move(SubExpr),
4292 E->getRParenLoc());
4293}
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295template<typename Derived>
4296Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004297TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E,
4298 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 if (E->isTypeOperand()) {
4300 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregora16548e2009-08-11 05:31:07 +00004302 QualType T = getDerived().TransformType(E->getTypeOperand());
4303 if (T.isNull())
4304 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004305
Douglas Gregora16548e2009-08-11 05:31:07 +00004306 if (!getDerived().AlwaysRebuild() &&
4307 T == E->getTypeOperand())
4308 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004309
Douglas Gregora16548e2009-08-11 05:31:07 +00004310 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4311 /*FIXME:*/E->getLocStart(),
4312 T,
4313 E->getLocEnd());
4314 }
Mike Stump11289f42009-09-09 15:08:12 +00004315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 // We don't know whether the expression is potentially evaluated until
4317 // after we perform semantic analysis, so the expression is potentially
4318 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004319 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004321
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4323 if (SubExpr.isInvalid())
4324 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004325
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 if (!getDerived().AlwaysRebuild() &&
4327 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004328 return SemaRef.Owned(E->Retain());
4329
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4331 /*FIXME:*/E->getLocStart(),
4332 move(SubExpr),
4333 E->getLocEnd());
4334}
4335
4336template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004337Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004338TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E,
4339 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004340 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004341}
Mike Stump11289f42009-09-09 15:08:12 +00004342
Douglas Gregora16548e2009-08-11 05:31:07 +00004343template<typename Derived>
4344Sema::OwningExprResult
4345TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004346 CXXNullPtrLiteralExpr *E,
4347 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004348 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004349}
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351template<typename Derived>
4352Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004353TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E,
4354 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 QualType T = getDerived().TransformType(E->getType());
4358 if (T.isNull())
4359 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 if (!getDerived().AlwaysRebuild() &&
4362 T == E->getType())
4363 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4366}
Mike Stump11289f42009-09-09 15:08:12 +00004367
Douglas Gregora16548e2009-08-11 05:31:07 +00004368template<typename Derived>
4369Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004370TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E,
4371 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004372 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4373 if (SubExpr.isInvalid())
4374 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004375
Douglas Gregora16548e2009-08-11 05:31:07 +00004376 if (!getDerived().AlwaysRebuild() &&
4377 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004378 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004379
4380 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4381}
Mike Stump11289f42009-09-09 15:08:12 +00004382
Douglas Gregora16548e2009-08-11 05:31:07 +00004383template<typename Derived>
4384Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004385TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E,
4386 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004387 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4389 if (!Param)
4390 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 if (getDerived().AlwaysRebuild() &&
4393 Param == E->getParam())
4394 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004395
Douglas Gregora16548e2009-08-11 05:31:07 +00004396 return getDerived().RebuildCXXDefaultArgExpr(Param);
4397}
Mike Stump11289f42009-09-09 15:08:12 +00004398
Douglas Gregora16548e2009-08-11 05:31:07 +00004399template<typename Derived>
4400Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004401TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E,
4402 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004403 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4404
4405 QualType T = getDerived().TransformType(E->getType());
4406 if (T.isNull())
4407 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004408
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 if (!getDerived().AlwaysRebuild() &&
4410 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004411 return SemaRef.Owned(E->Retain());
4412
4413 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 /*FIXME:*/E->getTypeBeginLoc(),
4415 T,
4416 E->getRParenLoc());
4417}
Mike Stump11289f42009-09-09 15:08:12 +00004418
Douglas Gregora16548e2009-08-11 05:31:07 +00004419template<typename Derived>
4420Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004421TreeTransform<Derived>::TransformCXXConditionDeclExpr(CXXConditionDeclExpr *E,
4422 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004423 VarDecl *Var
Douglas Gregorebe10102009-08-20 07:17:43 +00004424 = cast_or_null<VarDecl>(getDerived().TransformDefinition(E->getVarDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 if (!Var)
4426 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004427
Douglas Gregora16548e2009-08-11 05:31:07 +00004428 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004429 Var == E->getVarDecl())
Douglas Gregora16548e2009-08-11 05:31:07 +00004430 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004431
4432 return getDerived().RebuildCXXConditionDeclExpr(E->getStartLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 /*FIXME:*/E->getStartLoc(),
4434 Var);
4435}
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437template<typename Derived>
4438Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004439TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E,
4440 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 // Transform the type that we're allocating
4442 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4443 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4444 if (AllocType.isNull())
4445 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004446
Douglas Gregora16548e2009-08-11 05:31:07 +00004447 // Transform the size of the array we're allocating (if any).
4448 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4449 if (ArraySize.isInvalid())
4450 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 // Transform the placement arguments (if any).
4453 bool ArgumentChanged = false;
4454 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4455 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4456 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(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->getPlacementArg(I);
4461 PlacementArgs.push_back(Arg.take());
4462 }
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregorebe10102009-08-20 07:17:43 +00004464 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4466 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4467 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4468 if (Arg.isInvalid())
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4472 ConstructorArgs.push_back(Arg.take());
4473 }
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 if (!getDerived().AlwaysRebuild() &&
4476 AllocType == E->getAllocatedType() &&
4477 ArraySize.get() == E->getArraySize() &&
4478 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004479 return SemaRef.Owned(E->Retain());
4480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4482 E->isGlobalNew(),
4483 /*FIXME:*/E->getLocStart(),
4484 move_arg(PlacementArgs),
4485 /*FIXME:*/E->getLocStart(),
4486 E->isParenTypeId(),
4487 AllocType,
4488 /*FIXME:*/E->getLocStart(),
4489 /*FIXME:*/SourceRange(),
4490 move(ArraySize),
4491 /*FIXME:*/E->getLocStart(),
4492 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004493 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004494}
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregora16548e2009-08-11 05:31:07 +00004496template<typename Derived>
4497Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004498TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E,
4499 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4501 if (Operand.isInvalid())
4502 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004503
Douglas Gregora16548e2009-08-11 05:31:07 +00004504 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004505 Operand.get() == E->getArgument())
4506 return SemaRef.Owned(E->Retain());
4507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4509 E->isGlobalDelete(),
4510 E->isArrayForm(),
4511 move(Operand));
4512}
Mike Stump11289f42009-09-09 15:08:12 +00004513
Douglas Gregora16548e2009-08-11 05:31:07 +00004514template<typename Derived>
4515Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004516TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004517 CXXPseudoDestructorExpr *E,
4518 bool isAddressOfOperand) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004519 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4520 if (Base.isInvalid())
4521 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004522
Douglas Gregorad8a3362009-09-04 17:36:40 +00004523 NestedNameSpecifier *Qualifier
4524 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4525 E->getQualifierRange());
4526 if (E->getQualifier() && !Qualifier)
4527 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregorad8a3362009-09-04 17:36:40 +00004529 QualType DestroyedType;
4530 {
4531 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4532 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4533 if (DestroyedType.isNull())
4534 return SemaRef.ExprError();
4535 }
Mike Stump11289f42009-09-09 15:08:12 +00004536
Douglas Gregorad8a3362009-09-04 17:36:40 +00004537 if (!getDerived().AlwaysRebuild() &&
4538 Base.get() == E->getBase() &&
4539 Qualifier == E->getQualifier() &&
4540 DestroyedType == E->getDestroyedType())
4541 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004542
Douglas Gregorad8a3362009-09-04 17:36:40 +00004543 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4544 E->getOperatorLoc(),
4545 E->isArrow(),
4546 E->getDestroyedTypeLoc(),
4547 DestroyedType,
4548 Qualifier,
4549 E->getQualifierRange());
4550}
Mike Stump11289f42009-09-09 15:08:12 +00004551
Douglas Gregorad8a3362009-09-04 17:36:40 +00004552template<typename Derived>
4553Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004554TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCalle66edc12009-11-24 19:00:30 +00004555 UnresolvedLookupExpr *Old,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004556 bool isAddressOfOperand) {
John McCalle66edc12009-11-24 19:00:30 +00004557 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4558
4559 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4560 Sema::LookupOrdinaryName);
4561
4562 // Transform all the decls.
4563 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4564 E = Old->decls_end(); I != E; ++I) {
4565 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4566 if (!InstD)
4567 return SemaRef.ExprError();
4568
4569 // Expand using declarations.
4570 if (isa<UsingDecl>(InstD)) {
4571 UsingDecl *UD = cast<UsingDecl>(InstD);
4572 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4573 E = UD->shadow_end(); I != E; ++I)
4574 R.addDecl(*I);
4575 continue;
4576 }
4577
4578 R.addDecl(InstD);
4579 }
4580
4581 // Resolve a kind, but don't do any further analysis. If it's
4582 // ambiguous, the callee needs to deal with it.
4583 R.resolveKind();
4584
4585 // Rebuild the nested-name qualifier, if present.
4586 CXXScopeSpec SS;
4587 NestedNameSpecifier *Qualifier = 0;
4588 if (Old->getQualifier()) {
4589 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4590 Old->getQualifierRange());
4591 if (!Qualifier)
4592 return SemaRef.ExprError();
4593
4594 SS.setScopeRep(Qualifier);
4595 SS.setRange(Old->getQualifierRange());
4596 }
4597
4598 // If we have no template arguments, it's a normal declaration name.
4599 if (!Old->hasExplicitTemplateArgs())
4600 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4601
4602 // If we have template arguments, rebuild them, then rebuild the
4603 // templateid expression.
4604 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4605 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4606 TemplateArgumentLoc Loc;
4607 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4608 return SemaRef.ExprError();
4609 TransArgs.addArgument(Loc);
4610 }
4611
4612 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4613 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004614}
Mike Stump11289f42009-09-09 15:08:12 +00004615
Douglas Gregora16548e2009-08-11 05:31:07 +00004616template<typename Derived>
4617Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004618TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E,
4619 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregora16548e2009-08-11 05:31:07 +00004622 QualType T = getDerived().TransformType(E->getQueriedType());
4623 if (T.isNull())
4624 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004625
Douglas Gregora16548e2009-08-11 05:31:07 +00004626 if (!getDerived().AlwaysRebuild() &&
4627 T == E->getQueriedType())
4628 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004629
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 // FIXME: Bad location information
4631 SourceLocation FakeLParenLoc
4632 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004633
4634 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 E->getLocStart(),
4636 /*FIXME:*/FakeLParenLoc,
4637 T,
4638 E->getLocEnd());
4639}
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641template<typename Derived>
4642Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004643TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
4644 DependentScopeDeclRefExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004645 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004647 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4648 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004649 if (!NNS)
4650 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004651
4652 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004653 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4654 if (!Name)
4655 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004656
John McCalle66edc12009-11-24 19:00:30 +00004657 if (!E->hasExplicitTemplateArgs()) {
4658 if (!getDerived().AlwaysRebuild() &&
4659 NNS == E->getQualifier() &&
4660 Name == E->getDeclName())
4661 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004662
John McCalle66edc12009-11-24 19:00:30 +00004663 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4664 E->getQualifierRange(),
4665 Name, E->getLocation(),
4666 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004667 }
John McCall6b51f282009-11-23 01:53:49 +00004668
4669 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004671 TemplateArgumentLoc Loc;
4672 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004674 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 }
4676
John McCalle66edc12009-11-24 19:00:30 +00004677 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4678 E->getQualifierRange(),
4679 Name, E->getLocation(),
4680 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004681}
4682
4683template<typename Derived>
4684Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004685TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E,
4686 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004687 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4688
4689 QualType T = getDerived().TransformType(E->getType());
4690 if (T.isNull())
4691 return SemaRef.ExprError();
4692
4693 CXXConstructorDecl *Constructor
4694 = cast_or_null<CXXConstructorDecl>(
4695 getDerived().TransformDecl(E->getConstructor()));
4696 if (!Constructor)
4697 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699 bool ArgumentChanged = false;
4700 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004701 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 ArgEnd = E->arg_end();
4703 Arg != ArgEnd; ++Arg) {
4704 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4705 if (TransArg.isInvalid())
4706 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4709 Args.push_back(TransArg.takeAs<Expr>());
4710 }
4711
4712 if (!getDerived().AlwaysRebuild() &&
4713 T == E->getType() &&
4714 Constructor == E->getConstructor() &&
4715 !ArgumentChanged)
4716 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4719 move_arg(Args));
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722/// \brief Transform a C++ temporary-binding expression.
4723///
Mike Stump11289f42009-09-09 15:08:12 +00004724/// The transformation of a temporary-binding expression always attempts to
4725/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004726/// subexpression itself did not change, because the temporary variable itself
4727/// must be unique.
4728template<typename Derived>
4729Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004730TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E,
4731 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4733 if (SubExpr.isInvalid())
4734 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4737}
Mike Stump11289f42009-09-09 15:08:12 +00004738
4739/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004740/// be destroyed after the expression is evaluated.
4741///
Mike Stump11289f42009-09-09 15:08:12 +00004742/// The transformation of a full expression always attempts to build a new
4743/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004744/// subexpression itself did not change, because it will need to capture the
4745/// the new temporary variables introduced in the subexpression.
4746template<typename Derived>
4747Sema::OwningExprResult
4748TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004749 CXXExprWithTemporaries *E,
4750 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004751 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4752 if (SubExpr.isInvalid())
4753 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 return SemaRef.Owned(
4756 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4757 E->shouldDestroyTemporaries()));
4758}
Mike Stump11289f42009-09-09 15:08:12 +00004759
Douglas Gregora16548e2009-08-11 05:31:07 +00004760template<typename Derived>
4761Sema::OwningExprResult
4762TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004763 CXXTemporaryObjectExpr *E,
4764 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4766 QualType T = getDerived().TransformType(E->getType());
4767 if (T.isNull())
4768 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 CXXConstructorDecl *Constructor
4771 = cast_or_null<CXXConstructorDecl>(
4772 getDerived().TransformDecl(E->getConstructor()));
4773 if (!Constructor)
4774 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004775
Douglas Gregora16548e2009-08-11 05:31:07 +00004776 bool ArgumentChanged = false;
4777 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4778 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004779 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 ArgEnd = E->arg_end();
4781 Arg != ArgEnd; ++Arg) {
4782 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4783 if (TransArg.isInvalid())
4784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4787 Args.push_back((Expr *)TransArg.release());
4788 }
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregora16548e2009-08-11 05:31:07 +00004790 if (!getDerived().AlwaysRebuild() &&
4791 T == E->getType() &&
4792 Constructor == E->getConstructor() &&
4793 !ArgumentChanged)
4794 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 // FIXME: Bogus location information
4797 SourceLocation CommaLoc;
4798 if (Args.size() > 1) {
4799 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004800 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004801 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4802 }
4803 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4804 T,
4805 /*FIXME:*/E->getTypeBeginLoc(),
4806 move_arg(Args),
4807 &CommaLoc,
4808 E->getLocEnd());
4809}
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811template<typename Derived>
4812Sema::OwningExprResult
4813TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004814 CXXUnresolvedConstructExpr *E,
4815 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004816 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4817 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4818 if (T.isNull())
4819 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 bool ArgumentChanged = false;
4822 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4823 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4824 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4825 ArgEnd = E->arg_end();
4826 Arg != ArgEnd; ++Arg) {
4827 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4828 if (TransArg.isInvalid())
4829 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004830
Douglas Gregora16548e2009-08-11 05:31:07 +00004831 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4832 FakeCommaLocs.push_back(
4833 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4834 Args.push_back(TransArg.takeAs<Expr>());
4835 }
Mike Stump11289f42009-09-09 15:08:12 +00004836
Douglas Gregora16548e2009-08-11 05:31:07 +00004837 if (!getDerived().AlwaysRebuild() &&
4838 T == E->getTypeAsWritten() &&
4839 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004840 return SemaRef.Owned(E->Retain());
4841
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 // FIXME: we're faking the locations of the commas
4843 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4844 T,
4845 E->getLParenLoc(),
4846 move_arg(Args),
4847 FakeCommaLocs.data(),
4848 E->getRParenLoc());
4849}
Mike Stump11289f42009-09-09 15:08:12 +00004850
Douglas Gregora16548e2009-08-11 05:31:07 +00004851template<typename Derived>
4852Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004853TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
4854 CXXDependentScopeMemberExpr *E,
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004855 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004856 // Transform the base of the expression.
4857 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4858 if (Base.isInvalid())
4859 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004860
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004861 // Start the member reference and compute the object's type.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004862 Sema::TypeTy *ObjectType = 0;
Mike Stump11289f42009-09-09 15:08:12 +00004863 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004864 E->getOperatorLoc(),
4865 E->isArrow()? tok::arrow : tok::period,
4866 ObjectType);
4867 if (Base.isInvalid())
4868 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004869
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004870 // Transform the first part of the nested-name-specifier that qualifies
4871 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004872 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004873 = getDerived().TransformFirstQualifierInScope(
4874 E->getFirstQualifierFoundInScope(),
4875 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004877 NestedNameSpecifier *Qualifier = 0;
4878 if (E->getQualifier()) {
4879 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4880 E->getQualifierRange(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004881 QualType::getFromOpaquePtr(ObjectType),
4882 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004883 if (!Qualifier)
4884 return SemaRef.ExprError();
4885 }
Mike Stump11289f42009-09-09 15:08:12 +00004886
4887 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004888 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
4889 QualType::getFromOpaquePtr(ObjectType));
Douglas Gregorf816bd72009-09-03 22:13:48 +00004890 if (!Name)
4891 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004892
Douglas Gregor308047d2009-09-09 00:23:06 +00004893 if (!E->hasExplicitTemplateArgumentList()) {
4894 // This is a reference to a member without an explicitly-specified
4895 // template argument list. Optimize for this common case.
4896 if (!getDerived().AlwaysRebuild() &&
4897 Base.get() == E->getBase() &&
4898 Qualifier == E->getQualifier() &&
4899 Name == E->getMember() &&
4900 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004901 return SemaRef.Owned(E->Retain());
4902
John McCall8cd78132009-11-19 22:55:06 +00004903 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregor308047d2009-09-09 00:23:06 +00004904 E->isArrow(),
4905 E->getOperatorLoc(),
4906 Qualifier,
4907 E->getQualifierRange(),
4908 Name,
4909 E->getMemberLoc(),
4910 FirstQualifierInScope);
4911 }
4912
4913 // FIXME: This is an ugly hack, which forces the same template name to
4914 // be looked up multiple times. Yuck!
Douglas Gregor71395fa2009-11-04 00:56:37 +00004915 TemporaryBase Rebase(*this, E->getMemberLoc(), DeclarationName());
4916 TemplateName OrigTemplateName;
4917 if (const IdentifierInfo *II = Name.getAsIdentifierInfo())
4918 OrigTemplateName = SemaRef.Context.getDependentTemplateName(0, II);
4919 else
4920 OrigTemplateName
4921 = SemaRef.Context.getDependentTemplateName(0,
4922 Name.getCXXOverloadedOperator());
Mike Stump11289f42009-09-09 15:08:12 +00004923
4924 TemplateName Template
4925 = getDerived().TransformTemplateName(OrigTemplateName,
Douglas Gregor308047d2009-09-09 00:23:06 +00004926 QualType::getFromOpaquePtr(ObjectType));
4927 if (Template.isNull())
4928 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004929
John McCall6b51f282009-11-23 01:53:49 +00004930 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004931 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004932 TemplateArgumentLoc Loc;
4933 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004934 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004935 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004936 }
Mike Stump11289f42009-09-09 15:08:12 +00004937
John McCall8cd78132009-11-19 22:55:06 +00004938 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 E->isArrow(),
4940 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004941 Qualifier,
4942 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004943 Template,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004944 E->getMemberLoc(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004945 FirstQualifierInScope,
John McCall6b51f282009-11-23 01:53:49 +00004946 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004947}
4948
4949template<typename Derived>
4950Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004951TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E,
4952 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004953 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004954}
4955
Mike Stump11289f42009-09-09 15:08:12 +00004956template<typename Derived>
4957Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004958TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E,
4959 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004960 // FIXME: poor source location
4961 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4962 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4963 if (EncodedType.isNull())
4964 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 if (!getDerived().AlwaysRebuild() &&
4967 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004968 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004969
4970 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4971 EncodedType,
4972 E->getRParenLoc());
4973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
Douglas Gregora16548e2009-08-11 05:31:07 +00004975template<typename Derived>
4976Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004977TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E,
4978 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004979 // FIXME: Implement this!
4980 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004981 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004982}
4983
Mike Stump11289f42009-09-09 15:08:12 +00004984template<typename Derived>
4985Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004986TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E,
4987 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004988 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004989}
4990
Mike Stump11289f42009-09-09 15:08:12 +00004991template<typename Derived>
4992Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004993TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E,
4994 bool isAddressOfOperand) {
Mike Stump11289f42009-09-09 15:08:12 +00004995 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004996 = cast_or_null<ObjCProtocolDecl>(
4997 getDerived().TransformDecl(E->getProtocol()));
4998 if (!Protocol)
4999 return SemaRef.ExprError();
5000
5001 if (!getDerived().AlwaysRebuild() &&
5002 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005003 return SemaRef.Owned(E->Retain());
5004
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 return getDerived().RebuildObjCProtocolExpr(Protocol,
5006 E->getAtLoc(),
5007 /*FIXME:*/E->getAtLoc(),
5008 /*FIXME:*/E->getAtLoc(),
5009 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011}
5012
Mike Stump11289f42009-09-09 15:08:12 +00005013template<typename Derived>
5014Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005015TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E,
5016 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005017 // FIXME: Implement this!
5018 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005019 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005020}
5021
Mike Stump11289f42009-09-09 15:08:12 +00005022template<typename Derived>
5023Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005024TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E,
5025 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005026 // FIXME: Implement this!
5027 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005028 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005029}
5030
Mike Stump11289f42009-09-09 15:08:12 +00005031template<typename Derived>
5032Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005033TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005034 ObjCImplicitSetterGetterRefExpr *E,
5035 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 // FIXME: Implement this!
5037 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005038 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005039}
5040
Mike Stump11289f42009-09-09 15:08:12 +00005041template<typename Derived>
5042Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005043TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E,
5044 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 // FIXME: Implement this!
5046 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005047 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005048}
5049
Mike Stump11289f42009-09-09 15:08:12 +00005050template<typename Derived>
5051Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005052TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E,
5053 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 // FIXME: Implement this!
5055 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005056 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005057}
5058
Mike Stump11289f42009-09-09 15:08:12 +00005059template<typename Derived>
5060Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005061TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E,
5062 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005063 bool ArgumentChanged = false;
5064 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5065 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5066 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5067 if (SubExpr.isInvalid())
5068 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregora16548e2009-08-11 05:31:07 +00005070 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5071 SubExprs.push_back(SubExpr.takeAs<Expr>());
5072 }
Mike Stump11289f42009-09-09 15:08:12 +00005073
Douglas Gregora16548e2009-08-11 05:31:07 +00005074 if (!getDerived().AlwaysRebuild() &&
5075 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005076 return SemaRef.Owned(E->Retain());
5077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5079 move_arg(SubExprs),
5080 E->getRParenLoc());
5081}
5082
Mike Stump11289f42009-09-09 15:08:12 +00005083template<typename Derived>
5084Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005085TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E,
5086 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005087 // FIXME: Implement this!
5088 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005089 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005090}
5091
Mike Stump11289f42009-09-09 15:08:12 +00005092template<typename Derived>
5093Sema::OwningExprResult
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00005094TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E,
5095 bool isAddressOfOperand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 // FIXME: Implement this!
5097 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005098 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005099}
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005102// Type reconstruction
5103//===----------------------------------------------------------------------===//
5104
Mike Stump11289f42009-09-09 15:08:12 +00005105template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005106QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5107 SourceLocation Star) {
5108 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005109 getDerived().getBaseEntity());
5110}
5111
Mike Stump11289f42009-09-09 15:08:12 +00005112template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005113QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5114 SourceLocation Star) {
5115 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005116 getDerived().getBaseEntity());
5117}
5118
Mike Stump11289f42009-09-09 15:08:12 +00005119template<typename Derived>
5120QualType
John McCall70dd5f62009-10-30 00:06:24 +00005121TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5122 bool WrittenAsLValue,
5123 SourceLocation Sigil) {
5124 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5125 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005126}
5127
5128template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005129QualType
John McCall70dd5f62009-10-30 00:06:24 +00005130TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5131 QualType ClassType,
5132 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005133 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005134 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005135}
5136
5137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005138QualType
John McCall70dd5f62009-10-30 00:06:24 +00005139TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5140 SourceLocation Sigil) {
5141 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005142 getDerived().getBaseEntity());
5143}
5144
5145template<typename Derived>
5146QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005147TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5148 ArrayType::ArraySizeModifier SizeMod,
5149 const llvm::APInt *Size,
5150 Expr *SizeExpr,
5151 unsigned IndexTypeQuals,
5152 SourceRange BracketsRange) {
5153 if (SizeExpr || !Size)
5154 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5155 IndexTypeQuals, BracketsRange,
5156 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005157
5158 QualType Types[] = {
5159 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5160 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5161 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005162 };
5163 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5164 QualType SizeType;
5165 for (unsigned I = 0; I != NumTypes; ++I)
5166 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5167 SizeType = Types[I];
5168 break;
5169 }
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171 if (SizeType.isNull())
5172 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005173
Douglas Gregord6ff3322009-08-04 16:50:30 +00005174 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005175 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005176 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005177 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005178}
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregord6ff3322009-08-04 16:50:30 +00005180template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005181QualType
5182TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005183 ArrayType::ArraySizeModifier SizeMod,
5184 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005185 unsigned IndexTypeQuals,
5186 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005187 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005188 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005189}
5190
5191template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005192QualType
Mike Stump11289f42009-09-09 15:08:12 +00005193TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005194 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005195 unsigned IndexTypeQuals,
5196 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005197 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005198 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199}
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005202QualType
5203TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005204 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005205 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005206 unsigned IndexTypeQuals,
5207 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005208 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005209 SizeExpr.takeAs<Expr>(),
5210 IndexTypeQuals, BracketsRange);
5211}
5212
5213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005214QualType
5215TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005216 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005217 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005218 unsigned IndexTypeQuals,
5219 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005220 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005221 SizeExpr.takeAs<Expr>(),
5222 IndexTypeQuals, BracketsRange);
5223}
5224
5225template<typename Derived>
5226QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5227 unsigned NumElements) {
5228 // FIXME: semantic checking!
5229 return SemaRef.Context.getVectorType(ElementType, NumElements);
5230}
Mike Stump11289f42009-09-09 15:08:12 +00005231
Douglas Gregord6ff3322009-08-04 16:50:30 +00005232template<typename Derived>
5233QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5234 unsigned NumElements,
5235 SourceLocation AttributeLoc) {
5236 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5237 NumElements, true);
5238 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005239 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240 AttributeLoc);
5241 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5242 AttributeLoc);
5243}
Mike Stump11289f42009-09-09 15:08:12 +00005244
Douglas Gregord6ff3322009-08-04 16:50:30 +00005245template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005246QualType
5247TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005248 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005249 SourceLocation AttributeLoc) {
5250 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253template<typename Derived>
5254QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005255 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005256 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005257 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005258 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005259 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260 Quals,
5261 getDerived().getBaseLocation(),
5262 getDerived().getBaseEntity());
5263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregord6ff3322009-08-04 16:50:30 +00005265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005266QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5267 return SemaRef.Context.getFunctionNoProtoType(T);
5268}
5269
5270template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005271QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005272 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5273}
5274
5275template<typename Derived>
5276QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5277 return SemaRef.Context.getTypeOfType(Underlying);
5278}
5279
5280template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005281QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005282 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5283}
5284
5285template<typename Derived>
5286QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005287 TemplateName Template,
5288 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005289 const TemplateArgumentListInfo &TemplateArgs) {
5290 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005291}
Mike Stump11289f42009-09-09 15:08:12 +00005292
Douglas Gregor1135c352009-08-06 05:28:30 +00005293template<typename Derived>
5294NestedNameSpecifier *
5295TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5296 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005297 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005298 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005299 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005300 CXXScopeSpec SS;
5301 // FIXME: The source location information is all wrong.
5302 SS.setRange(Range);
5303 SS.setScopeRep(Prefix);
5304 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005305 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005306 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005307 ObjectType,
5308 FirstQualifierInScope,
Douglas Gregore861bac2009-08-25 22:51:20 +00005309 false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005310}
5311
5312template<typename Derived>
5313NestedNameSpecifier *
5314TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5315 SourceRange Range,
5316 NamespaceDecl *NS) {
5317 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5318}
5319
5320template<typename Derived>
5321NestedNameSpecifier *
5322TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5323 SourceRange Range,
5324 bool TemplateKW,
5325 QualType T) {
5326 if (T->isDependentType() || T->isRecordType() ||
5327 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005328 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005329 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5330 T.getTypePtr());
5331 }
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregor1135c352009-08-06 05:28:30 +00005333 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5334 return 0;
5335}
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregor71dc5092009-08-06 06:41:21 +00005337template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005338TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005339TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5340 bool TemplateKW,
5341 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005342 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005343 Template);
5344}
5345
5346template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005347TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005348TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005349 const IdentifierInfo &II,
5350 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005351 CXXScopeSpec SS;
5352 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005353 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005354 UnqualifiedId Name;
5355 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005356 return getSema().ActOnDependentTemplateName(
5357 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005358 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005359 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005360 ObjectType.getAsOpaquePtr(),
5361 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005362 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005363}
Mike Stump11289f42009-09-09 15:08:12 +00005364
Douglas Gregora16548e2009-08-11 05:31:07 +00005365template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005366TemplateName
5367TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5368 OverloadedOperatorKind Operator,
5369 QualType ObjectType) {
5370 CXXScopeSpec SS;
5371 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5372 SS.setScopeRep(Qualifier);
5373 UnqualifiedId Name;
5374 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5375 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5376 Operator, SymbolLocations);
5377 return getSema().ActOnDependentTemplateName(
5378 /*FIXME:*/getDerived().getBaseLocation(),
5379 SS,
5380 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005381 ObjectType.getAsOpaquePtr(),
5382 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005383 .template getAsVal<TemplateName>();
5384}
5385
5386template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005387Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005388TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5389 SourceLocation OpLoc,
5390 ExprArg Callee,
5391 ExprArg First,
5392 ExprArg Second) {
5393 Expr *FirstExpr = (Expr *)First.get();
5394 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005395 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005397
Douglas Gregora16548e2009-08-11 05:31:07 +00005398 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005399 if (Op == OO_Subscript) {
5400 if (!FirstExpr->getType()->isOverloadableType() &&
5401 !SecondExpr->getType()->isOverloadableType())
5402 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005403 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005404 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005405 } else if (Op == OO_Arrow) {
5406 // -> is never a builtin operation.
5407 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005408 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 if (!FirstExpr->getType()->isOverloadableType()) {
5410 // The argument is not of overloadable type, so try to create a
5411 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005412 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005413 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005414
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5416 }
5417 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005418 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005419 !SecondExpr->getType()->isOverloadableType()) {
5420 // Neither of the arguments is an overloadable type, so try to
5421 // create a built-in binary operation.
5422 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005423 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5425 if (Result.isInvalid())
5426 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005427
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 First.release();
5429 Second.release();
5430 return move(Result);
5431 }
5432 }
Mike Stump11289f42009-09-09 15:08:12 +00005433
5434 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 // used during overload resolution.
5436 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005437
John McCalld14a8642009-11-21 08:51:07 +00005438 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5439 assert(ULE->requiresADL());
5440
5441 // FIXME: Do we have to check
5442 // IsAcceptableNonMemberOperatorCandidate for each of these?
5443 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5444 E = ULE->decls_end(); I != E; ++I)
5445 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5446 } else {
5447 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5448 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5449 }
Mike Stump11289f42009-09-09 15:08:12 +00005450
Douglas Gregora16548e2009-08-11 05:31:07 +00005451 // Add any functions found via argument-dependent lookup.
5452 Expr *Args[2] = { FirstExpr, SecondExpr };
5453 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005454 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005455 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005456 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5457 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregora16548e2009-08-11 05:31:07 +00005459 // Create the overloaded operator invocation for unary operators.
5460 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005461 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005462 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5463 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5464 }
Mike Stump11289f42009-09-09 15:08:12 +00005465
Sebastian Redladba46e2009-10-29 20:17:01 +00005466 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005467 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5468 OpLoc,
5469 move(First),
5470 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005471
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005473 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005475 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5477 if (Result.isInvalid())
5478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregora16548e2009-08-11 05:31:07 +00005480 First.release();
5481 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005482 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005483}
Mike Stump11289f42009-09-09 15:08:12 +00005484
Douglas Gregord6ff3322009-08-04 16:50:30 +00005485} // end namespace clang
5486
5487#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H