blob: 73ca797ce9bd8371f170c3e9863fbe919b9b8a80 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
175 /// \brief Transforms the given type into another type.
176 ///
John McCall550e0c22009-10-21 00:40:46 +0000177 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000178 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000179 /// function. This is expensive, but we don't mind, because
180 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000181 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000182 ///
183 /// \returns the transformed type.
184 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000185
John McCall550e0c22009-10-21 00:40:46 +0000186 /// \brief Transforms the given type-with-location into a new
187 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 ///
John McCall550e0c22009-10-21 00:40:46 +0000189 /// By default, this routine transforms a type by delegating to the
190 /// appropriate TransformXXXType to build a new type. Subclasses
191 /// may override this function (to take over all type
192 /// transformations) or some set of the TransformXXXType functions
193 /// to alter the transformation.
John McCallbcd03502009-12-07 02:54:59 +0000194 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000195
196 /// \brief Transform the given type-with-location into a new
197 /// type, collecting location information in the given builder
198 /// as necessary.
199 ///
200 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000201
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000202 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000203 ///
Mike Stump11289f42009-09-09 15:08:12 +0000204 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000205 /// appropriate TransformXXXStmt function to transform a specific kind of
206 /// statement or the TransformExpr() function to transform an expression.
207 /// Subclasses may override this function to transform statements using some
208 /// other mechanism.
209 ///
210 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000211 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000212
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000213 /// \brief Transform the given expression.
214 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000215 /// By default, this routine transforms an expression by delegating to the
216 /// appropriate TransformXXXExpr function to build a new expression.
217 /// Subclasses may override this function to transform expressions using some
218 /// other mechanism.
219 ///
220 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000221 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000222
Douglas Gregord6ff3322009-08-04 16:50:30 +0000223 /// \brief Transform the given declaration, which is referenced from a type
224 /// or expression.
225 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000226 /// By default, acts as the identity function on declarations. Subclasses
227 /// may override this function to provide alternate behavior.
228 Decl *TransformDecl(Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000229
230 /// \brief Transform the definition of the given declaration.
231 ///
Mike Stump11289f42009-09-09 15:08:12 +0000232 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000233 /// Subclasses may override this function to provide alternate behavior.
234 Decl *TransformDefinition(Decl *D) { return getDerived().TransformDecl(D); }
Mike Stump11289f42009-09-09 15:08:12 +0000235
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000236 /// \brief Transform the given declaration, which was the first part of a
237 /// nested-name-specifier in a member access expression.
238 ///
239 /// This specific declaration transformation only applies to the first
240 /// identifier in a nested-name-specifier of a member access expression, e.g.,
241 /// the \c T in \c x->T::member
242 ///
243 /// By default, invokes TransformDecl() to transform the declaration.
244 /// Subclasses may override this function to provide alternate behavior.
245 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
246 return cast_or_null<NamedDecl>(getDerived().TransformDecl(D));
247 }
248
Douglas Gregord6ff3322009-08-04 16:50:30 +0000249 /// \brief Transform the given nested-name-specifier.
250 ///
Mike Stump11289f42009-09-09 15:08:12 +0000251 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000252 /// nested-name-specifier. Subclasses may override this function to provide
253 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000254 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000255 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000256 QualType ObjectType = QualType(),
257 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000258
Douglas Gregorf816bd72009-09-03 22:13:48 +0000259 /// \brief Transform the given declaration name.
260 ///
261 /// By default, transforms the types of conversion function, constructor,
262 /// and destructor names and then (if needed) rebuilds the declaration name.
263 /// Identifiers and selectors are returned unmodified. Sublcasses may
264 /// override this function to provide alternate behavior.
265 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000266 SourceLocation Loc,
267 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000268
Douglas Gregord6ff3322009-08-04 16:50:30 +0000269 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000270 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000271 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000272 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000273 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000274 TemplateName TransformTemplateName(TemplateName Name,
275 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000276
Douglas Gregord6ff3322009-08-04 16:50:30 +0000277 /// \brief Transform the given template argument.
278 ///
Mike Stump11289f42009-09-09 15:08:12 +0000279 /// By default, this operation transforms the type, expression, or
280 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000281 /// new template argument from the transformed result. Subclasses may
282 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000283 ///
284 /// Returns true if there was an error.
285 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
286 TemplateArgumentLoc &Output);
287
288 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
289 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
290 TemplateArgumentLoc &ArgLoc);
291
John McCallbcd03502009-12-07 02:54:59 +0000292 /// \brief Fakes up a TypeSourceInfo for a type.
293 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
294 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000295 getDerived().getBaseLocation());
296 }
Mike Stump11289f42009-09-09 15:08:12 +0000297
John McCall550e0c22009-10-21 00:40:46 +0000298#define ABSTRACT_TYPELOC(CLASS, PARENT)
299#define TYPELOC(CLASS, PARENT) \
300 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
301#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000302
John McCall70dd5f62009-10-30 00:06:24 +0000303 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
304
Douglas Gregorc59e5612009-10-19 22:04:39 +0000305 QualType
306 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
307 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000308
309 QualType
310 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
311 TemplateSpecializationTypeLoc TL,
312 QualType ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +0000313
Douglas Gregorebe10102009-08-20 07:17:43 +0000314 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Mike Stump11289f42009-09-09 15:08:12 +0000315
Douglas Gregorebe10102009-08-20 07:17:43 +0000316#define STMT(Node, Parent) \
317 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000318#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000319 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000320#define ABSTRACT_EXPR(Node, Parent)
321#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregord6ff3322009-08-04 16:50:30 +0000323 /// \brief Build a new pointer type given its pointee type.
324 ///
325 /// By default, performs semantic analysis when building the pointer type.
326 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000327 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000328
329 /// \brief Build a new block pointer type given its pointee type.
330 ///
Mike Stump11289f42009-09-09 15:08:12 +0000331 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000332 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000333 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000334
John McCall70dd5f62009-10-30 00:06:24 +0000335 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000336 ///
John McCall70dd5f62009-10-30 00:06:24 +0000337 /// By default, performs semantic analysis when building the
338 /// reference type. Subclasses may override this routine to provide
339 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000340 ///
John McCall70dd5f62009-10-30 00:06:24 +0000341 /// \param LValue whether the type was written with an lvalue sigil
342 /// or an rvalue sigil.
343 QualType RebuildReferenceType(QualType ReferentType,
344 bool LValue,
345 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000346
Douglas Gregord6ff3322009-08-04 16:50:30 +0000347 /// \brief Build a new member pointer type given the pointee type and the
348 /// class type it refers into.
349 ///
350 /// By default, performs semantic analysis when building the member pointer
351 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000352 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
353 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000354
John McCall550e0c22009-10-21 00:40:46 +0000355 /// \brief Build a new Objective C object pointer type.
John McCall70dd5f62009-10-30 00:06:24 +0000356 QualType RebuildObjCObjectPointerType(QualType PointeeType,
357 SourceLocation Sigil);
John McCall550e0c22009-10-21 00:40:46 +0000358
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// \brief Build a new array type given the element type, size
360 /// modifier, size of the array (if known), size expression, and index type
361 /// qualifiers.
362 ///
363 /// By default, performs semantic analysis when building the array type.
364 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000365 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000366 QualType RebuildArrayType(QualType ElementType,
367 ArrayType::ArraySizeModifier SizeMod,
368 const llvm::APInt *Size,
369 Expr *SizeExpr,
370 unsigned IndexTypeQuals,
371 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000372
Douglas Gregord6ff3322009-08-04 16:50:30 +0000373 /// \brief Build a new constant array type given the element type, size
374 /// modifier, (known) size of the array, and index type qualifiers.
375 ///
376 /// By default, performs semantic analysis when building the array type.
377 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000378 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000379 ArrayType::ArraySizeModifier SizeMod,
380 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000381 unsigned IndexTypeQuals,
382 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383
Douglas Gregord6ff3322009-08-04 16:50:30 +0000384 /// \brief Build a new incomplete array type given the element type, size
385 /// modifier, 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 RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000390 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000391 unsigned IndexTypeQuals,
392 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000393
Mike Stump11289f42009-09-09 15:08:12 +0000394 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000395 /// size modifier, size expression, and index type qualifiers.
396 ///
397 /// By default, performs semantic analysis when building the array type.
398 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000399 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000400 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000401 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 unsigned IndexTypeQuals,
403 SourceRange BracketsRange);
404
Mike Stump11289f42009-09-09 15:08:12 +0000405 /// \brief Build a new dependent-sized 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 RebuildDependentSizedArrayType(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
416 /// \brief Build a new vector type given the element type and
417 /// number of elements.
418 ///
419 /// By default, performs semantic analysis when building the vector type.
420 /// Subclasses may override this routine to provide different behavior.
421 QualType RebuildVectorType(QualType ElementType, unsigned NumElements);
Mike Stump11289f42009-09-09 15:08:12 +0000422
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 /// \brief Build a new extended vector type given the element type and
424 /// number of elements.
425 ///
426 /// By default, performs semantic analysis when building the vector type.
427 /// Subclasses may override this routine to provide different behavior.
428 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
429 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000430
431 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000432 /// given the element type and number of elements.
433 ///
434 /// By default, performs semantic analysis when building the vector type.
435 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000436 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000437 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000438 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000439
Douglas Gregord6ff3322009-08-04 16:50:30 +0000440 /// \brief Build a new function type.
441 ///
442 /// By default, performs semantic analysis when building the function type.
443 /// Subclasses may override this routine to provide different behavior.
444 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000445 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000446 unsigned NumParamTypes,
447 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000448
John McCall550e0c22009-10-21 00:40:46 +0000449 /// \brief Build a new unprototyped function type.
450 QualType RebuildFunctionNoProtoType(QualType ResultType);
451
John McCallb96ec562009-12-04 22:46:56 +0000452 /// \brief Rebuild an unresolved typename type, given the decl that
453 /// the UnresolvedUsingTypenameDecl was transformed to.
454 QualType RebuildUnresolvedUsingType(Decl *D);
455
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// \brief Build a new typedef type.
457 QualType RebuildTypedefType(TypedefDecl *Typedef) {
458 return SemaRef.Context.getTypeDeclType(Typedef);
459 }
460
461 /// \brief Build a new class/struct/union type.
462 QualType RebuildRecordType(RecordDecl *Record) {
463 return SemaRef.Context.getTypeDeclType(Record);
464 }
465
466 /// \brief Build a new Enum type.
467 QualType RebuildEnumType(EnumDecl *Enum) {
468 return SemaRef.Context.getTypeDeclType(Enum);
469 }
John McCallfcc33b02009-09-05 00:15:47 +0000470
471 /// \brief Build a new elaborated type.
472 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
473 return SemaRef.Context.getElaboratedType(T, Tag);
474 }
Mike Stump11289f42009-09-09 15:08:12 +0000475
476 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000477 ///
478 /// By default, performs semantic analysis when building the typeof type.
479 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000480 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000481
Mike Stump11289f42009-09-09 15:08:12 +0000482 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000483 ///
484 /// By default, builds a new TypeOfType with the given underlying type.
485 QualType RebuildTypeOfType(QualType Underlying);
486
Mike Stump11289f42009-09-09 15:08:12 +0000487 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000488 ///
489 /// By default, performs semantic analysis when building the decltype type.
490 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000491 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000492
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493 /// \brief Build a new template specialization type.
494 ///
495 /// By default, performs semantic analysis when building the template
496 /// specialization type. Subclasses may override this routine to provide
497 /// different behavior.
498 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000499 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000500 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000501
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 /// \brief Build a new qualified name type.
503 ///
Mike Stump11289f42009-09-09 15:08:12 +0000504 /// By default, builds a new QualifiedNameType type from the
505 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000506 /// this routine to provide different behavior.
507 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
508 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000509 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000510
511 /// \brief Build a new typename type that refers to a template-id.
512 ///
513 /// By default, builds a new TypenameType type from the nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000514 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000515 /// different behavior.
516 QualType RebuildTypenameType(NestedNameSpecifier *NNS, QualType T) {
517 if (NNS->isDependent())
Mike Stump11289f42009-09-09 15:08:12 +0000518 return SemaRef.Context.getTypenameType(NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000519 cast<TemplateSpecializationType>(T));
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000522 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000523
524 /// \brief Build a new typename type that refers to an identifier.
525 ///
526 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000527 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000528 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000529 QualType RebuildTypenameType(NestedNameSpecifier *NNS,
John McCall0ad16662009-10-29 08:12:44 +0000530 const IdentifierInfo *Id,
531 SourceRange SR) {
532 return SemaRef.CheckTypenameType(NNS, *Id, SR);
Douglas Gregor1135c352009-08-06 05:28:30 +0000533 }
Mike Stump11289f42009-09-09 15:08:12 +0000534
Douglas Gregor1135c352009-08-06 05:28:30 +0000535 /// \brief Build a new nested-name-specifier given the prefix and an
536 /// identifier that names the next step in the nested-name-specifier.
537 ///
538 /// By default, performs semantic analysis when building the new
539 /// nested-name-specifier. Subclasses may override this routine to provide
540 /// different behavior.
541 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
542 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000543 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000544 QualType ObjectType,
545 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000546
547 /// \brief Build a new nested-name-specifier given the prefix and the
548 /// namespace named in the next step in the nested-name-specifier.
549 ///
550 /// By default, performs semantic analysis when building the new
551 /// nested-name-specifier. Subclasses may override this routine to provide
552 /// different behavior.
553 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
554 SourceRange Range,
555 NamespaceDecl *NS);
556
557 /// \brief Build a new nested-name-specifier given the prefix and the
558 /// type named in the next step in the nested-name-specifier.
559 ///
560 /// By default, performs semantic analysis when building the new
561 /// nested-name-specifier. Subclasses may override this routine to provide
562 /// different behavior.
563 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
564 SourceRange Range,
565 bool TemplateKW,
566 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000567
568 /// \brief Build a new template name given a nested name specifier, a flag
569 /// indicating whether the "template" keyword was provided, and the template
570 /// that the template name refers to.
571 ///
572 /// By default, builds the new template name directly. Subclasses may override
573 /// this routine to provide different behavior.
574 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
575 bool TemplateKW,
576 TemplateDecl *Template);
577
Douglas Gregor71dc5092009-08-06 06:41:21 +0000578 /// \brief Build a new template name given a nested name specifier and the
579 /// name that is referred to as a template.
580 ///
581 /// By default, performs semantic analysis to determine whether the name can
582 /// be resolved to a specific template, then builds the appropriate kind of
583 /// template name. Subclasses may override this routine to provide different
584 /// behavior.
585 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000586 const IdentifierInfo &II,
587 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000588
Douglas Gregor71395fa2009-11-04 00:56:37 +0000589 /// \brief Build a new template name given a nested name specifier and the
590 /// overloaded operator name that is referred to as a template.
591 ///
592 /// By default, performs semantic analysis to determine whether the name can
593 /// be resolved to a specific template, then builds the appropriate kind of
594 /// template name. Subclasses may override this routine to provide different
595 /// behavior.
596 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
597 OverloadedOperatorKind Operator,
598 QualType ObjectType);
599
Douglas Gregorebe10102009-08-20 07:17:43 +0000600 /// \brief Build a new compound statement.
601 ///
602 /// By default, performs semantic analysis to build the new statement.
603 /// Subclasses may override this routine to provide different behavior.
604 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
605 MultiStmtArg Statements,
606 SourceLocation RBraceLoc,
607 bool IsStmtExpr) {
608 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
609 IsStmtExpr);
610 }
611
612 /// \brief Build a new case statement.
613 ///
614 /// By default, performs semantic analysis to build the new statement.
615 /// Subclasses may override this routine to provide different behavior.
616 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
617 ExprArg LHS,
618 SourceLocation EllipsisLoc,
619 ExprArg RHS,
620 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000621 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000622 ColonLoc);
623 }
Mike Stump11289f42009-09-09 15:08:12 +0000624
Douglas Gregorebe10102009-08-20 07:17:43 +0000625 /// \brief Attach the body to a new case statement.
626 ///
627 /// By default, performs semantic analysis to build the new statement.
628 /// Subclasses may override this routine to provide different behavior.
629 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
630 getSema().ActOnCaseStmtBody(S.get(), move(Body));
631 return move(S);
632 }
Mike Stump11289f42009-09-09 15:08:12 +0000633
Douglas Gregorebe10102009-08-20 07:17:43 +0000634 /// \brief Build a new default statement.
635 ///
636 /// By default, performs semantic analysis to build the new statement.
637 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000638 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000639 SourceLocation ColonLoc,
640 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000641 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000642 /*CurScope=*/0);
643 }
Mike Stump11289f42009-09-09 15:08:12 +0000644
Douglas Gregorebe10102009-08-20 07:17:43 +0000645 /// \brief Build a new label statement.
646 ///
647 /// By default, performs semantic analysis to build the new statement.
648 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000649 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000650 IdentifierInfo *Id,
651 SourceLocation ColonLoc,
652 StmtArg SubStmt) {
653 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
654 }
Mike Stump11289f42009-09-09 15:08:12 +0000655
Douglas Gregorebe10102009-08-20 07:17:43 +0000656 /// \brief Build a new "if" statement.
657 ///
658 /// By default, performs semantic analysis to build the new statement.
659 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000660 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000661 VarDecl *CondVar, StmtArg Then,
662 SourceLocation ElseLoc, StmtArg Else) {
663 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
664 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000665 }
Mike Stump11289f42009-09-09 15:08:12 +0000666
Douglas Gregorebe10102009-08-20 07:17:43 +0000667 /// \brief Start building a new switch statement.
668 ///
669 /// By default, performs semantic analysis to build the new statement.
670 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000671 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
672 VarDecl *CondVar) {
673 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000674 }
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregorebe10102009-08-20 07:17:43 +0000676 /// \brief Attach the body to the switch statement.
677 ///
678 /// By default, performs semantic analysis to build the new statement.
679 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000680 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000681 StmtArg Switch, StmtArg Body) {
682 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
683 move(Body));
684 }
685
686 /// \brief Build a new while statement.
687 ///
688 /// By default, performs semantic analysis to build the new statement.
689 /// Subclasses may override this routine to provide different behavior.
690 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
691 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000692 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000693 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000694 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
695 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000696 }
Mike Stump11289f42009-09-09 15:08:12 +0000697
Douglas Gregorebe10102009-08-20 07:17:43 +0000698 /// \brief Build a new do-while statement.
699 ///
700 /// By default, performs semantic analysis to build the new statement.
701 /// Subclasses may override this routine to provide different behavior.
702 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
703 SourceLocation WhileLoc,
704 SourceLocation LParenLoc,
705 ExprArg Cond,
706 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000707 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000708 move(Cond), RParenLoc);
709 }
710
711 /// \brief Build a new for statement.
712 ///
713 /// By default, performs semantic analysis to build the new statement.
714 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000715 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000716 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000717 StmtArg Init, Sema::FullExprArg Cond,
718 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000719 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000720 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
721 DeclPtrTy::make(CondVar),
722 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 }
Mike Stump11289f42009-09-09 15:08:12 +0000724
Douglas Gregorebe10102009-08-20 07:17:43 +0000725 /// \brief Build a new goto statement.
726 ///
727 /// By default, performs semantic analysis to build the new statement.
728 /// Subclasses may override this routine to provide different behavior.
729 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
730 SourceLocation LabelLoc,
731 LabelStmt *Label) {
732 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
733 }
734
735 /// \brief Build a new indirect goto statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
739 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
740 SourceLocation StarLoc,
741 ExprArg Target) {
742 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
743 }
Mike Stump11289f42009-09-09 15:08:12 +0000744
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 /// \brief Build a new return statement.
746 ///
747 /// By default, performs semantic analysis to build the new statement.
748 /// Subclasses may override this routine to provide different behavior.
749 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
750 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000751
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
753 }
Mike Stump11289f42009-09-09 15:08:12 +0000754
Douglas Gregorebe10102009-08-20 07:17:43 +0000755 /// \brief Build a new declaration statement.
756 ///
757 /// By default, performs semantic analysis to build the new statement.
758 /// Subclasses may override this routine to provide different behavior.
759 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000760 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000761 SourceLocation EndLoc) {
762 return getSema().Owned(
763 new (getSema().Context) DeclStmt(
764 DeclGroupRef::Create(getSema().Context,
765 Decls, NumDecls),
766 StartLoc, EndLoc));
767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Build a new C++ exception declaration.
770 ///
771 /// By default, performs semantic analysis to build the new decaration.
772 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000773 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000774 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000775 IdentifierInfo *Name,
776 SourceLocation Loc,
777 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000778 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000779 TypeRange);
780 }
781
782 /// \brief Build a new C++ catch statement.
783 ///
784 /// By default, performs semantic analysis to build the new statement.
785 /// Subclasses may override this routine to provide different behavior.
786 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
787 VarDecl *ExceptionDecl,
788 StmtArg Handler) {
789 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000790 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000791 Handler.takeAs<Stmt>()));
792 }
Mike Stump11289f42009-09-09 15:08:12 +0000793
Douglas Gregorebe10102009-08-20 07:17:43 +0000794 /// \brief Build a new C++ try statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
798 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
799 StmtArg TryBlock,
800 MultiStmtArg Handlers) {
801 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
802 }
Mike Stump11289f42009-09-09 15:08:12 +0000803
Douglas Gregora16548e2009-08-11 05:31:07 +0000804 /// \brief Build a new expression that references a declaration.
805 ///
806 /// By default, performs semantic analysis to build the new expression.
807 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000808 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
809 LookupResult &R,
810 bool RequiresADL) {
811 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
812 }
813
814
815 /// \brief Build a new expression that references a declaration.
816 ///
817 /// By default, performs semantic analysis to build the new expression.
818 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000819 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
820 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000821 ValueDecl *VD, SourceLocation Loc,
822 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000823 CXXScopeSpec SS;
824 SS.setScopeRep(Qualifier);
825 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000826
827 // FIXME: loses template args.
828
829 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000830 }
Mike Stump11289f42009-09-09 15:08:12 +0000831
Douglas Gregora16548e2009-08-11 05:31:07 +0000832 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000833 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000834 /// By default, performs semantic analysis to build the new expression.
835 /// Subclasses may override this routine to provide different behavior.
836 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
837 SourceLocation RParen) {
838 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
839 }
840
Douglas Gregorad8a3362009-09-04 17:36:40 +0000841 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +0000842 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +0000843 /// By default, performs semantic analysis to build the new expression.
844 /// Subclasses may override this routine to provide different behavior.
845 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
846 SourceLocation OperatorLoc,
847 bool isArrow,
848 SourceLocation DestroyedTypeLoc,
849 QualType DestroyedType,
850 NestedNameSpecifier *Qualifier,
851 SourceRange QualifierRange) {
852 CXXScopeSpec SS;
853 if (Qualifier) {
854 SS.setRange(QualifierRange);
855 SS.setScopeRep(Qualifier);
856 }
857
John McCall2d74de92009-12-01 22:10:20 +0000858 QualType BaseType = ((Expr*) Base.get())->getType();
859
Mike Stump11289f42009-09-09 15:08:12 +0000860 DeclarationName Name
Douglas Gregorad8a3362009-09-04 17:36:40 +0000861 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
862 SemaRef.Context.getCanonicalType(DestroyedType));
Mike Stump11289f42009-09-09 15:08:12 +0000863
John McCall2d74de92009-12-01 22:10:20 +0000864 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
865 OperatorLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000866 SS, /*FIXME: FirstQualifier*/ 0,
867 Name, DestroyedTypeLoc,
868 /*TemplateArgs*/ 0);
Mike Stump11289f42009-09-09 15:08:12 +0000869 }
870
Douglas Gregora16548e2009-08-11 05:31:07 +0000871 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000872 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000873 /// By default, performs semantic analysis to build the new expression.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
876 UnaryOperator::Opcode Opc,
877 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000878 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +0000879 }
Mike Stump11289f42009-09-09 15:08:12 +0000880
Douglas Gregora16548e2009-08-11 05:31:07 +0000881 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +0000882 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000883 /// By default, performs semantic analysis to build the new expression.
884 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +0000885 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +0000886 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +0000887 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +0000888 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +0000889 }
890
Mike Stump11289f42009-09-09 15:08:12 +0000891 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +0000892 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +0000893 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000894 /// By default, performs semantic analysis to build the new expression.
895 /// Subclasses may override this routine to provide different behavior.
896 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
897 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +0000898 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +0000899 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
900 OpLoc, isSizeOf, R);
901 if (Result.isInvalid())
902 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +0000903
Douglas Gregora16548e2009-08-11 05:31:07 +0000904 SubExpr.release();
905 return move(Result);
906 }
Mike Stump11289f42009-09-09 15:08:12 +0000907
Douglas Gregora16548e2009-08-11 05:31:07 +0000908 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +0000909 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000910 /// By default, performs semantic analysis to build the new expression.
911 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000912 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +0000913 SourceLocation LBracketLoc,
914 ExprArg RHS,
915 SourceLocation RBracketLoc) {
916 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +0000917 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +0000918 RBracketLoc);
919 }
920
921 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +0000922 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000923 /// By default, performs semantic analysis to build the new expression.
924 /// Subclasses may override this routine to provide different behavior.
925 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
926 MultiExprArg Args,
927 SourceLocation *CommaLocs,
928 SourceLocation RParenLoc) {
929 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
930 move(Args), CommaLocs, RParenLoc);
931 }
932
933 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +0000934 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000935 /// By default, performs semantic analysis to build the new expression.
936 /// Subclasses may override this routine to provide different behavior.
937 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +0000938 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000939 NestedNameSpecifier *Qualifier,
940 SourceRange QualifierRange,
941 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +0000942 ValueDecl *Member,
John McCall6b51f282009-11-23 01:53:49 +0000943 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +0000944 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +0000945 if (!Member->getDeclName()) {
946 // We have a reference to an unnamed field.
947 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +0000948
949 MemberExpr *ME =
Anders Carlsson5da84842009-09-01 04:26:58 +0000950 new (getSema().Context) MemberExpr(Base.takeAs<Expr>(), isArrow,
951 Member, MemberLoc,
952 cast<FieldDecl>(Member)->getType());
953 return getSema().Owned(ME);
954 }
Mike Stump11289f42009-09-09 15:08:12 +0000955
Douglas Gregorf405d7e2009-08-31 23:41:50 +0000956 CXXScopeSpec SS;
957 if (Qualifier) {
958 SS.setRange(QualifierRange);
959 SS.setScopeRep(Qualifier);
960 }
961
John McCall2d74de92009-12-01 22:10:20 +0000962 QualType BaseType = ((Expr*) Base.get())->getType();
963
964 // FIXME: wait, this is re-performing lookup?
965 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
966 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +0000967 SS, FirstQualifierInScope,
968 Member->getDeclName(), MemberLoc,
969 ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +0000970 }
Mike Stump11289f42009-09-09 15:08:12 +0000971
Douglas Gregora16548e2009-08-11 05:31:07 +0000972 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000973 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000974 /// By default, performs semantic analysis to build the new expression.
975 /// Subclasses may override this routine to provide different behavior.
976 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
977 BinaryOperator::Opcode Opc,
978 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +0000979 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
980 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +0000981 }
982
983 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +0000984 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000985 /// By default, performs semantic analysis to build the new expression.
986 /// Subclasses may override this routine to provide different behavior.
987 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
988 SourceLocation QuestionLoc,
989 ExprArg LHS,
990 SourceLocation ColonLoc,
991 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +0000992 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +0000993 move(LHS), move(RHS));
994 }
995
996 /// \brief Build a new implicit cast expression.
Mike Stump11289f42009-09-09 15:08:12 +0000997 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000998 /// By default, builds a new implicit cast without any semantic analysis.
999 /// Subclasses may override this routine to provide different behavior.
1000 OwningExprResult RebuildImplicitCastExpr(QualType T, CastExpr::CastKind Kind,
1001 ExprArg SubExpr, bool isLvalue) {
1002 ImplicitCastExpr *ICE
Mike Stump11289f42009-09-09 15:08:12 +00001003 = new (getSema().Context) ImplicitCastExpr(T, Kind,
Douglas Gregora16548e2009-08-11 05:31:07 +00001004 (Expr *)SubExpr.release(),
1005 isLvalue);
1006 return getSema().Owned(ICE);
1007 }
1008
1009 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001011 /// By default, performs semantic analysis to build the new expression.
1012 /// Subclasses may override this routine to provide different behavior.
1013 OwningExprResult RebuildCStyleCaseExpr(SourceLocation LParenLoc,
1014 QualType ExplicitTy,
1015 SourceLocation RParenLoc,
1016 ExprArg SubExpr) {
1017 return getSema().ActOnCastExpr(/*Scope=*/0,
1018 LParenLoc,
1019 ExplicitTy.getAsOpaquePtr(),
1020 RParenLoc,
1021 move(SubExpr));
1022 }
Mike Stump11289f42009-09-09 15:08:12 +00001023
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001025 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001026 /// By default, performs semantic analysis to build the new expression.
1027 /// Subclasses may override this routine to provide different behavior.
1028 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
1029 QualType T,
1030 SourceLocation RParenLoc,
1031 ExprArg Init) {
1032 return getSema().ActOnCompoundLiteral(LParenLoc, T.getAsOpaquePtr(),
1033 RParenLoc, move(Init));
1034 }
Mike Stump11289f42009-09-09 15:08:12 +00001035
Douglas Gregora16548e2009-08-11 05:31:07 +00001036 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001037 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001038 /// By default, performs semantic analysis to build the new expression.
1039 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001040 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001041 SourceLocation OpLoc,
1042 SourceLocation AccessorLoc,
1043 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001044
John McCall10eae182009-11-30 22:42:35 +00001045 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001046 QualType BaseType = ((Expr*) Base.get())->getType();
1047 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001048 OpLoc, /*IsArrow*/ false,
1049 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001050 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001051 AccessorLoc,
1052 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 }
Mike Stump11289f42009-09-09 15:08:12 +00001054
Douglas Gregora16548e2009-08-11 05:31:07 +00001055 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001056 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001057 /// By default, performs semantic analysis to build the new expression.
1058 /// Subclasses may override this routine to provide different behavior.
1059 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1060 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001061 SourceLocation RBraceLoc,
1062 QualType ResultTy) {
1063 OwningExprResult Result
1064 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1065 if (Result.isInvalid() || ResultTy->isDependentType())
1066 return move(Result);
1067
1068 // Patch in the result type we were given, which may have been computed
1069 // when the initial InitListExpr was built.
1070 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1071 ILE->setType(ResultTy);
1072 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 }
Mike Stump11289f42009-09-09 15:08:12 +00001074
Douglas Gregora16548e2009-08-11 05:31:07 +00001075 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001076 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 /// By default, performs semantic analysis to build the new expression.
1078 /// Subclasses may override this routine to provide different behavior.
1079 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1080 MultiExprArg ArrayExprs,
1081 SourceLocation EqualOrColonLoc,
1082 bool GNUSyntax,
1083 ExprArg Init) {
1084 OwningExprResult Result
1085 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1086 move(Init));
1087 if (Result.isInvalid())
1088 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001089
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 ArrayExprs.release();
1091 return move(Result);
1092 }
Mike Stump11289f42009-09-09 15:08:12 +00001093
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001095 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 /// By default, builds the implicit value initialization without performing
1097 /// any semantic analysis. Subclasses may override this routine to provide
1098 /// different behavior.
1099 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1100 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1101 }
Mike Stump11289f42009-09-09 15:08:12 +00001102
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001104 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001105 /// By default, performs semantic analysis to build the new expression.
1106 /// Subclasses may override this routine to provide different behavior.
1107 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1108 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001109 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001110 RParenLoc);
1111 }
1112
1113 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001114 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 /// By default, performs semantic analysis to build the new expression.
1116 /// Subclasses may override this routine to provide different behavior.
1117 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1118 MultiExprArg SubExprs,
1119 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001120 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1121 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 }
Mike Stump11289f42009-09-09 15:08:12 +00001123
Douglas Gregora16548e2009-08-11 05:31:07 +00001124 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001125 ///
1126 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 /// rather than attempting to map the label statement itself.
1128 /// Subclasses may override this routine to provide different behavior.
1129 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1130 SourceLocation LabelLoc,
1131 LabelStmt *Label) {
1132 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1133 }
Mike Stump11289f42009-09-09 15:08:12 +00001134
Douglas Gregora16548e2009-08-11 05:31:07 +00001135 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001136 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 /// By default, performs semantic analysis to build the new expression.
1138 /// Subclasses may override this routine to provide different behavior.
1139 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1140 StmtArg SubStmt,
1141 SourceLocation RParenLoc) {
1142 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1143 }
Mike Stump11289f42009-09-09 15:08:12 +00001144
Douglas Gregora16548e2009-08-11 05:31:07 +00001145 /// \brief Build a new __builtin_types_compatible_p expression.
1146 ///
1147 /// By default, performs semantic analysis to build the new expression.
1148 /// Subclasses may override this routine to provide different behavior.
1149 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1150 QualType T1, QualType T2,
1151 SourceLocation RParenLoc) {
1152 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1153 T1.getAsOpaquePtr(),
1154 T2.getAsOpaquePtr(),
1155 RParenLoc);
1156 }
Mike Stump11289f42009-09-09 15:08:12 +00001157
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 /// \brief Build a new __builtin_choose_expr expression.
1159 ///
1160 /// By default, performs semantic analysis to build the new expression.
1161 /// Subclasses may override this routine to provide different behavior.
1162 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1163 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1164 SourceLocation RParenLoc) {
1165 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1166 move(Cond), move(LHS), move(RHS),
1167 RParenLoc);
1168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 /// \brief Build a new overloaded operator call expression.
1171 ///
1172 /// By default, performs semantic analysis to build the new expression.
1173 /// The semantic analysis provides the behavior of template instantiation,
1174 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001175 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001176 /// argument-dependent lookup, etc. Subclasses may override this routine to
1177 /// provide different behavior.
1178 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1179 SourceLocation OpLoc,
1180 ExprArg Callee,
1181 ExprArg First,
1182 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001183
1184 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001185 /// reinterpret_cast.
1186 ///
1187 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001188 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001189 /// Subclasses may override this routine to provide different behavior.
1190 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1191 Stmt::StmtClass Class,
1192 SourceLocation LAngleLoc,
1193 QualType T,
1194 SourceLocation RAngleLoc,
1195 SourceLocation LParenLoc,
1196 ExprArg SubExpr,
1197 SourceLocation RParenLoc) {
1198 switch (Class) {
1199 case Stmt::CXXStaticCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001200 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, T,
1201 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001202 move(SubExpr), RParenLoc);
1203
1204 case Stmt::CXXDynamicCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001205 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, T,
1206 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 case Stmt::CXXReinterpretCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001210 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, T,
1211 RAngleLoc, LParenLoc,
1212 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 case Stmt::CXXConstCastExprClass:
Mike Stump11289f42009-09-09 15:08:12 +00001216 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, T,
1217 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 default:
1221 assert(false && "Invalid C++ named cast");
1222 break;
1223 }
Mike Stump11289f42009-09-09 15:08:12 +00001224
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 return getSema().ExprError();
1226 }
Mike Stump11289f42009-09-09 15:08:12 +00001227
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 /// \brief Build a new C++ static_cast expression.
1229 ///
1230 /// By default, performs semantic analysis to build the new expression.
1231 /// Subclasses may override this routine to provide different behavior.
1232 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1233 SourceLocation LAngleLoc,
1234 QualType T,
1235 SourceLocation RAngleLoc,
1236 SourceLocation LParenLoc,
1237 ExprArg SubExpr,
1238 SourceLocation RParenLoc) {
1239 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_static_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001240 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 LParenLoc, move(SubExpr), RParenLoc);
1242 }
1243
1244 /// \brief Build a new C++ dynamic_cast expression.
1245 ///
1246 /// By default, performs semantic analysis to build the new expression.
1247 /// Subclasses may override this routine to provide different behavior.
1248 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1249 SourceLocation LAngleLoc,
1250 QualType T,
1251 SourceLocation RAngleLoc,
1252 SourceLocation LParenLoc,
1253 ExprArg SubExpr,
1254 SourceLocation RParenLoc) {
1255 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001256 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 LParenLoc, move(SubExpr), RParenLoc);
1258 }
1259
1260 /// \brief Build a new C++ reinterpret_cast expression.
1261 ///
1262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
1264 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1265 SourceLocation LAngleLoc,
1266 QualType T,
1267 SourceLocation RAngleLoc,
1268 SourceLocation LParenLoc,
1269 ExprArg SubExpr,
1270 SourceLocation RParenLoc) {
1271 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1272 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
1273 LParenLoc, move(SubExpr), RParenLoc);
1274 }
1275
1276 /// \brief Build a new C++ const_cast expression.
1277 ///
1278 /// By default, performs semantic analysis to build the new expression.
1279 /// Subclasses may override this routine to provide different behavior.
1280 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1281 SourceLocation LAngleLoc,
1282 QualType T,
1283 SourceLocation RAngleLoc,
1284 SourceLocation LParenLoc,
1285 ExprArg SubExpr,
1286 SourceLocation RParenLoc) {
1287 return getSema().ActOnCXXNamedCast(OpLoc, tok::kw_const_cast,
Mike Stump11289f42009-09-09 15:08:12 +00001288 LAngleLoc, T.getAsOpaquePtr(), RAngleLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001289 LParenLoc, move(SubExpr), RParenLoc);
1290 }
Mike Stump11289f42009-09-09 15:08:12 +00001291
Douglas Gregora16548e2009-08-11 05:31:07 +00001292 /// \brief Build a new C++ functional-style cast expression.
1293 ///
1294 /// By default, performs semantic analysis to build the new expression.
1295 /// Subclasses may override this routine to provide different behavior.
1296 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
1297 QualType T,
1298 SourceLocation LParenLoc,
1299 ExprArg SubExpr,
1300 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001301 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
1303 T.getAsOpaquePtr(),
1304 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001305 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001306 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 RParenLoc);
1308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// \brief Build a new C++ typeid(type) expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1315 SourceLocation LParenLoc,
1316 QualType T,
1317 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001318 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 T.getAsOpaquePtr(), RParenLoc);
1320 }
Mike Stump11289f42009-09-09 15:08:12 +00001321
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// \brief Build a new C++ typeid(expr) expression.
1323 ///
1324 /// By default, performs semantic analysis to build the new expression.
1325 /// Subclasses may override this routine to provide different behavior.
1326 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1327 SourceLocation LParenLoc,
1328 ExprArg Operand,
1329 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001330 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1332 RParenLoc);
1333 if (Result.isInvalid())
1334 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001335
Douglas Gregora16548e2009-08-11 05:31:07 +00001336 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1337 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001338 }
1339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 /// \brief Build a new C++ "this" expression.
1341 ///
1342 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001343 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001345 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001346 QualType ThisType) {
1347 return getSema().Owned(
1348 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType));
1349 }
1350
1351 /// \brief Build a new C++ throw expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1356 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1357 }
1358
1359 /// \brief Build a new C++ default-argument expression.
1360 ///
1361 /// By default, builds a new default-argument expression, which does not
1362 /// require any semantic analysis. Subclasses may override this routine to
1363 /// provide different behavior.
1364 OwningExprResult RebuildCXXDefaultArgExpr(ParmVarDecl *Param) {
Anders Carlssone8271232009-08-14 18:30:22 +00001365 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 }
1367
1368 /// \brief Build a new C++ zero-initialization expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001372 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001373 SourceLocation LParenLoc,
1374 QualType T,
1375 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001376 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1377 T.getAsOpaquePtr(), LParenLoc,
1378 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 0, RParenLoc);
1380 }
Mike Stump11289f42009-09-09 15:08:12 +00001381
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// \brief Build a new C++ "new" expression.
1383 ///
1384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001386 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 bool UseGlobal,
1388 SourceLocation PlacementLParen,
1389 MultiExprArg PlacementArgs,
1390 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001391 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 QualType AllocType,
1393 SourceLocation TypeLoc,
1394 SourceRange TypeRange,
1395 ExprArg ArraySize,
1396 SourceLocation ConstructorLParen,
1397 MultiExprArg ConstructorArgs,
1398 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001399 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 PlacementLParen,
1401 move(PlacementArgs),
1402 PlacementRParen,
1403 ParenTypeId,
1404 AllocType,
1405 TypeLoc,
1406 TypeRange,
1407 move(ArraySize),
1408 ConstructorLParen,
1409 move(ConstructorArgs),
1410 ConstructorRParen);
1411 }
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// \brief Build a new C++ "delete" expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1418 bool IsGlobalDelete,
1419 bool IsArrayForm,
1420 ExprArg Operand) {
1421 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1422 move(Operand));
1423 }
Mike Stump11289f42009-09-09 15:08:12 +00001424
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 /// \brief Build a new unary type trait expression.
1426 ///
1427 /// By default, performs semantic analysis to build the new expression.
1428 /// Subclasses may override this routine to provide different behavior.
1429 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1430 SourceLocation StartLoc,
1431 SourceLocation LParenLoc,
1432 QualType T,
1433 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001434 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001435 T.getAsOpaquePtr(), RParenLoc);
1436 }
1437
Mike Stump11289f42009-09-09 15:08:12 +00001438 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 /// expression.
1440 ///
1441 /// By default, performs semantic analysis to build the new expression.
1442 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001443 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 SourceRange QualifierRange,
1445 DeclarationName Name,
1446 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001447 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 CXXScopeSpec SS;
1449 SS.setRange(QualifierRange);
1450 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001451
1452 if (TemplateArgs)
1453 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1454 *TemplateArgs);
1455
1456 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new template-id expression.
1460 ///
1461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001463 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1464 LookupResult &R,
1465 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001466 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001467 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 }
1469
1470 /// \brief Build a new object-construction expression.
1471 ///
1472 /// By default, performs semantic analysis to build the new expression.
1473 /// Subclasses may override this routine to provide different behavior.
1474 OwningExprResult RebuildCXXConstructExpr(QualType T,
1475 CXXConstructorDecl *Constructor,
1476 bool IsElidable,
1477 MultiExprArg Args) {
Anders Carlsson1b4ebfa2009-09-05 07:40:38 +00001478 return getSema().BuildCXXConstructExpr(/*FIXME:ConstructLoc*/
1479 SourceLocation(),
1480 T, Constructor, IsElidable,
Anders Carlsson5995a3e2009-09-07 22:23:31 +00001481 move(Args));
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 }
1483
1484 /// \brief Build a new object-construction expression.
1485 ///
1486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
1488 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1489 QualType T,
1490 SourceLocation LParenLoc,
1491 MultiExprArg Args,
1492 SourceLocation *Commas,
1493 SourceLocation RParenLoc) {
1494 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1495 T.getAsOpaquePtr(),
1496 LParenLoc,
1497 move(Args),
1498 Commas,
1499 RParenLoc);
1500 }
1501
1502 /// \brief Build a new object-construction expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1507 QualType T,
1508 SourceLocation LParenLoc,
1509 MultiExprArg Args,
1510 SourceLocation *Commas,
1511 SourceLocation RParenLoc) {
1512 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1513 /*FIXME*/LParenLoc),
1514 T.getAsOpaquePtr(),
1515 LParenLoc,
1516 move(Args),
1517 Commas,
1518 RParenLoc);
1519 }
Mike Stump11289f42009-09-09 15:08:12 +00001520
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 /// \brief Build a new member reference expression.
1522 ///
1523 /// By default, performs semantic analysis to build the new expression.
1524 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001525 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001526 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 bool IsArrow,
1528 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001529 NestedNameSpecifier *Qualifier,
1530 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001531 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001533 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001534 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001536 SS.setRange(QualifierRange);
1537 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001538
John McCall2d74de92009-12-01 22:10:20 +00001539 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1540 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001541 SS, FirstQualifierInScope,
1542 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 }
1544
John McCall10eae182009-11-30 22:42:35 +00001545 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001546 ///
1547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001549 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001550 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001551 SourceLocation OperatorLoc,
1552 bool IsArrow,
1553 NestedNameSpecifier *Qualifier,
1554 SourceRange QualifierRange,
1555 LookupResult &R,
1556 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001557 CXXScopeSpec SS;
1558 SS.setRange(QualifierRange);
1559 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001560
John McCall2d74de92009-12-01 22:10:20 +00001561 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1562 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001563 SS, R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001564 }
Mike Stump11289f42009-09-09 15:08:12 +00001565
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 /// \brief Build a new Objective-C @encode expression.
1567 ///
1568 /// By default, performs semantic analysis to build the new expression.
1569 /// Subclasses may override this routine to provide different behavior.
1570 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
1571 QualType T,
1572 SourceLocation RParenLoc) {
1573 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, T,
1574 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001575 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001576
1577 /// \brief Build a new Objective-C protocol expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
1581 OwningExprResult RebuildObjCProtocolExpr(ObjCProtocolDecl *Protocol,
1582 SourceLocation AtLoc,
1583 SourceLocation ProtoLoc,
1584 SourceLocation LParenLoc,
1585 SourceLocation RParenLoc) {
1586 return SemaRef.Owned(SemaRef.ParseObjCProtocolExpression(
1587 Protocol->getIdentifier(),
1588 AtLoc,
1589 ProtoLoc,
1590 LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001591 RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 }
Mike Stump11289f42009-09-09 15:08:12 +00001593
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 /// \brief Build a new shuffle vector expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1598 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1599 MultiExprArg SubExprs,
1600 SourceLocation RParenLoc) {
1601 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001602 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1604 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1605 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1606 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001607
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 // Build a reference to the __builtin_shufflevector builtin
1609 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001610 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001612 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001614
1615 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 unsigned NumSubExprs = SubExprs.size();
1617 Expr **Subs = (Expr **)SubExprs.release();
1618 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1619 Subs, NumSubExprs,
1620 Builtin->getResultType(),
1621 RParenLoc);
1622 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001623
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 // Type-check the __builtin_shufflevector expression.
1625 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1626 if (Result.isInvalid())
1627 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001628
Douglas Gregora16548e2009-08-11 05:31:07 +00001629 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001630 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001632};
Douglas Gregora16548e2009-08-11 05:31:07 +00001633
Douglas Gregorebe10102009-08-20 07:17:43 +00001634template<typename Derived>
1635Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1636 if (!S)
1637 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregorebe10102009-08-20 07:17:43 +00001639 switch (S->getStmtClass()) {
1640 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregorebe10102009-08-20 07:17:43 +00001642 // Transform individual statement nodes
1643#define STMT(Node, Parent) \
1644 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1645#define EXPR(Node, Parent)
1646#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001647
Douglas Gregorebe10102009-08-20 07:17:43 +00001648 // Transform expressions by calling TransformExpr.
1649#define STMT(Node, Parent)
1650#define EXPR(Node, Parent) case Stmt::Node##Class:
1651#include "clang/AST/StmtNodes.def"
1652 {
1653 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1654 if (E.isInvalid())
1655 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001656
Douglas Gregor07eae022009-11-13 18:34:26 +00001657 return getSema().ActOnExprStmt(getSema().FullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001658 }
Mike Stump11289f42009-09-09 15:08:12 +00001659 }
1660
Douglas Gregorebe10102009-08-20 07:17:43 +00001661 return SemaRef.Owned(S->Retain());
1662}
Mike Stump11289f42009-09-09 15:08:12 +00001663
1664
Douglas Gregore922c772009-08-04 22:27:00 +00001665template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001666Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001667 if (!E)
1668 return SemaRef.Owned(E);
1669
1670 switch (E->getStmtClass()) {
1671 case Stmt::NoStmtClass: break;
1672#define STMT(Node, Parent) case Stmt::Node##Class: break;
1673#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001674 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001675#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001676 }
1677
Douglas Gregora16548e2009-08-11 05:31:07 +00001678 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001679}
1680
1681template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001682NestedNameSpecifier *
1683TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001684 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001685 QualType ObjectType,
1686 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001687 if (!NNS)
1688 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001689
Douglas Gregorebe10102009-08-20 07:17:43 +00001690 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001691 NestedNameSpecifier *Prefix = NNS->getPrefix();
1692 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001693 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001694 ObjectType,
1695 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001696 if (!Prefix)
1697 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001698
1699 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001700 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001701 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001702 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001703 }
Mike Stump11289f42009-09-09 15:08:12 +00001704
Douglas Gregor1135c352009-08-06 05:28:30 +00001705 switch (NNS->getKind()) {
1706 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001707 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001708 "Identifier nested-name-specifier with no prefix or object type");
1709 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1710 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001711 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001712
1713 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001714 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001715 ObjectType,
1716 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001717
Douglas Gregor1135c352009-08-06 05:28:30 +00001718 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001719 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001720 = cast_or_null<NamespaceDecl>(
1721 getDerived().TransformDecl(NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001722 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001723 Prefix == NNS->getPrefix() &&
1724 NS == NNS->getAsNamespace())
1725 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001726
Douglas Gregor1135c352009-08-06 05:28:30 +00001727 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1728 }
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregor1135c352009-08-06 05:28:30 +00001730 case NestedNameSpecifier::Global:
1731 // There is no meaningful transformation that one could perform on the
1732 // global scope.
1733 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001734
Douglas Gregor1135c352009-08-06 05:28:30 +00001735 case NestedNameSpecifier::TypeSpecWithTemplate:
1736 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001737 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregor1135c352009-08-06 05:28:30 +00001738 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001739 if (T.isNull())
1740 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001741
Douglas Gregor1135c352009-08-06 05:28:30 +00001742 if (!getDerived().AlwaysRebuild() &&
1743 Prefix == NNS->getPrefix() &&
1744 T == QualType(NNS->getAsType(), 0))
1745 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001746
1747 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1748 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregor1135c352009-08-06 05:28:30 +00001749 T);
1750 }
1751 }
Mike Stump11289f42009-09-09 15:08:12 +00001752
Douglas Gregor1135c352009-08-06 05:28:30 +00001753 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001754 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001755}
1756
1757template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001758DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001759TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001760 SourceLocation Loc,
1761 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001762 if (!Name)
1763 return Name;
1764
1765 switch (Name.getNameKind()) {
1766 case DeclarationName::Identifier:
1767 case DeclarationName::ObjCZeroArgSelector:
1768 case DeclarationName::ObjCOneArgSelector:
1769 case DeclarationName::ObjCMultiArgSelector:
1770 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001771 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001772 case DeclarationName::CXXUsingDirective:
1773 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001774
Douglas Gregorf816bd72009-09-03 22:13:48 +00001775 case DeclarationName::CXXConstructorName:
1776 case DeclarationName::CXXDestructorName:
1777 case DeclarationName::CXXConversionFunctionName: {
1778 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorc59e5612009-10-19 22:04:39 +00001779 QualType T;
1780 if (!ObjectType.isNull() &&
1781 isa<TemplateSpecializationType>(Name.getCXXNameType())) {
1782 TemplateSpecializationType *SpecType
1783 = cast<TemplateSpecializationType>(Name.getCXXNameType());
1784 T = TransformTemplateSpecializationType(SpecType, ObjectType);
1785 } else
1786 T = getDerived().TransformType(Name.getCXXNameType());
Douglas Gregorf816bd72009-09-03 22:13:48 +00001787 if (T.isNull())
1788 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregorf816bd72009-09-03 22:13:48 +00001790 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001791 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001792 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001793 }
Mike Stump11289f42009-09-09 15:08:12 +00001794 }
1795
Douglas Gregorf816bd72009-09-03 22:13:48 +00001796 return DeclarationName();
1797}
1798
1799template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001800TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001801TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1802 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00001803 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001804 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001805 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
1806 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
1807 if (!NNS)
1808 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001809
Douglas Gregor71dc5092009-08-06 06:41:21 +00001810 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001811 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001812 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1813 if (!TransTemplate)
1814 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregor71dc5092009-08-06 06:41:21 +00001816 if (!getDerived().AlwaysRebuild() &&
1817 NNS == QTN->getQualifier() &&
1818 TransTemplate == Template)
1819 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001820
Douglas Gregor71dc5092009-08-06 06:41:21 +00001821 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1822 TransTemplate);
1823 }
Mike Stump11289f42009-09-09 15:08:12 +00001824
John McCalle66edc12009-11-24 19:00:30 +00001825 // These should be getting filtered out before they make it into the AST.
1826 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001827 }
Mike Stump11289f42009-09-09 15:08:12 +00001828
Douglas Gregor71dc5092009-08-06 06:41:21 +00001829 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001830 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001831 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
1832 /*FIXME:*/SourceRange(getDerived().getBaseLocation()));
Douglas Gregor308047d2009-09-09 00:23:06 +00001833 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001834 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001835
Douglas Gregor71dc5092009-08-06 06:41:21 +00001836 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00001837 NNS == DTN->getQualifier() &&
1838 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00001839 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregor71395fa2009-11-04 00:56:37 +00001841 if (DTN->isIdentifier())
1842 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
1843 ObjectType);
1844
1845 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
1846 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001847 }
Mike Stump11289f42009-09-09 15:08:12 +00001848
Douglas Gregor71dc5092009-08-06 06:41:21 +00001849 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001850 TemplateDecl *TransTemplate
Douglas Gregor71dc5092009-08-06 06:41:21 +00001851 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Template));
1852 if (!TransTemplate)
1853 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001854
Douglas Gregor71dc5092009-08-06 06:41:21 +00001855 if (!getDerived().AlwaysRebuild() &&
1856 TransTemplate == Template)
1857 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001858
Douglas Gregor71dc5092009-08-06 06:41:21 +00001859 return TemplateName(TransTemplate);
1860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
John McCalle66edc12009-11-24 19:00:30 +00001862 // These should be getting filtered out before they reach the AST.
1863 assert(false && "overloaded function decl survived to here");
1864 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00001865}
1866
1867template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00001868void TreeTransform<Derived>::InventTemplateArgumentLoc(
1869 const TemplateArgument &Arg,
1870 TemplateArgumentLoc &Output) {
1871 SourceLocation Loc = getDerived().getBaseLocation();
1872 switch (Arg.getKind()) {
1873 case TemplateArgument::Null:
1874 llvm::llvm_unreachable("null template argument in TreeTransform");
1875 break;
1876
1877 case TemplateArgument::Type:
1878 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00001879 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00001880
1881 break;
1882
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001883 case TemplateArgument::Template:
1884 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
1885 break;
1886
John McCall0ad16662009-10-29 08:12:44 +00001887 case TemplateArgument::Expression:
1888 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
1889 break;
1890
1891 case TemplateArgument::Declaration:
1892 case TemplateArgument::Integral:
1893 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00001894 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00001895 break;
1896 }
1897}
1898
1899template<typename Derived>
1900bool TreeTransform<Derived>::TransformTemplateArgument(
1901 const TemplateArgumentLoc &Input,
1902 TemplateArgumentLoc &Output) {
1903 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00001904 switch (Arg.getKind()) {
1905 case TemplateArgument::Null:
1906 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00001907 Output = Input;
1908 return false;
Mike Stump11289f42009-09-09 15:08:12 +00001909
Douglas Gregore922c772009-08-04 22:27:00 +00001910 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00001911 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00001912 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00001913 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00001914
1915 DI = getDerived().TransformType(DI);
1916 if (!DI) return true;
1917
1918 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
1919 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001920 }
Mike Stump11289f42009-09-09 15:08:12 +00001921
Douglas Gregore922c772009-08-04 22:27:00 +00001922 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00001923 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00001924 DeclarationName Name;
1925 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
1926 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001927 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregore922c772009-08-04 22:27:00 +00001928 Decl *D = getDerived().TransformDecl(Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00001929 if (!D) return true;
1930
John McCall0d07eb32009-10-29 18:45:58 +00001931 Expr *SourceExpr = Input.getSourceDeclExpression();
1932 if (SourceExpr) {
1933 EnterExpressionEvaluationContext Unevaluated(getSema(),
1934 Action::Unevaluated);
1935 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
1936 if (E.isInvalid())
1937 SourceExpr = NULL;
1938 else {
1939 SourceExpr = E.takeAs<Expr>();
1940 SourceExpr->Retain();
1941 }
1942 }
1943
1944 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00001945 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001946 }
Mike Stump11289f42009-09-09 15:08:12 +00001947
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001948 case TemplateArgument::Template: {
1949 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
1950 TemplateName Template
1951 = getDerived().TransformTemplateName(Arg.getAsTemplate());
1952 if (Template.isNull())
1953 return true;
1954
1955 Output = TemplateArgumentLoc(TemplateArgument(Template),
1956 Input.getTemplateQualifierRange(),
1957 Input.getTemplateNameLoc());
1958 return false;
1959 }
1960
Douglas Gregore922c772009-08-04 22:27:00 +00001961 case TemplateArgument::Expression: {
1962 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00001963 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00001964 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00001965
John McCall0ad16662009-10-29 08:12:44 +00001966 Expr *InputExpr = Input.getSourceExpression();
1967 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
1968
1969 Sema::OwningExprResult E
1970 = getDerived().TransformExpr(InputExpr);
1971 if (E.isInvalid()) return true;
1972
1973 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00001974 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00001975 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
1976 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00001977 }
Mike Stump11289f42009-09-09 15:08:12 +00001978
Douglas Gregore922c772009-08-04 22:27:00 +00001979 case TemplateArgument::Pack: {
1980 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
1981 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00001982 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00001983 AEnd = Arg.pack_end();
1984 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00001985
John McCall0ad16662009-10-29 08:12:44 +00001986 // FIXME: preserve source information here when we start
1987 // caring about parameter packs.
1988
John McCall0d07eb32009-10-29 18:45:58 +00001989 TemplateArgumentLoc InputArg;
1990 TemplateArgumentLoc OutputArg;
1991 getDerived().InventTemplateArgumentLoc(*A, InputArg);
1992 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00001993 return true;
1994
John McCall0d07eb32009-10-29 18:45:58 +00001995 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00001996 }
1997 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00001998 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00001999 true);
John McCall0d07eb32009-10-29 18:45:58 +00002000 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002001 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002002 }
2003 }
Mike Stump11289f42009-09-09 15:08:12 +00002004
Douglas Gregore922c772009-08-04 22:27:00 +00002005 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002006 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002007}
2008
Douglas Gregord6ff3322009-08-04 16:50:30 +00002009//===----------------------------------------------------------------------===//
2010// Type transformation
2011//===----------------------------------------------------------------------===//
2012
2013template<typename Derived>
2014QualType TreeTransform<Derived>::TransformType(QualType T) {
2015 if (getDerived().AlreadyTransformed(T))
2016 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002017
John McCall550e0c22009-10-21 00:40:46 +00002018 // Temporary workaround. All of these transformations should
2019 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002020 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002021 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002022
John McCallbcd03502009-12-07 02:54:59 +00002023 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002024
John McCall550e0c22009-10-21 00:40:46 +00002025 if (!NewDI)
2026 return QualType();
2027
2028 return NewDI->getType();
2029}
2030
2031template<typename Derived>
John McCallbcd03502009-12-07 02:54:59 +00002032TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002033 if (getDerived().AlreadyTransformed(DI->getType()))
2034 return DI;
2035
2036 TypeLocBuilder TLB;
2037
2038 TypeLoc TL = DI->getTypeLoc();
2039 TLB.reserve(TL.getFullDataSize());
2040
2041 QualType Result = getDerived().TransformType(TLB, TL);
2042 if (Result.isNull())
2043 return 0;
2044
John McCallbcd03502009-12-07 02:54:59 +00002045 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002046}
2047
2048template<typename Derived>
2049QualType
2050TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
2051 switch (T.getTypeLocClass()) {
2052#define ABSTRACT_TYPELOC(CLASS, PARENT)
2053#define TYPELOC(CLASS, PARENT) \
2054 case TypeLoc::CLASS: \
2055 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
2056#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002057 }
Mike Stump11289f42009-09-09 15:08:12 +00002058
John McCall550e0c22009-10-21 00:40:46 +00002059 llvm::llvm_unreachable("unhandled type loc!");
2060 return QualType();
2061}
2062
2063/// FIXME: By default, this routine adds type qualifiers only to types
2064/// that can have qualifiers, and silently suppresses those qualifiers
2065/// that are not permitted (e.g., qualifiers on reference or function
2066/// types). This is the right thing for template instantiation, but
2067/// probably not for other clients.
2068template<typename Derived>
2069QualType
2070TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
2071 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002072 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002073
2074 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
2075 if (Result.isNull())
2076 return QualType();
2077
2078 // Silently suppress qualifiers if the result type can't be qualified.
2079 // FIXME: this is the right thing for template instantiation, but
2080 // probably not for other clients.
2081 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002082 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002083
John McCall550e0c22009-10-21 00:40:46 +00002084 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2085
2086 TLB.push<QualifiedTypeLoc>(Result);
2087
2088 // No location information to preserve.
2089
2090 return Result;
2091}
2092
2093template <class TyLoc> static inline
2094QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2095 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2096 NewT.setNameLoc(T.getNameLoc());
2097 return T.getType();
2098}
2099
2100// Ugly metaprogramming macros because I couldn't be bothered to make
2101// the equivalent template version work.
2102#define TransformPointerLikeType(TypeClass) do { \
2103 QualType PointeeType \
2104 = getDerived().TransformType(TLB, TL.getPointeeLoc()); \
2105 if (PointeeType.isNull()) \
2106 return QualType(); \
2107 \
2108 QualType Result = TL.getType(); \
2109 if (getDerived().AlwaysRebuild() || \
2110 PointeeType != TL.getPointeeLoc().getType()) { \
John McCall70dd5f62009-10-30 00:06:24 +00002111 Result = getDerived().Rebuild##TypeClass(PointeeType, \
2112 TL.getSigilLoc()); \
John McCall550e0c22009-10-21 00:40:46 +00002113 if (Result.isNull()) \
2114 return QualType(); \
2115 } \
2116 \
2117 TypeClass##Loc NewT = TLB.push<TypeClass##Loc>(Result); \
2118 NewT.setSigilLoc(TL.getSigilLoc()); \
2119 \
2120 return Result; \
2121} while(0)
2122
John McCall550e0c22009-10-21 00:40:46 +00002123template<typename Derived>
2124QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
2125 BuiltinTypeLoc T) {
2126 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002127}
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregord6ff3322009-08-04 16:50:30 +00002129template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002130QualType
John McCall550e0c22009-10-21 00:40:46 +00002131TreeTransform<Derived>::TransformFixedWidthIntType(TypeLocBuilder &TLB,
2132 FixedWidthIntTypeLoc T) {
2133 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002134}
Argyrios Kyrtzidise9189262009-08-19 01:28:17 +00002135
Douglas Gregord6ff3322009-08-04 16:50:30 +00002136template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002137QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
2138 ComplexTypeLoc T) {
2139 // FIXME: recurse?
2140 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002141}
Mike Stump11289f42009-09-09 15:08:12 +00002142
Douglas Gregord6ff3322009-08-04 16:50:30 +00002143template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002144QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
2145 PointerTypeLoc TL) {
2146 TransformPointerLikeType(PointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002147}
Mike Stump11289f42009-09-09 15:08:12 +00002148
2149template<typename Derived>
2150QualType
John McCall550e0c22009-10-21 00:40:46 +00002151TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
2152 BlockPointerTypeLoc TL) {
2153 TransformPointerLikeType(BlockPointerType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002154}
2155
John McCall70dd5f62009-10-30 00:06:24 +00002156/// Transforms a reference type. Note that somewhat paradoxically we
2157/// don't care whether the type itself is an l-value type or an r-value
2158/// type; we only care if the type was *written* as an l-value type
2159/// or an r-value type.
2160template<typename Derived>
2161QualType
2162TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
2163 ReferenceTypeLoc TL) {
2164 const ReferenceType *T = TL.getTypePtr();
2165
2166 // Note that this works with the pointee-as-written.
2167 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2168 if (PointeeType.isNull())
2169 return QualType();
2170
2171 QualType Result = TL.getType();
2172 if (getDerived().AlwaysRebuild() ||
2173 PointeeType != T->getPointeeTypeAsWritten()) {
2174 Result = getDerived().RebuildReferenceType(PointeeType,
2175 T->isSpelledAsLValue(),
2176 TL.getSigilLoc());
2177 if (Result.isNull())
2178 return QualType();
2179 }
2180
2181 // r-value references can be rebuilt as l-value references.
2182 ReferenceTypeLoc NewTL;
2183 if (isa<LValueReferenceType>(Result))
2184 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2185 else
2186 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2187 NewTL.setSigilLoc(TL.getSigilLoc());
2188
2189 return Result;
2190}
2191
Mike Stump11289f42009-09-09 15:08:12 +00002192template<typename Derived>
2193QualType
John McCall550e0c22009-10-21 00:40:46 +00002194TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
2195 LValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002196 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002197}
2198
Mike Stump11289f42009-09-09 15:08:12 +00002199template<typename Derived>
2200QualType
John McCall550e0c22009-10-21 00:40:46 +00002201TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
2202 RValueReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00002203 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002204}
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregord6ff3322009-08-04 16:50:30 +00002206template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002207QualType
John McCall550e0c22009-10-21 00:40:46 +00002208TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
2209 MemberPointerTypeLoc TL) {
2210 MemberPointerType *T = TL.getTypePtr();
2211
2212 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002213 if (PointeeType.isNull())
2214 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002215
John McCall550e0c22009-10-21 00:40:46 +00002216 // TODO: preserve source information for this.
2217 QualType ClassType
2218 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002219 if (ClassType.isNull())
2220 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002221
John McCall550e0c22009-10-21 00:40:46 +00002222 QualType Result = TL.getType();
2223 if (getDerived().AlwaysRebuild() ||
2224 PointeeType != T->getPointeeType() ||
2225 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002226 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2227 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002228 if (Result.isNull())
2229 return QualType();
2230 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002231
John McCall550e0c22009-10-21 00:40:46 +00002232 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2233 NewTL.setSigilLoc(TL.getSigilLoc());
2234
2235 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002236}
2237
Mike Stump11289f42009-09-09 15:08:12 +00002238template<typename Derived>
2239QualType
John McCall550e0c22009-10-21 00:40:46 +00002240TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
2241 ConstantArrayTypeLoc TL) {
2242 ConstantArrayType *T = TL.getTypePtr();
2243 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002244 if (ElementType.isNull())
2245 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002246
John McCall550e0c22009-10-21 00:40:46 +00002247 QualType Result = TL.getType();
2248 if (getDerived().AlwaysRebuild() ||
2249 ElementType != T->getElementType()) {
2250 Result = getDerived().RebuildConstantArrayType(ElementType,
2251 T->getSizeModifier(),
2252 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002253 T->getIndexTypeCVRQualifiers(),
2254 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002255 if (Result.isNull())
2256 return QualType();
2257 }
2258
2259 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2260 NewTL.setLBracketLoc(TL.getLBracketLoc());
2261 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002262
John McCall550e0c22009-10-21 00:40:46 +00002263 Expr *Size = TL.getSizeExpr();
2264 if (Size) {
2265 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2266 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2267 }
2268 NewTL.setSizeExpr(Size);
2269
2270 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002271}
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregord6ff3322009-08-04 16:50:30 +00002273template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002274QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002275 TypeLocBuilder &TLB,
2276 IncompleteArrayTypeLoc TL) {
2277 IncompleteArrayType *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().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002286 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002287 T->getIndexTypeCVRQualifiers(),
2288 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002289 if (Result.isNull())
2290 return QualType();
2291 }
2292
2293 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2294 NewTL.setLBracketLoc(TL.getLBracketLoc());
2295 NewTL.setRBracketLoc(TL.getRBracketLoc());
2296 NewTL.setSizeExpr(0);
2297
2298 return Result;
2299}
2300
2301template<typename Derived>
2302QualType
2303TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
2304 VariableArrayTypeLoc TL) {
2305 VariableArrayType *T = TL.getTypePtr();
2306 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2307 if (ElementType.isNull())
2308 return QualType();
2309
2310 // Array bounds are not potentially evaluated contexts
2311 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2312
2313 Sema::OwningExprResult SizeResult
2314 = getDerived().TransformExpr(T->getSizeExpr());
2315 if (SizeResult.isInvalid())
2316 return QualType();
2317
2318 Expr *Size = static_cast<Expr*>(SizeResult.get());
2319
2320 QualType Result = TL.getType();
2321 if (getDerived().AlwaysRebuild() ||
2322 ElementType != T->getElementType() ||
2323 Size != T->getSizeExpr()) {
2324 Result = getDerived().RebuildVariableArrayType(ElementType,
2325 T->getSizeModifier(),
2326 move(SizeResult),
2327 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002328 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002329 if (Result.isNull())
2330 return QualType();
2331 }
2332 else SizeResult.take();
2333
2334 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2335 NewTL.setLBracketLoc(TL.getLBracketLoc());
2336 NewTL.setRBracketLoc(TL.getRBracketLoc());
2337 NewTL.setSizeExpr(Size);
2338
2339 return Result;
2340}
2341
2342template<typename Derived>
2343QualType
2344TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
2345 DependentSizedArrayTypeLoc TL) {
2346 DependentSizedArrayType *T = TL.getTypePtr();
2347 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2348 if (ElementType.isNull())
2349 return QualType();
2350
2351 // Array bounds are not potentially evaluated contexts
2352 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2353
2354 Sema::OwningExprResult SizeResult
2355 = getDerived().TransformExpr(T->getSizeExpr());
2356 if (SizeResult.isInvalid())
2357 return QualType();
2358
2359 Expr *Size = static_cast<Expr*>(SizeResult.get());
2360
2361 QualType Result = TL.getType();
2362 if (getDerived().AlwaysRebuild() ||
2363 ElementType != T->getElementType() ||
2364 Size != T->getSizeExpr()) {
2365 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2366 T->getSizeModifier(),
2367 move(SizeResult),
2368 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002369 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002370 if (Result.isNull())
2371 return QualType();
2372 }
2373 else SizeResult.take();
2374
2375 // We might have any sort of array type now, but fortunately they
2376 // all have the same location layout.
2377 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2378 NewTL.setLBracketLoc(TL.getLBracketLoc());
2379 NewTL.setRBracketLoc(TL.getRBracketLoc());
2380 NewTL.setSizeExpr(Size);
2381
2382 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002383}
Mike Stump11289f42009-09-09 15:08:12 +00002384
2385template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002387 TypeLocBuilder &TLB,
2388 DependentSizedExtVectorTypeLoc TL) {
2389 DependentSizedExtVectorType *T = TL.getTypePtr();
2390
2391 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002392 QualType ElementType = getDerived().TransformType(T->getElementType());
2393 if (ElementType.isNull())
2394 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregore922c772009-08-04 22:27:00 +00002396 // Vector sizes are not potentially evaluated contexts
2397 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2398
Douglas Gregord6ff3322009-08-04 16:50:30 +00002399 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2400 if (Size.isInvalid())
2401 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002402
John McCall550e0c22009-10-21 00:40:46 +00002403 QualType Result = TL.getType();
2404 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002405 ElementType != T->getElementType() ||
2406 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002407 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002408 move(Size),
2409 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002410 if (Result.isNull())
2411 return QualType();
2412 }
2413 else Size.take();
2414
2415 // Result might be dependent or not.
2416 if (isa<DependentSizedExtVectorType>(Result)) {
2417 DependentSizedExtVectorTypeLoc NewTL
2418 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2419 NewTL.setNameLoc(TL.getNameLoc());
2420 } else {
2421 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2422 NewTL.setNameLoc(TL.getNameLoc());
2423 }
2424
2425 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002426}
Mike Stump11289f42009-09-09 15:08:12 +00002427
2428template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002429QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
2430 VectorTypeLoc TL) {
2431 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002432 QualType ElementType = getDerived().TransformType(T->getElementType());
2433 if (ElementType.isNull())
2434 return QualType();
2435
John McCall550e0c22009-10-21 00:40:46 +00002436 QualType Result = TL.getType();
2437 if (getDerived().AlwaysRebuild() ||
2438 ElementType != T->getElementType()) {
2439 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements());
2440 if (Result.isNull())
2441 return QualType();
2442 }
2443
2444 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2445 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002446
John McCall550e0c22009-10-21 00:40:46 +00002447 return Result;
2448}
2449
2450template<typename Derived>
2451QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
2452 ExtVectorTypeLoc TL) {
2453 VectorType *T = TL.getTypePtr();
2454 QualType ElementType = getDerived().TransformType(T->getElementType());
2455 if (ElementType.isNull())
2456 return QualType();
2457
2458 QualType Result = TL.getType();
2459 if (getDerived().AlwaysRebuild() ||
2460 ElementType != T->getElementType()) {
2461 Result = getDerived().RebuildExtVectorType(ElementType,
2462 T->getNumElements(),
2463 /*FIXME*/ SourceLocation());
2464 if (Result.isNull())
2465 return QualType();
2466 }
2467
2468 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2469 NewTL.setNameLoc(TL.getNameLoc());
2470
2471 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002472}
Mike Stump11289f42009-09-09 15:08:12 +00002473
2474template<typename Derived>
2475QualType
John McCall550e0c22009-10-21 00:40:46 +00002476TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
2477 FunctionProtoTypeLoc TL) {
2478 FunctionProtoType *T = TL.getTypePtr();
2479 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002480 if (ResultType.isNull())
2481 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002482
John McCall550e0c22009-10-21 00:40:46 +00002483 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002484 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002485 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
2486 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2487 ParmVarDecl *OldParm = TL.getArg(i);
Mike Stump11289f42009-09-09 15:08:12 +00002488
John McCall550e0c22009-10-21 00:40:46 +00002489 QualType NewType;
2490 ParmVarDecl *NewParm;
2491
2492 if (OldParm) {
John McCallbcd03502009-12-07 02:54:59 +00002493 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
John McCall550e0c22009-10-21 00:40:46 +00002494 assert(OldDI->getType() == T->getArgType(i));
2495
John McCallbcd03502009-12-07 02:54:59 +00002496 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
John McCall550e0c22009-10-21 00:40:46 +00002497 if (!NewDI)
2498 return QualType();
2499
2500 if (NewDI == OldDI)
2501 NewParm = OldParm;
2502 else
2503 NewParm = ParmVarDecl::Create(SemaRef.Context,
2504 OldParm->getDeclContext(),
2505 OldParm->getLocation(),
2506 OldParm->getIdentifier(),
2507 NewDI->getType(),
2508 NewDI,
2509 OldParm->getStorageClass(),
2510 /* DefArg */ NULL);
2511 NewType = NewParm->getType();
2512
2513 // Deal with the possibility that we don't have a parameter
2514 // declaration for this parameter.
2515 } else {
2516 NewParm = 0;
2517
2518 QualType OldType = T->getArgType(i);
2519 NewType = getDerived().TransformType(OldType);
2520 if (NewType.isNull())
2521 return QualType();
2522 }
2523
2524 ParamTypes.push_back(NewType);
2525 ParamDecls.push_back(NewParm);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002526 }
Mike Stump11289f42009-09-09 15:08:12 +00002527
John McCall550e0c22009-10-21 00:40:46 +00002528 QualType Result = TL.getType();
2529 if (getDerived().AlwaysRebuild() ||
2530 ResultType != T->getResultType() ||
2531 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2532 Result = getDerived().RebuildFunctionProtoType(ResultType,
2533 ParamTypes.data(),
2534 ParamTypes.size(),
2535 T->isVariadic(),
2536 T->getTypeQuals());
2537 if (Result.isNull())
2538 return QualType();
2539 }
Mike Stump11289f42009-09-09 15:08:12 +00002540
John McCall550e0c22009-10-21 00:40:46 +00002541 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2542 NewTL.setLParenLoc(TL.getLParenLoc());
2543 NewTL.setRParenLoc(TL.getRParenLoc());
2544 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2545 NewTL.setArg(i, ParamDecls[i]);
2546
2547 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002548}
Mike Stump11289f42009-09-09 15:08:12 +00002549
Douglas Gregord6ff3322009-08-04 16:50:30 +00002550template<typename Derived>
2551QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002552 TypeLocBuilder &TLB,
2553 FunctionNoProtoTypeLoc TL) {
2554 FunctionNoProtoType *T = TL.getTypePtr();
2555 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2556 if (ResultType.isNull())
2557 return QualType();
2558
2559 QualType Result = TL.getType();
2560 if (getDerived().AlwaysRebuild() ||
2561 ResultType != T->getResultType())
2562 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2563
2564 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2565 NewTL.setLParenLoc(TL.getLParenLoc());
2566 NewTL.setRParenLoc(TL.getRParenLoc());
2567
2568 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002569}
Mike Stump11289f42009-09-09 15:08:12 +00002570
John McCallb96ec562009-12-04 22:46:56 +00002571template<typename Derived> QualType
2572TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
2573 UnresolvedUsingTypeLoc TL) {
2574 UnresolvedUsingType *T = TL.getTypePtr();
2575 Decl *D = getDerived().TransformDecl(T->getDecl());
2576 if (!D)
2577 return QualType();
2578
2579 QualType Result = TL.getType();
2580 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2581 Result = getDerived().RebuildUnresolvedUsingType(D);
2582 if (Result.isNull())
2583 return QualType();
2584 }
2585
2586 // We might get an arbitrary type spec type back. We should at
2587 // least always get a type spec type, though.
2588 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2589 NewTL.setNameLoc(TL.getNameLoc());
2590
2591 return Result;
2592}
2593
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002595QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
2596 TypedefTypeLoc TL) {
2597 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002598 TypedefDecl *Typedef
2599 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(T->getDecl()));
2600 if (!Typedef)
2601 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002602
John McCall550e0c22009-10-21 00:40:46 +00002603 QualType Result = TL.getType();
2604 if (getDerived().AlwaysRebuild() ||
2605 Typedef != T->getDecl()) {
2606 Result = getDerived().RebuildTypedefType(Typedef);
2607 if (Result.isNull())
2608 return QualType();
2609 }
Mike Stump11289f42009-09-09 15:08:12 +00002610
John McCall550e0c22009-10-21 00:40:46 +00002611 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2612 NewTL.setNameLoc(TL.getNameLoc());
2613
2614 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002615}
Mike Stump11289f42009-09-09 15:08:12 +00002616
Douglas Gregord6ff3322009-08-04 16:50:30 +00002617template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002618QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
2619 TypeOfExprTypeLoc TL) {
2620 TypeOfExprType *T = TL.getTypePtr();
2621
Douglas Gregore922c772009-08-04 22:27:00 +00002622 // typeof expressions are not potentially evaluated contexts
2623 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002624
Douglas Gregord6ff3322009-08-04 16:50:30 +00002625 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2626 if (E.isInvalid())
2627 return QualType();
2628
John McCall550e0c22009-10-21 00:40:46 +00002629 QualType Result = TL.getType();
2630 if (getDerived().AlwaysRebuild() ||
2631 E.get() != T->getUnderlyingExpr()) {
2632 Result = getDerived().RebuildTypeOfExprType(move(E));
2633 if (Result.isNull())
2634 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635 }
John McCall550e0c22009-10-21 00:40:46 +00002636 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002637
John McCall550e0c22009-10-21 00:40:46 +00002638 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
2639 NewTL.setNameLoc(TL.getNameLoc());
2640
2641 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002642}
Mike Stump11289f42009-09-09 15:08:12 +00002643
2644template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002645QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
2646 TypeOfTypeLoc TL) {
2647 TypeOfType *T = TL.getTypePtr();
2648
John McCallbcd03502009-12-07 02:54:59 +00002649 // FIXME: should be an inner type, or at least have a TypeSourceInfo.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002650 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2651 if (Underlying.isNull())
2652 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002653
John McCall550e0c22009-10-21 00:40:46 +00002654 QualType Result = TL.getType();
2655 if (getDerived().AlwaysRebuild() ||
2656 Underlying != T->getUnderlyingType()) {
2657 Result = getDerived().RebuildTypeOfType(Underlying);
2658 if (Result.isNull())
2659 return QualType();
2660 }
Mike Stump11289f42009-09-09 15:08:12 +00002661
John McCall550e0c22009-10-21 00:40:46 +00002662 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
2663 NewTL.setNameLoc(TL.getNameLoc());
2664
2665 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002666}
Mike Stump11289f42009-09-09 15:08:12 +00002667
2668template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002669QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
2670 DecltypeTypeLoc TL) {
2671 DecltypeType *T = TL.getTypePtr();
2672
Douglas Gregore922c772009-08-04 22:27:00 +00002673 // decltype expressions are not potentially evaluated contexts
2674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002675
Douglas Gregord6ff3322009-08-04 16:50:30 +00002676 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2677 if (E.isInvalid())
2678 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002679
John McCall550e0c22009-10-21 00:40:46 +00002680 QualType Result = TL.getType();
2681 if (getDerived().AlwaysRebuild() ||
2682 E.get() != T->getUnderlyingExpr()) {
2683 Result = getDerived().RebuildDecltypeType(move(E));
2684 if (Result.isNull())
2685 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002686 }
John McCall550e0c22009-10-21 00:40:46 +00002687 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002688
John McCall550e0c22009-10-21 00:40:46 +00002689 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2690 NewTL.setNameLoc(TL.getNameLoc());
2691
2692 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002693}
2694
2695template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002696QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
2697 RecordTypeLoc TL) {
2698 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002699 RecordDecl *Record
John McCall550e0c22009-10-21 00:40:46 +00002700 = cast_or_null<RecordDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002701 if (!Record)
2702 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002703
John McCall550e0c22009-10-21 00:40:46 +00002704 QualType Result = TL.getType();
2705 if (getDerived().AlwaysRebuild() ||
2706 Record != T->getDecl()) {
2707 Result = getDerived().RebuildRecordType(Record);
2708 if (Result.isNull())
2709 return QualType();
2710 }
Mike Stump11289f42009-09-09 15:08:12 +00002711
John McCall550e0c22009-10-21 00:40:46 +00002712 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2713 NewTL.setNameLoc(TL.getNameLoc());
2714
2715 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002716}
Mike Stump11289f42009-09-09 15:08:12 +00002717
2718template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002719QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
2720 EnumTypeLoc TL) {
2721 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002722 EnumDecl *Enum
John McCall550e0c22009-10-21 00:40:46 +00002723 = cast_or_null<EnumDecl>(getDerived().TransformDecl(T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002724 if (!Enum)
2725 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002726
John McCall550e0c22009-10-21 00:40:46 +00002727 QualType Result = TL.getType();
2728 if (getDerived().AlwaysRebuild() ||
2729 Enum != T->getDecl()) {
2730 Result = getDerived().RebuildEnumType(Enum);
2731 if (Result.isNull())
2732 return QualType();
2733 }
Mike Stump11289f42009-09-09 15:08:12 +00002734
John McCall550e0c22009-10-21 00:40:46 +00002735 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2736 NewTL.setNameLoc(TL.getNameLoc());
2737
2738 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002739}
John McCallfcc33b02009-09-05 00:15:47 +00002740
2741template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002742QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
2743 ElaboratedTypeLoc TL) {
2744 ElaboratedType *T = TL.getTypePtr();
2745
2746 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002747 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2748 if (Underlying.isNull())
2749 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002750
John McCall550e0c22009-10-21 00:40:46 +00002751 QualType Result = TL.getType();
2752 if (getDerived().AlwaysRebuild() ||
2753 Underlying != T->getUnderlyingType()) {
2754 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
2755 if (Result.isNull())
2756 return QualType();
2757 }
Mike Stump11289f42009-09-09 15:08:12 +00002758
John McCall550e0c22009-10-21 00:40:46 +00002759 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
2760 NewTL.setNameLoc(TL.getNameLoc());
2761
2762 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00002763}
Mike Stump11289f42009-09-09 15:08:12 +00002764
2765
Douglas Gregord6ff3322009-08-04 16:50:30 +00002766template<typename Derived>
2767QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002768 TypeLocBuilder &TLB,
2769 TemplateTypeParmTypeLoc TL) {
2770 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002771}
2772
Mike Stump11289f42009-09-09 15:08:12 +00002773template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00002774QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00002775 TypeLocBuilder &TLB,
2776 SubstTemplateTypeParmTypeLoc TL) {
2777 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00002778}
2779
2780template<typename Derived>
Douglas Gregorc59e5612009-10-19 22:04:39 +00002781inline QualType
2782TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall550e0c22009-10-21 00:40:46 +00002783 TypeLocBuilder &TLB,
2784 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00002785 return TransformTemplateSpecializationType(TLB, TL, QualType());
2786}
John McCall550e0c22009-10-21 00:40:46 +00002787
John McCall0ad16662009-10-29 08:12:44 +00002788template<typename Derived>
2789QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
2790 const TemplateSpecializationType *TST,
2791 QualType ObjectType) {
2792 // FIXME: this entire method is a temporary workaround; callers
2793 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00002794
John McCall0ad16662009-10-29 08:12:44 +00002795 // Fake up a TemplateSpecializationTypeLoc.
2796 TypeLocBuilder TLB;
2797 TemplateSpecializationTypeLoc TL
2798 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
2799
John McCall0d07eb32009-10-29 18:45:58 +00002800 SourceLocation BaseLoc = getDerived().getBaseLocation();
2801
2802 TL.setTemplateNameLoc(BaseLoc);
2803 TL.setLAngleLoc(BaseLoc);
2804 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00002805 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2806 const TemplateArgument &TA = TST->getArg(i);
2807 TemplateArgumentLoc TAL;
2808 getDerived().InventTemplateArgumentLoc(TA, TAL);
2809 TL.setArgLocInfo(i, TAL.getLocInfo());
2810 }
2811
2812 TypeLocBuilder IgnoredTLB;
2813 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00002814}
2815
2816template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002817QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00002818 TypeLocBuilder &TLB,
2819 TemplateSpecializationTypeLoc TL,
2820 QualType ObjectType) {
2821 const TemplateSpecializationType *T = TL.getTypePtr();
2822
Mike Stump11289f42009-09-09 15:08:12 +00002823 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00002824 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002825 if (Template.isNull())
2826 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002827
John McCall6b51f282009-11-23 01:53:49 +00002828 TemplateArgumentListInfo NewTemplateArgs;
2829 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
2830 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
2831
2832 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
2833 TemplateArgumentLoc Loc;
2834 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00002835 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00002836 NewTemplateArgs.addArgument(Loc);
2837 }
Mike Stump11289f42009-09-09 15:08:12 +00002838
John McCall0ad16662009-10-29 08:12:44 +00002839 // FIXME: maybe don't rebuild if all the template arguments are the same.
2840
2841 QualType Result =
2842 getDerived().RebuildTemplateSpecializationType(Template,
2843 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00002844 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00002845
2846 if (!Result.isNull()) {
2847 TemplateSpecializationTypeLoc NewTL
2848 = TLB.push<TemplateSpecializationTypeLoc>(Result);
2849 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
2850 NewTL.setLAngleLoc(TL.getLAngleLoc());
2851 NewTL.setRAngleLoc(TL.getRAngleLoc());
2852 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
2853 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002854 }
Mike Stump11289f42009-09-09 15:08:12 +00002855
John McCall0ad16662009-10-29 08:12:44 +00002856 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002857}
Mike Stump11289f42009-09-09 15:08:12 +00002858
2859template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002860QualType
2861TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
2862 QualifiedNameTypeLoc TL) {
2863 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002864 NestedNameSpecifier *NNS
2865 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
2866 SourceRange());
2867 if (!NNS)
2868 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002869
Douglas Gregord6ff3322009-08-04 16:50:30 +00002870 QualType Named = getDerived().TransformType(T->getNamedType());
2871 if (Named.isNull())
2872 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002873
John McCall550e0c22009-10-21 00:40:46 +00002874 QualType Result = TL.getType();
2875 if (getDerived().AlwaysRebuild() ||
2876 NNS != T->getQualifier() ||
2877 Named != T->getNamedType()) {
2878 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
2879 if (Result.isNull())
2880 return QualType();
2881 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002882
John McCall550e0c22009-10-21 00:40:46 +00002883 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
2884 NewTL.setNameLoc(TL.getNameLoc());
2885
2886 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002887}
Mike Stump11289f42009-09-09 15:08:12 +00002888
2889template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002890QualType TreeTransform<Derived>::TransformTypenameType(TypeLocBuilder &TLB,
2891 TypenameTypeLoc TL) {
2892 TypenameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00002893
2894 /* FIXME: preserve source information better than this */
2895 SourceRange SR(TL.getNameLoc());
2896
Douglas Gregord6ff3322009-08-04 16:50:30 +00002897 NestedNameSpecifier *NNS
John McCall0ad16662009-10-29 08:12:44 +00002898 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002899 if (!NNS)
2900 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002901
John McCall550e0c22009-10-21 00:40:46 +00002902 QualType Result;
2903
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00002905 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00002906 = getDerived().TransformType(QualType(TemplateId, 0));
2907 if (NewTemplateId.isNull())
2908 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002909
Douglas Gregord6ff3322009-08-04 16:50:30 +00002910 if (!getDerived().AlwaysRebuild() &&
2911 NNS == T->getQualifier() &&
2912 NewTemplateId == QualType(TemplateId, 0))
2913 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00002914
John McCall550e0c22009-10-21 00:40:46 +00002915 Result = getDerived().RebuildTypenameType(NNS, NewTemplateId);
2916 } else {
John McCall0ad16662009-10-29 08:12:44 +00002917 Result = getDerived().RebuildTypenameType(NNS, T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002918 }
John McCall550e0c22009-10-21 00:40:46 +00002919 if (Result.isNull())
2920 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002921
John McCall550e0c22009-10-21 00:40:46 +00002922 TypenameTypeLoc NewTL = TLB.push<TypenameTypeLoc>(Result);
2923 NewTL.setNameLoc(TL.getNameLoc());
2924
2925 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002926}
Mike Stump11289f42009-09-09 15:08:12 +00002927
Douglas Gregord6ff3322009-08-04 16:50:30 +00002928template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002929QualType
2930TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
2931 ObjCInterfaceTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002932 assert(false && "TransformObjCInterfaceType unimplemented");
2933 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002934}
Mike Stump11289f42009-09-09 15:08:12 +00002935
2936template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002937QualType
2938TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
2939 ObjCObjectPointerTypeLoc TL) {
John McCallfc93cf92009-10-22 22:37:11 +00002940 assert(false && "TransformObjCObjectPointerType unimplemented");
2941 return QualType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00002942}
2943
Douglas Gregord6ff3322009-08-04 16:50:30 +00002944//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00002945// Statement transformation
2946//===----------------------------------------------------------------------===//
2947template<typename Derived>
2948Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002949TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
2950 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002951}
2952
2953template<typename Derived>
2954Sema::OwningStmtResult
2955TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
2956 return getDerived().TransformCompoundStmt(S, false);
2957}
2958
2959template<typename Derived>
2960Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002961TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00002962 bool IsStmtExpr) {
2963 bool SubStmtChanged = false;
2964 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
2965 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
2966 B != BEnd; ++B) {
2967 OwningStmtResult Result = getDerived().TransformStmt(*B);
2968 if (Result.isInvalid())
2969 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002970
Douglas Gregorebe10102009-08-20 07:17:43 +00002971 SubStmtChanged = SubStmtChanged || Result.get() != *B;
2972 Statements.push_back(Result.takeAs<Stmt>());
2973 }
Mike Stump11289f42009-09-09 15:08:12 +00002974
Douglas Gregorebe10102009-08-20 07:17:43 +00002975 if (!getDerived().AlwaysRebuild() &&
2976 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00002977 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00002978
2979 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
2980 move_arg(Statements),
2981 S->getRBracLoc(),
2982 IsStmtExpr);
2983}
Mike Stump11289f42009-09-09 15:08:12 +00002984
Douglas Gregorebe10102009-08-20 07:17:43 +00002985template<typename Derived>
2986Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00002987TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00002988 OwningExprResult LHS(SemaRef), RHS(SemaRef);
2989 {
2990 // The case value expressions are not potentially evaluated.
2991 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002992
Eli Friedman06577382009-11-19 03:14:00 +00002993 // Transform the left-hand case value.
2994 LHS = getDerived().TransformExpr(S->getLHS());
2995 if (LHS.isInvalid())
2996 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002997
Eli Friedman06577382009-11-19 03:14:00 +00002998 // Transform the right-hand case value (for the GNU case-range extension).
2999 RHS = getDerived().TransformExpr(S->getRHS());
3000 if (RHS.isInvalid())
3001 return SemaRef.StmtError();
3002 }
Mike Stump11289f42009-09-09 15:08:12 +00003003
Douglas Gregorebe10102009-08-20 07:17:43 +00003004 // Build the case statement.
3005 // Case statements are always rebuilt so that they will attached to their
3006 // transformed switch statement.
3007 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3008 move(LHS),
3009 S->getEllipsisLoc(),
3010 move(RHS),
3011 S->getColonLoc());
3012 if (Case.isInvalid())
3013 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003014
Douglas Gregorebe10102009-08-20 07:17:43 +00003015 // Transform the statement following the case
3016 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3017 if (SubStmt.isInvalid())
3018 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003019
Douglas Gregorebe10102009-08-20 07:17:43 +00003020 // Attach the body to the case statement
3021 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3022}
3023
3024template<typename Derived>
3025Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003026TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003027 // Transform the statement following the default 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 // Default statements are always rebuilt
3033 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3034 move(SubStmt));
3035}
Mike Stump11289f42009-09-09 15:08:12 +00003036
Douglas Gregorebe10102009-08-20 07:17:43 +00003037template<typename Derived>
3038Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003039TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003040 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 // FIXME: Pass the real colon location in.
3045 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3046 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3047 move(SubStmt));
3048}
Mike Stump11289f42009-09-09 15:08:12 +00003049
Douglas Gregorebe10102009-08-20 07:17:43 +00003050template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003051Sema::OwningStmtResult
3052TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003053 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003054 OwningExprResult Cond(SemaRef);
3055 VarDecl *ConditionVar = 0;
3056 if (S->getConditionVariable()) {
3057 ConditionVar
3058 = cast_or_null<VarDecl>(
3059 getDerived().TransformDefinition(S->getConditionVariable()));
3060 if (!ConditionVar)
3061 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003062 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003063 Cond = getDerived().TransformExpr(S->getCond());
3064
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003065 if (Cond.isInvalid())
3066 return SemaRef.StmtError();
3067 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003068
Douglas Gregorebe10102009-08-20 07:17:43 +00003069 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003070
Douglas Gregorebe10102009-08-20 07:17:43 +00003071 // Transform the "then" branch.
3072 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3073 if (Then.isInvalid())
3074 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregorebe10102009-08-20 07:17:43 +00003076 // Transform the "else" branch.
3077 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3078 if (Else.isInvalid())
3079 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003080
Douglas Gregorebe10102009-08-20 07:17:43 +00003081 if (!getDerived().AlwaysRebuild() &&
3082 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003083 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003084 Then.get() == S->getThen() &&
3085 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003086 return SemaRef.Owned(S->Retain());
3087
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003088 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3089 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003090 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003091}
3092
3093template<typename Derived>
3094Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003095TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003096 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003097 OwningExprResult Cond(SemaRef);
3098 VarDecl *ConditionVar = 0;
3099 if (S->getConditionVariable()) {
3100 ConditionVar
3101 = cast_or_null<VarDecl>(
3102 getDerived().TransformDefinition(S->getConditionVariable()));
3103 if (!ConditionVar)
3104 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003105 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003106 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003107
3108 if (Cond.isInvalid())
3109 return SemaRef.StmtError();
3110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003112 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
3113
Douglas Gregorebe10102009-08-20 07:17:43 +00003114 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003115 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3116 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003117 if (Switch.isInvalid())
3118 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003119
Douglas Gregorebe10102009-08-20 07:17:43 +00003120 // Transform the body of the switch statement.
3121 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3122 if (Body.isInvalid())
3123 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003124
Douglas Gregorebe10102009-08-20 07:17:43 +00003125 // Complete the switch statement.
3126 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3127 move(Body));
3128}
Mike Stump11289f42009-09-09 15:08:12 +00003129
Douglas Gregorebe10102009-08-20 07:17:43 +00003130template<typename Derived>
3131Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003132TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003133 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003134 OwningExprResult Cond(SemaRef);
3135 VarDecl *ConditionVar = 0;
3136 if (S->getConditionVariable()) {
3137 ConditionVar
3138 = cast_or_null<VarDecl>(
3139 getDerived().TransformDefinition(S->getConditionVariable()));
3140 if (!ConditionVar)
3141 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003142 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003143 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003144
3145 if (Cond.isInvalid())
3146 return SemaRef.StmtError();
3147 }
Mike Stump11289f42009-09-09 15:08:12 +00003148
Douglas Gregorebe10102009-08-20 07:17:43 +00003149 Sema::FullExprArg FullCond(getSema().FullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003150
Douglas Gregorebe10102009-08-20 07:17:43 +00003151 // Transform the body
3152 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3153 if (Body.isInvalid())
3154 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003155
Douglas Gregorebe10102009-08-20 07:17:43 +00003156 if (!getDerived().AlwaysRebuild() &&
3157 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003158 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003159 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003160 return SemaRef.Owned(S->Retain());
3161
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003162 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3163 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003164}
Mike Stump11289f42009-09-09 15:08:12 +00003165
Douglas Gregorebe10102009-08-20 07:17:43 +00003166template<typename Derived>
3167Sema::OwningStmtResult
3168TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3169 // Transform the condition
3170 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3171 if (Cond.isInvalid())
3172 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003173
Douglas Gregorebe10102009-08-20 07:17:43 +00003174 // Transform the body
3175 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3176 if (Body.isInvalid())
3177 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003178
Douglas Gregorebe10102009-08-20 07:17:43 +00003179 if (!getDerived().AlwaysRebuild() &&
3180 Cond.get() == S->getCond() &&
3181 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003182 return SemaRef.Owned(S->Retain());
3183
Douglas Gregorebe10102009-08-20 07:17:43 +00003184 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3185 /*FIXME:*/S->getWhileLoc(), move(Cond),
3186 S->getRParenLoc());
3187}
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregorebe10102009-08-20 07:17:43 +00003189template<typename Derived>
3190Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003191TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003192 // Transform the initialization statement
3193 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3194 if (Init.isInvalid())
3195 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003196
Douglas Gregorebe10102009-08-20 07:17:43 +00003197 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003198 OwningExprResult Cond(SemaRef);
3199 VarDecl *ConditionVar = 0;
3200 if (S->getConditionVariable()) {
3201 ConditionVar
3202 = cast_or_null<VarDecl>(
3203 getDerived().TransformDefinition(S->getConditionVariable()));
3204 if (!ConditionVar)
3205 return SemaRef.StmtError();
3206 } else {
3207 Cond = getDerived().TransformExpr(S->getCond());
3208
3209 if (Cond.isInvalid())
3210 return SemaRef.StmtError();
3211 }
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregorebe10102009-08-20 07:17:43 +00003213 // Transform the increment
3214 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3215 if (Inc.isInvalid())
3216 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003217
Douglas Gregorebe10102009-08-20 07:17:43 +00003218 // Transform the body
3219 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3220 if (Body.isInvalid())
3221 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003222
Douglas Gregorebe10102009-08-20 07:17:43 +00003223 if (!getDerived().AlwaysRebuild() &&
3224 Init.get() == S->getInit() &&
3225 Cond.get() == S->getCond() &&
3226 Inc.get() == S->getInc() &&
3227 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003228 return SemaRef.Owned(S->Retain());
3229
Douglas Gregorebe10102009-08-20 07:17:43 +00003230 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003231 move(Init), getSema().FullExpr(Cond),
3232 ConditionVar,
3233 getSema().FullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003234 S->getRParenLoc(), move(Body));
3235}
3236
3237template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003238Sema::OwningStmtResult
3239TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003240 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003241 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003242 S->getLabel());
3243}
3244
3245template<typename Derived>
3246Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003247TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003248 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3249 if (Target.isInvalid())
3250 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003251
Douglas Gregorebe10102009-08-20 07:17:43 +00003252 if (!getDerived().AlwaysRebuild() &&
3253 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003254 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003255
3256 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3257 move(Target));
3258}
3259
3260template<typename Derived>
3261Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003262TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3263 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003264}
Mike Stump11289f42009-09-09 15:08:12 +00003265
Douglas Gregorebe10102009-08-20 07:17:43 +00003266template<typename Derived>
3267Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003268TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3269 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003270}
Mike Stump11289f42009-09-09 15:08:12 +00003271
Douglas Gregorebe10102009-08-20 07:17:43 +00003272template<typename Derived>
3273Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003274TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003275 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3276 if (Result.isInvalid())
3277 return SemaRef.StmtError();
3278
Mike Stump11289f42009-09-09 15:08:12 +00003279 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003280 // to tell whether the return type of the function has changed.
3281 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3282}
Mike Stump11289f42009-09-09 15:08:12 +00003283
Douglas Gregorebe10102009-08-20 07:17:43 +00003284template<typename Derived>
3285Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003286TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003287 bool DeclChanged = false;
3288 llvm::SmallVector<Decl *, 4> Decls;
3289 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3290 D != DEnd; ++D) {
3291 Decl *Transformed = getDerived().TransformDefinition(*D);
3292 if (!Transformed)
3293 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003294
Douglas Gregorebe10102009-08-20 07:17:43 +00003295 if (Transformed != *D)
3296 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003297
Douglas Gregorebe10102009-08-20 07:17:43 +00003298 Decls.push_back(Transformed);
3299 }
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003302 return SemaRef.Owned(S->Retain());
3303
3304 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003305 S->getStartLoc(), S->getEndLoc());
3306}
Mike Stump11289f42009-09-09 15:08:12 +00003307
Douglas Gregorebe10102009-08-20 07:17:43 +00003308template<typename Derived>
3309Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003310TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003311 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003312 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003313}
3314
3315template<typename Derived>
3316Sema::OwningStmtResult
3317TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
3318 // FIXME: Implement!
3319 assert(false && "Inline assembly cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003320 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003321}
3322
3323
3324template<typename Derived>
3325Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003326TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003327 // FIXME: Implement this
3328 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003329 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003330}
Mike Stump11289f42009-09-09 15:08:12 +00003331
Douglas Gregorebe10102009-08-20 07:17:43 +00003332template<typename Derived>
3333Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003334TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003335 // FIXME: Implement this
3336 assert(false && "Cannot transform an Objective-C @catch statement");
3337 return SemaRef.Owned(S->Retain());
3338}
Mike Stump11289f42009-09-09 15:08:12 +00003339
Douglas Gregorebe10102009-08-20 07:17:43 +00003340template<typename Derived>
3341Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003342TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003343 // FIXME: Implement this
3344 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003345 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003346}
Mike Stump11289f42009-09-09 15:08:12 +00003347
Douglas Gregorebe10102009-08-20 07:17:43 +00003348template<typename Derived>
3349Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003350TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003351 // FIXME: Implement this
3352 assert(false && "Cannot transform an Objective-C @throw statement");
Mike Stump11289f42009-09-09 15:08:12 +00003353 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003354}
Mike Stump11289f42009-09-09 15:08:12 +00003355
Douglas Gregorebe10102009-08-20 07:17:43 +00003356template<typename Derived>
3357Sema::OwningStmtResult
3358TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003359 ObjCAtSynchronizedStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003360 // FIXME: Implement this
3361 assert(false && "Cannot transform an Objective-C @synchronized statement");
Mike Stump11289f42009-09-09 15:08:12 +00003362 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003363}
3364
3365template<typename Derived>
3366Sema::OwningStmtResult
3367TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003368 ObjCForCollectionStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 // FIXME: Implement this
3370 assert(false && "Cannot transform an Objective-C for-each statement");
Mike Stump11289f42009-09-09 15:08:12 +00003371 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003372}
3373
3374
3375template<typename Derived>
3376Sema::OwningStmtResult
3377TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3378 // Transform the exception declaration, if any.
3379 VarDecl *Var = 0;
3380 if (S->getExceptionDecl()) {
3381 VarDecl *ExceptionDecl = S->getExceptionDecl();
3382 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3383 ExceptionDecl->getDeclName());
3384
3385 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3386 if (T.isNull())
3387 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003388
Douglas Gregorebe10102009-08-20 07:17:43 +00003389 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3390 T,
John McCallbcd03502009-12-07 02:54:59 +00003391 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003392 ExceptionDecl->getIdentifier(),
3393 ExceptionDecl->getLocation(),
3394 /*FIXME: Inaccurate*/
3395 SourceRange(ExceptionDecl->getLocation()));
3396 if (!Var || Var->isInvalidDecl()) {
3397 if (Var)
3398 Var->Destroy(SemaRef.Context);
3399 return SemaRef.StmtError();
3400 }
3401 }
Mike Stump11289f42009-09-09 15:08:12 +00003402
Douglas Gregorebe10102009-08-20 07:17:43 +00003403 // Transform the actual exception handler.
3404 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3405 if (Handler.isInvalid()) {
3406 if (Var)
3407 Var->Destroy(SemaRef.Context);
3408 return SemaRef.StmtError();
3409 }
Mike Stump11289f42009-09-09 15:08:12 +00003410
Douglas Gregorebe10102009-08-20 07:17:43 +00003411 if (!getDerived().AlwaysRebuild() &&
3412 !Var &&
3413 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003414 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003415
3416 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3417 Var,
3418 move(Handler));
3419}
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregorebe10102009-08-20 07:17:43 +00003421template<typename Derived>
3422Sema::OwningStmtResult
3423TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3424 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003425 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 = getDerived().TransformCompoundStmt(S->getTryBlock());
3427 if (TryBlock.isInvalid())
3428 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregorebe10102009-08-20 07:17:43 +00003430 // Transform the handlers.
3431 bool HandlerChanged = false;
3432 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3433 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003434 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003435 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3436 if (Handler.isInvalid())
3437 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003438
Douglas Gregorebe10102009-08-20 07:17:43 +00003439 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3440 Handlers.push_back(Handler.takeAs<Stmt>());
3441 }
Mike Stump11289f42009-09-09 15:08:12 +00003442
Douglas Gregorebe10102009-08-20 07:17:43 +00003443 if (!getDerived().AlwaysRebuild() &&
3444 TryBlock.get() == S->getTryBlock() &&
3445 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003446 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003447
3448 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003449 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003450}
Mike Stump11289f42009-09-09 15:08:12 +00003451
Douglas Gregorebe10102009-08-20 07:17:43 +00003452//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003453// Expression transformation
3454//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003455template<typename Derived>
3456Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003457TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003458 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003459}
Mike Stump11289f42009-09-09 15:08:12 +00003460
3461template<typename Derived>
3462Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003463TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003464 NestedNameSpecifier *Qualifier = 0;
3465 if (E->getQualifier()) {
3466 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3467 E->getQualifierRange());
3468 if (!Qualifier)
3469 return SemaRef.ExprError();
3470 }
John McCallce546572009-12-08 09:08:17 +00003471
3472 ValueDecl *ND
3473 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003474 if (!ND)
3475 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003476
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003477 if (!getDerived().AlwaysRebuild() &&
3478 Qualifier == E->getQualifier() &&
3479 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003480 !E->hasExplicitTemplateArgumentList()) {
3481
3482 // Mark it referenced in the new context regardless.
3483 // FIXME: this is a bit instantiation-specific.
3484 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3485
Mike Stump11289f42009-09-09 15:08:12 +00003486 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003487 }
John McCallce546572009-12-08 09:08:17 +00003488
3489 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3490 if (E->hasExplicitTemplateArgumentList()) {
3491 TemplateArgs = &TransArgs;
3492 TransArgs.setLAngleLoc(E->getLAngleLoc());
3493 TransArgs.setRAngleLoc(E->getRAngleLoc());
3494 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3495 TemplateArgumentLoc Loc;
3496 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3497 return SemaRef.ExprError();
3498 TransArgs.addArgument(Loc);
3499 }
3500 }
3501
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003502 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003503 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003504}
Mike Stump11289f42009-09-09 15:08:12 +00003505
Douglas Gregora16548e2009-08-11 05:31:07 +00003506template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003507Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003508TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003509 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003510}
Mike Stump11289f42009-09-09 15:08:12 +00003511
Douglas Gregora16548e2009-08-11 05:31:07 +00003512template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003513Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003514TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003515 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003516}
Mike Stump11289f42009-09-09 15:08:12 +00003517
Douglas Gregora16548e2009-08-11 05:31:07 +00003518template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003519Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003520TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003521 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003522}
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregora16548e2009-08-11 05:31:07 +00003524template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003525Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003526TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003527 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003528}
Mike Stump11289f42009-09-09 15:08:12 +00003529
Douglas Gregora16548e2009-08-11 05:31:07 +00003530template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003531Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003532TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003533 return SemaRef.Owned(E->Retain());
3534}
3535
3536template<typename Derived>
3537Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003538TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003539 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3540 if (SubExpr.isInvalid())
3541 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003542
Douglas Gregora16548e2009-08-11 05:31:07 +00003543 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003544 return SemaRef.Owned(E->Retain());
3545
3546 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003547 E->getRParen());
3548}
3549
Mike Stump11289f42009-09-09 15:08:12 +00003550template<typename Derived>
3551Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003552TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3553 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003554 if (SubExpr.isInvalid())
3555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003556
Douglas Gregora16548e2009-08-11 05:31:07 +00003557 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003558 return SemaRef.Owned(E->Retain());
3559
Douglas Gregora16548e2009-08-11 05:31:07 +00003560 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3561 E->getOpcode(),
3562 move(SubExpr));
3563}
Mike Stump11289f42009-09-09 15:08:12 +00003564
Douglas Gregora16548e2009-08-11 05:31:07 +00003565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003566Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003567TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003568 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003569 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003570
John McCallbcd03502009-12-07 02:54:59 +00003571 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003572 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003573 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003574
John McCall4c98fd82009-11-04 07:28:41 +00003575 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003576 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003577
John McCall4c98fd82009-11-04 07:28:41 +00003578 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003579 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003580 E->getSourceRange());
3581 }
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregora16548e2009-08-11 05:31:07 +00003583 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003584 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003585 // C++0x [expr.sizeof]p1:
3586 // The operand is either an expression, which is an unevaluated operand
3587 // [...]
3588 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003589
Douglas Gregora16548e2009-08-11 05:31:07 +00003590 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3591 if (SubExpr.isInvalid())
3592 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregora16548e2009-08-11 05:31:07 +00003594 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3595 return SemaRef.Owned(E->Retain());
3596 }
Mike Stump11289f42009-09-09 15:08:12 +00003597
Douglas Gregora16548e2009-08-11 05:31:07 +00003598 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3599 E->isSizeOf(),
3600 E->getSourceRange());
3601}
Mike Stump11289f42009-09-09 15:08:12 +00003602
Douglas Gregora16548e2009-08-11 05:31:07 +00003603template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003604Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003605TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003606 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3607 if (LHS.isInvalid())
3608 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003609
Douglas Gregora16548e2009-08-11 05:31:07 +00003610 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3611 if (RHS.isInvalid())
3612 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003613
3614
Douglas Gregora16548e2009-08-11 05:31:07 +00003615 if (!getDerived().AlwaysRebuild() &&
3616 LHS.get() == E->getLHS() &&
3617 RHS.get() == E->getRHS())
3618 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003619
Douglas Gregora16548e2009-08-11 05:31:07 +00003620 return getDerived().RebuildArraySubscriptExpr(move(LHS),
3621 /*FIXME:*/E->getLHS()->getLocStart(),
3622 move(RHS),
3623 E->getRBracketLoc());
3624}
Mike Stump11289f42009-09-09 15:08:12 +00003625
3626template<typename Derived>
3627Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003628TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003629 // Transform the callee.
3630 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
3631 if (Callee.isInvalid())
3632 return SemaRef.ExprError();
3633
3634 // Transform arguments.
3635 bool ArgChanged = false;
3636 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
3637 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
3638 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
3639 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
3640 if (Arg.isInvalid())
3641 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003642
Douglas Gregora16548e2009-08-11 05:31:07 +00003643 // FIXME: Wrong source location information for the ','.
3644 FakeCommaLocs.push_back(
3645 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00003646
3647 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00003648 Args.push_back(Arg.takeAs<Expr>());
3649 }
Mike Stump11289f42009-09-09 15:08:12 +00003650
Douglas Gregora16548e2009-08-11 05:31:07 +00003651 if (!getDerived().AlwaysRebuild() &&
3652 Callee.get() == E->getCallee() &&
3653 !ArgChanged)
3654 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003655
Douglas Gregora16548e2009-08-11 05:31:07 +00003656 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00003657 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003658 = ((Expr *)Callee.get())->getSourceRange().getBegin();
3659 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
3660 move_arg(Args),
3661 FakeCommaLocs.data(),
3662 E->getRParenLoc());
3663}
Mike Stump11289f42009-09-09 15:08:12 +00003664
3665template<typename Derived>
3666Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003667TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003668 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3669 if (Base.isInvalid())
3670 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003672 NestedNameSpecifier *Qualifier = 0;
3673 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00003674 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003675 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
3676 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00003677 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003678 return SemaRef.ExprError();
3679 }
Mike Stump11289f42009-09-09 15:08:12 +00003680
Eli Friedman2cfcef62009-12-04 06:40:45 +00003681 ValueDecl *Member
3682 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003683 if (!Member)
3684 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregora16548e2009-08-11 05:31:07 +00003686 if (!getDerived().AlwaysRebuild() &&
3687 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003688 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003689 Member == E->getMemberDecl() &&
3690 !E->hasExplicitTemplateArgumentList())
Mike Stump11289f42009-09-09 15:08:12 +00003691 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003692
John McCall6b51f282009-11-23 01:53:49 +00003693 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003694 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00003695 TransArgs.setLAngleLoc(E->getLAngleLoc());
3696 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003697 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00003698 TemplateArgumentLoc Loc;
3699 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003700 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00003701 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003702 }
3703 }
3704
Douglas Gregora16548e2009-08-11 05:31:07 +00003705 // FIXME: Bogus source location for the operator
3706 SourceLocation FakeOperatorLoc
3707 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
3708
3709 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
3710 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00003711 Qualifier,
3712 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003713 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003714 Member,
John McCall6b51f282009-11-23 01:53:49 +00003715 (E->hasExplicitTemplateArgumentList()
3716 ? &TransArgs : 0),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00003717 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00003718}
Mike Stump11289f42009-09-09 15:08:12 +00003719
Douglas Gregora16548e2009-08-11 05:31:07 +00003720template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003721Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003722TreeTransform<Derived>::TransformCastExpr(CastExpr *E) {
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
John McCall47f29ea2009-12-08 09:21:05 +00003729TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003730 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3731 if (LHS.isInvalid())
3732 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003733
Douglas Gregora16548e2009-08-11 05:31:07 +00003734 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3735 if (RHS.isInvalid())
3736 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregora16548e2009-08-11 05:31:07 +00003738 if (!getDerived().AlwaysRebuild() &&
3739 LHS.get() == E->getLHS() &&
3740 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00003741 return SemaRef.Owned(E->Retain());
3742
Douglas Gregora16548e2009-08-11 05:31:07 +00003743 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
3744 move(LHS), move(RHS));
3745}
3746
Mike Stump11289f42009-09-09 15:08:12 +00003747template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00003748Sema::OwningExprResult
3749TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00003750 CompoundAssignOperator *E) {
3751 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00003752}
Mike Stump11289f42009-09-09 15:08:12 +00003753
Douglas Gregora16548e2009-08-11 05:31:07 +00003754template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003755Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003756TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003757 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
3758 if (Cond.isInvalid())
3759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregora16548e2009-08-11 05:31:07 +00003761 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3762 if (LHS.isInvalid())
3763 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003764
Douglas Gregora16548e2009-08-11 05:31:07 +00003765 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
3766 if (RHS.isInvalid())
3767 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003768
Douglas Gregora16548e2009-08-11 05:31:07 +00003769 if (!getDerived().AlwaysRebuild() &&
3770 Cond.get() == E->getCond() &&
3771 LHS.get() == E->getLHS() &&
3772 RHS.get() == E->getRHS())
3773 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003774
3775 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003776 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003777 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00003778 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003779 move(RHS));
3780}
Mike Stump11289f42009-09-09 15:08:12 +00003781
3782template<typename Derived>
3783Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003784TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003785 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3786
3787 // FIXME: Will we ever have type information here? It seems like we won't,
3788 // so do we even need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003789 QualType T = getDerived().TransformType(E->getType());
3790 if (T.isNull())
3791 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003792
Douglas Gregora16548e2009-08-11 05:31:07 +00003793 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3794 if (SubExpr.isInvalid())
3795 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003796
Douglas Gregora16548e2009-08-11 05:31:07 +00003797 if (!getDerived().AlwaysRebuild() &&
3798 T == E->getType() &&
3799 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003800 return SemaRef.Owned(E->Retain());
3801
Douglas Gregora16548e2009-08-11 05:31:07 +00003802 return getDerived().RebuildImplicitCastExpr(T, E->getCastKind(),
Mike Stump11289f42009-09-09 15:08:12 +00003803 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00003804 E->isLvalueCast());
3805}
Mike Stump11289f42009-09-09 15:08:12 +00003806
Douglas Gregora16548e2009-08-11 05:31:07 +00003807template<typename Derived>
3808Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003809TreeTransform<Derived>::TransformExplicitCastExpr(ExplicitCastExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003810 assert(false && "Cannot transform abstract class");
3811 return SemaRef.Owned(E->Retain());
3812}
3813
3814template<typename Derived>
3815Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003816TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003817 QualType T;
3818 {
3819 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003820 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003821 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3822 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003823
Douglas Gregora16548e2009-08-11 05:31:07 +00003824 T = getDerived().TransformType(E->getTypeAsWritten());
3825 if (T.isNull())
3826 return SemaRef.ExprError();
3827 }
Mike Stump11289f42009-09-09 15:08:12 +00003828
Douglas Gregora16548e2009-08-11 05:31:07 +00003829 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3830 if (SubExpr.isInvalid())
3831 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003832
Douglas Gregora16548e2009-08-11 05:31:07 +00003833 if (!getDerived().AlwaysRebuild() &&
3834 T == E->getTypeAsWritten() &&
3835 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003836 return SemaRef.Owned(E->Retain());
3837
Douglas Gregora16548e2009-08-11 05:31:07 +00003838 return getDerived().RebuildCStyleCaseExpr(E->getLParenLoc(), T,
3839 E->getRParenLoc(),
3840 move(SubExpr));
3841}
Mike Stump11289f42009-09-09 15:08:12 +00003842
Douglas Gregora16548e2009-08-11 05:31:07 +00003843template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003844Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003845TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003846 QualType T;
3847 {
3848 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00003849 SourceLocation FakeTypeLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003850 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
3851 TemporaryBase Rebase(*this, FakeTypeLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00003852
Douglas Gregora16548e2009-08-11 05:31:07 +00003853 T = getDerived().TransformType(E->getType());
3854 if (T.isNull())
3855 return SemaRef.ExprError();
3856 }
Mike Stump11289f42009-09-09 15:08:12 +00003857
Douglas Gregora16548e2009-08-11 05:31:07 +00003858 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
3859 if (Init.isInvalid())
3860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003861
Douglas Gregora16548e2009-08-11 05:31:07 +00003862 if (!getDerived().AlwaysRebuild() &&
3863 T == E->getType() &&
3864 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00003865 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003866
3867 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), T,
3868 /*FIXME:*/E->getInitializer()->getLocEnd(),
3869 move(Init));
3870}
Mike Stump11289f42009-09-09 15:08:12 +00003871
Douglas Gregora16548e2009-08-11 05:31:07 +00003872template<typename Derived>
3873Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003874TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003875 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
3876 if (Base.isInvalid())
3877 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003878
Douglas Gregora16548e2009-08-11 05:31:07 +00003879 if (!getDerived().AlwaysRebuild() &&
3880 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00003881 return SemaRef.Owned(E->Retain());
3882
Douglas Gregora16548e2009-08-11 05:31:07 +00003883 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00003884 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00003885 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
3886 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
3887 E->getAccessorLoc(),
3888 E->getAccessor());
3889}
Mike Stump11289f42009-09-09 15:08:12 +00003890
Douglas Gregora16548e2009-08-11 05:31:07 +00003891template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003892Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003893TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003894 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
3897 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
3898 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
3899 if (Init.isInvalid())
3900 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902 InitChanged = InitChanged || Init.get() != E->getInit(I);
3903 Inits.push_back(Init.takeAs<Expr>());
3904 }
Mike Stump11289f42009-09-09 15:08:12 +00003905
Douglas Gregora16548e2009-08-11 05:31:07 +00003906 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003907 return SemaRef.Owned(E->Retain());
3908
Douglas Gregora16548e2009-08-11 05:31:07 +00003909 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00003910 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregora16548e2009-08-11 05:31:07 +00003913template<typename Derived>
3914Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003915TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003916 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00003917
Douglas Gregorebe10102009-08-20 07:17:43 +00003918 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00003919 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
3920 if (Init.isInvalid())
3921 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregorebe10102009-08-20 07:17:43 +00003923 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00003924 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
3925 bool ExprChanged = false;
3926 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
3927 DEnd = E->designators_end();
3928 D != DEnd; ++D) {
3929 if (D->isFieldDesignator()) {
3930 Desig.AddDesignator(Designator::getField(D->getFieldName(),
3931 D->getDotLoc(),
3932 D->getFieldLoc()));
3933 continue;
3934 }
Mike Stump11289f42009-09-09 15:08:12 +00003935
Douglas Gregora16548e2009-08-11 05:31:07 +00003936 if (D->isArrayDesignator()) {
3937 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
3938 if (Index.isInvalid())
3939 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003940
3941 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003942 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003943
Douglas Gregora16548e2009-08-11 05:31:07 +00003944 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
3945 ArrayExprs.push_back(Index.release());
3946 continue;
3947 }
Mike Stump11289f42009-09-09 15:08:12 +00003948
Douglas Gregora16548e2009-08-11 05:31:07 +00003949 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00003950 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00003951 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
3952 if (Start.isInvalid())
3953 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003954
Douglas Gregora16548e2009-08-11 05:31:07 +00003955 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
3956 if (End.isInvalid())
3957 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003958
3959 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003960 End.get(),
3961 D->getLBracketLoc(),
3962 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00003963
Douglas Gregora16548e2009-08-11 05:31:07 +00003964 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
3965 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00003966
Douglas Gregora16548e2009-08-11 05:31:07 +00003967 ArrayExprs.push_back(Start.release());
3968 ArrayExprs.push_back(End.release());
3969 }
Mike Stump11289f42009-09-09 15:08:12 +00003970
Douglas Gregora16548e2009-08-11 05:31:07 +00003971 if (!getDerived().AlwaysRebuild() &&
3972 Init.get() == E->getInit() &&
3973 !ExprChanged)
3974 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003975
Douglas Gregora16548e2009-08-11 05:31:07 +00003976 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
3977 E->getEqualOrColonLoc(),
3978 E->usesGNUSyntax(), move(Init));
3979}
Mike Stump11289f42009-09-09 15:08:12 +00003980
Douglas Gregora16548e2009-08-11 05:31:07 +00003981template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003982Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00003983TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00003984 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00003985 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
3986
3987 // FIXME: Will we ever have proper type location here? Will we actually
3988 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00003989 QualType T = getDerived().TransformType(E->getType());
3990 if (T.isNull())
3991 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003992
Douglas Gregora16548e2009-08-11 05:31:07 +00003993 if (!getDerived().AlwaysRebuild() &&
3994 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00003995 return SemaRef.Owned(E->Retain());
3996
Douglas Gregora16548e2009-08-11 05:31:07 +00003997 return getDerived().RebuildImplicitValueInitExpr(T);
3998}
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004001Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004002TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004003 // FIXME: Do we want the type as written?
4004 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004005
Douglas Gregora16548e2009-08-11 05:31:07 +00004006 {
4007 // FIXME: Source location isn't quite accurate.
4008 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4009 T = getDerived().TransformType(E->getType());
4010 if (T.isNull())
4011 return SemaRef.ExprError();
4012 }
Mike Stump11289f42009-09-09 15:08:12 +00004013
Douglas Gregora16548e2009-08-11 05:31:07 +00004014 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4015 if (SubExpr.isInvalid())
4016 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004017
Douglas Gregora16548e2009-08-11 05:31:07 +00004018 if (!getDerived().AlwaysRebuild() &&
4019 T == E->getType() &&
4020 SubExpr.get() == E->getSubExpr())
4021 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregora16548e2009-08-11 05:31:07 +00004023 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4024 T, E->getRParenLoc());
4025}
4026
4027template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004028Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004029TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004030 bool ArgumentChanged = false;
4031 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4032 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4033 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4034 if (Init.isInvalid())
4035 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregora16548e2009-08-11 05:31:07 +00004037 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4038 Inits.push_back(Init.takeAs<Expr>());
4039 }
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4042 move_arg(Inits),
4043 E->getRParenLoc());
4044}
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046/// \brief Transform an address-of-label expression.
4047///
4048/// By default, the transformation of an address-of-label expression always
4049/// rebuilds the expression, so that the label identifier can be resolved to
4050/// the corresponding label statement by semantic analysis.
4051template<typename Derived>
4052Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004053TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004054 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4055 E->getLabel());
4056}
Mike Stump11289f42009-09-09 15:08:12 +00004057
4058template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004059Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004060TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004061 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004062 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4063 if (SubStmt.isInvalid())
4064 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004065
Douglas Gregora16548e2009-08-11 05:31:07 +00004066 if (!getDerived().AlwaysRebuild() &&
4067 SubStmt.get() == E->getSubStmt())
4068 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004069
4070 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004071 move(SubStmt),
4072 E->getRParenLoc());
4073}
Mike Stump11289f42009-09-09 15:08:12 +00004074
Douglas Gregora16548e2009-08-11 05:31:07 +00004075template<typename Derived>
4076Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004077TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004078 QualType T1, T2;
4079 {
4080 // FIXME: Source location isn't quite accurate.
4081 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004082
Douglas Gregora16548e2009-08-11 05:31:07 +00004083 T1 = getDerived().TransformType(E->getArgType1());
4084 if (T1.isNull())
4085 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 T2 = getDerived().TransformType(E->getArgType2());
4088 if (T2.isNull())
4089 return SemaRef.ExprError();
4090 }
4091
4092 if (!getDerived().AlwaysRebuild() &&
4093 T1 == E->getArgType1() &&
4094 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004095 return SemaRef.Owned(E->Retain());
4096
Douglas Gregora16548e2009-08-11 05:31:07 +00004097 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4098 T1, T2, E->getRParenLoc());
4099}
Mike Stump11289f42009-09-09 15:08:12 +00004100
Douglas Gregora16548e2009-08-11 05:31:07 +00004101template<typename Derived>
4102Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004103TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004104 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4105 if (Cond.isInvalid())
4106 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004107
Douglas Gregora16548e2009-08-11 05:31:07 +00004108 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4109 if (LHS.isInvalid())
4110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4113 if (RHS.isInvalid())
4114 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004115
Douglas Gregora16548e2009-08-11 05:31:07 +00004116 if (!getDerived().AlwaysRebuild() &&
4117 Cond.get() == E->getCond() &&
4118 LHS.get() == E->getLHS() &&
4119 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004120 return SemaRef.Owned(E->Retain());
4121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4123 move(Cond), move(LHS), move(RHS),
4124 E->getRParenLoc());
4125}
Mike Stump11289f42009-09-09 15:08:12 +00004126
Douglas Gregora16548e2009-08-11 05:31:07 +00004127template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004128Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004129TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004130 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004131}
4132
4133template<typename Derived>
4134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004135TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004136 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4137 if (Callee.isInvalid())
4138 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004139
John McCall47f29ea2009-12-08 09:21:05 +00004140 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004141 if (First.isInvalid())
4142 return SemaRef.ExprError();
4143
4144 OwningExprResult Second(SemaRef);
4145 if (E->getNumArgs() == 2) {
4146 Second = getDerived().TransformExpr(E->getArg(1));
4147 if (Second.isInvalid())
4148 return SemaRef.ExprError();
4149 }
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregora16548e2009-08-11 05:31:07 +00004151 if (!getDerived().AlwaysRebuild() &&
4152 Callee.get() == E->getCallee() &&
4153 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004154 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4155 return SemaRef.Owned(E->Retain());
4156
Douglas Gregora16548e2009-08-11 05:31:07 +00004157 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4158 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004159 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004160 move(First),
4161 move(Second));
4162}
Mike Stump11289f42009-09-09 15:08:12 +00004163
Douglas Gregora16548e2009-08-11 05:31:07 +00004164template<typename Derived>
4165Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004166TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4167 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004168}
Mike Stump11289f42009-09-09 15:08:12 +00004169
Douglas Gregora16548e2009-08-11 05:31:07 +00004170template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004171Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004172TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004173 QualType ExplicitTy;
4174 {
4175 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004176 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004177 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4178 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004179
Douglas Gregora16548e2009-08-11 05:31:07 +00004180 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4181 if (ExplicitTy.isNull())
4182 return SemaRef.ExprError();
4183 }
Mike Stump11289f42009-09-09 15:08:12 +00004184
Douglas Gregora16548e2009-08-11 05:31:07 +00004185 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4186 if (SubExpr.isInvalid())
4187 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004188
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 if (!getDerived().AlwaysRebuild() &&
4190 ExplicitTy == E->getTypeAsWritten() &&
4191 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004192 return SemaRef.Owned(E->Retain());
4193
Douglas Gregora16548e2009-08-11 05:31:07 +00004194 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004195 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4197 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4198 SourceLocation FakeRParenLoc
4199 = SemaRef.PP.getLocForEndOfToken(
4200 E->getSubExpr()->getSourceRange().getEnd());
4201 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004202 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004203 FakeLAngleLoc,
4204 ExplicitTy,
4205 FakeRAngleLoc,
4206 FakeRAngleLoc,
4207 move(SubExpr),
4208 FakeRParenLoc);
4209}
Mike Stump11289f42009-09-09 15:08:12 +00004210
Douglas Gregora16548e2009-08-11 05:31:07 +00004211template<typename Derived>
4212Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004213TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4214 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004215}
Mike Stump11289f42009-09-09 15:08:12 +00004216
4217template<typename Derived>
4218Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004219TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4220 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004221}
4222
Douglas Gregora16548e2009-08-11 05:31:07 +00004223template<typename Derived>
4224Sema::OwningExprResult
4225TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004226 CXXReinterpretCastExpr *E) {
4227 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230template<typename Derived>
4231Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004232TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4233 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004234}
Mike Stump11289f42009-09-09 15:08:12 +00004235
Douglas Gregora16548e2009-08-11 05:31:07 +00004236template<typename Derived>
4237Sema::OwningExprResult
4238TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004239 CXXFunctionalCastExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004240 QualType ExplicitTy;
4241 {
4242 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004243
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 ExplicitTy = getDerived().TransformType(E->getTypeAsWritten());
4245 if (ExplicitTy.isNull())
4246 return SemaRef.ExprError();
4247 }
Mike Stump11289f42009-09-09 15:08:12 +00004248
Douglas Gregora16548e2009-08-11 05:31:07 +00004249 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4250 if (SubExpr.isInvalid())
4251 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004252
Douglas Gregora16548e2009-08-11 05:31:07 +00004253 if (!getDerived().AlwaysRebuild() &&
4254 ExplicitTy == E->getTypeAsWritten() &&
4255 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004256 return SemaRef.Owned(E->Retain());
4257
Douglas Gregora16548e2009-08-11 05:31:07 +00004258 // FIXME: The end of the type's source range is wrong
4259 return getDerived().RebuildCXXFunctionalCastExpr(
4260 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
4261 ExplicitTy,
4262 /*FIXME:*/E->getSubExpr()->getLocStart(),
4263 move(SubExpr),
4264 E->getRParenLoc());
4265}
Mike Stump11289f42009-09-09 15:08:12 +00004266
Douglas Gregora16548e2009-08-11 05:31:07 +00004267template<typename Derived>
4268Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004269TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004270 if (E->isTypeOperand()) {
4271 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004272
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 QualType T = getDerived().TransformType(E->getTypeOperand());
4274 if (T.isNull())
4275 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004276
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 if (!getDerived().AlwaysRebuild() &&
4278 T == E->getTypeOperand())
4279 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004280
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4282 /*FIXME:*/E->getLocStart(),
4283 T,
4284 E->getLocEnd());
4285 }
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287 // We don't know whether the expression is potentially evaluated until
4288 // after we perform semantic analysis, so the expression is potentially
4289 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004290 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4294 if (SubExpr.isInvalid())
4295 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004296
Douglas Gregora16548e2009-08-11 05:31:07 +00004297 if (!getDerived().AlwaysRebuild() &&
4298 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004299 return SemaRef.Owned(E->Retain());
4300
Douglas Gregora16548e2009-08-11 05:31:07 +00004301 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4302 /*FIXME:*/E->getLocStart(),
4303 move(SubExpr),
4304 E->getLocEnd());
4305}
4306
4307template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004308Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004309TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004310 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004311}
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313template<typename Derived>
4314Sema::OwningExprResult
4315TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004316 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004317 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004318}
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320template<typename Derived>
4321Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004322TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004323 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 QualType T = getDerived().TransformType(E->getType());
4326 if (T.isNull())
4327 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004328
Douglas Gregora16548e2009-08-11 05:31:07 +00004329 if (!getDerived().AlwaysRebuild() &&
4330 T == E->getType())
4331 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T);
4334}
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336template<typename Derived>
4337Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004338TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4340 if (SubExpr.isInvalid())
4341 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004342
Douglas Gregora16548e2009-08-11 05:31:07 +00004343 if (!getDerived().AlwaysRebuild() &&
4344 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004345 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004346
4347 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4348}
Mike Stump11289f42009-09-09 15:08:12 +00004349
Douglas Gregora16548e2009-08-11 05:31:07 +00004350template<typename Derived>
4351Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004352TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004353 ParmVarDecl *Param
Douglas Gregora16548e2009-08-11 05:31:07 +00004354 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getParam()));
4355 if (!Param)
4356 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004357
Douglas Gregora16548e2009-08-11 05:31:07 +00004358 if (getDerived().AlwaysRebuild() &&
4359 Param == E->getParam())
4360 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004361
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 return getDerived().RebuildCXXDefaultArgExpr(Param);
4363}
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365template<typename Derived>
4366Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004367TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004368 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4369
4370 QualType T = getDerived().TransformType(E->getType());
4371 if (T.isNull())
4372 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004373
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 if (!getDerived().AlwaysRebuild() &&
4375 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004376 return SemaRef.Owned(E->Retain());
4377
4378 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 /*FIXME:*/E->getTypeBeginLoc(),
4380 T,
4381 E->getRParenLoc());
4382}
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384template<typename Derived>
4385Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004386TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 // Transform the type that we're allocating
4388 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4389 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4390 if (AllocType.isNull())
4391 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004392
Douglas Gregora16548e2009-08-11 05:31:07 +00004393 // Transform the size of the array we're allocating (if any).
4394 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4395 if (ArraySize.isInvalid())
4396 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 // Transform the placement arguments (if any).
4399 bool ArgumentChanged = false;
4400 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4401 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4402 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4403 if (Arg.isInvalid())
4404 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004405
Douglas Gregora16548e2009-08-11 05:31:07 +00004406 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4407 PlacementArgs.push_back(Arg.take());
4408 }
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregorebe10102009-08-20 07:17:43 +00004410 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004411 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4412 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4413 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4414 if (Arg.isInvalid())
4415 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004416
Douglas Gregora16548e2009-08-11 05:31:07 +00004417 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4418 ConstructorArgs.push_back(Arg.take());
4419 }
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 if (!getDerived().AlwaysRebuild() &&
4422 AllocType == E->getAllocatedType() &&
4423 ArraySize.get() == E->getArraySize() &&
4424 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004425 return SemaRef.Owned(E->Retain());
4426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4428 E->isGlobalNew(),
4429 /*FIXME:*/E->getLocStart(),
4430 move_arg(PlacementArgs),
4431 /*FIXME:*/E->getLocStart(),
4432 E->isParenTypeId(),
4433 AllocType,
4434 /*FIXME:*/E->getLocStart(),
4435 /*FIXME:*/SourceRange(),
4436 move(ArraySize),
4437 /*FIXME:*/E->getLocStart(),
4438 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004439 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
Douglas Gregora16548e2009-08-11 05:31:07 +00004442template<typename Derived>
4443Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004444TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4446 if (Operand.isInvalid())
4447 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004448
Douglas Gregora16548e2009-08-11 05:31:07 +00004449 if (!getDerived().AlwaysRebuild() &&
Mike Stump11289f42009-09-09 15:08:12 +00004450 Operand.get() == E->getArgument())
4451 return SemaRef.Owned(E->Retain());
4452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4454 E->isGlobalDelete(),
4455 E->isArrayForm(),
4456 move(Operand));
4457}
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459template<typename Derived>
4460Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004461TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004462 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00004463 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4464 if (Base.isInvalid())
4465 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregorad8a3362009-09-04 17:36:40 +00004467 NestedNameSpecifier *Qualifier
4468 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4469 E->getQualifierRange());
4470 if (E->getQualifier() && !Qualifier)
4471 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004472
Douglas Gregorad8a3362009-09-04 17:36:40 +00004473 QualType DestroyedType;
4474 {
4475 TemporaryBase Rebase(*this, E->getDestroyedTypeLoc(), DeclarationName());
4476 DestroyedType = getDerived().TransformType(E->getDestroyedType());
4477 if (DestroyedType.isNull())
4478 return SemaRef.ExprError();
4479 }
Mike Stump11289f42009-09-09 15:08:12 +00004480
Douglas Gregorad8a3362009-09-04 17:36:40 +00004481 if (!getDerived().AlwaysRebuild() &&
4482 Base.get() == E->getBase() &&
4483 Qualifier == E->getQualifier() &&
4484 DestroyedType == E->getDestroyedType())
4485 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregorad8a3362009-09-04 17:36:40 +00004487 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
4488 E->getOperatorLoc(),
4489 E->isArrow(),
4490 E->getDestroyedTypeLoc(),
4491 DestroyedType,
4492 Qualifier,
4493 E->getQualifierRange());
4494}
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregorad8a3362009-09-04 17:36:40 +00004496template<typename Derived>
4497Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00004498TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004499 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00004500 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
4501
4502 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
4503 Sema::LookupOrdinaryName);
4504
4505 // Transform all the decls.
4506 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
4507 E = Old->decls_end(); I != E; ++I) {
4508 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4509 if (!InstD)
4510 return SemaRef.ExprError();
4511
4512 // Expand using declarations.
4513 if (isa<UsingDecl>(InstD)) {
4514 UsingDecl *UD = cast<UsingDecl>(InstD);
4515 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4516 E = UD->shadow_end(); I != E; ++I)
4517 R.addDecl(*I);
4518 continue;
4519 }
4520
4521 R.addDecl(InstD);
4522 }
4523
4524 // Resolve a kind, but don't do any further analysis. If it's
4525 // ambiguous, the callee needs to deal with it.
4526 R.resolveKind();
4527
4528 // Rebuild the nested-name qualifier, if present.
4529 CXXScopeSpec SS;
4530 NestedNameSpecifier *Qualifier = 0;
4531 if (Old->getQualifier()) {
4532 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4533 Old->getQualifierRange());
4534 if (!Qualifier)
4535 return SemaRef.ExprError();
4536
4537 SS.setScopeRep(Qualifier);
4538 SS.setRange(Old->getQualifierRange());
4539 }
4540
4541 // If we have no template arguments, it's a normal declaration name.
4542 if (!Old->hasExplicitTemplateArgs())
4543 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
4544
4545 // If we have template arguments, rebuild them, then rebuild the
4546 // templateid expression.
4547 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
4548 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4549 TemplateArgumentLoc Loc;
4550 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
4551 return SemaRef.ExprError();
4552 TransArgs.addArgument(Loc);
4553 }
4554
4555 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
4556 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004557}
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559template<typename Derived>
4560Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004561TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004563
Douglas Gregora16548e2009-08-11 05:31:07 +00004564 QualType T = getDerived().TransformType(E->getQueriedType());
4565 if (T.isNull())
4566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004567
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 if (!getDerived().AlwaysRebuild() &&
4569 T == E->getQueriedType())
4570 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 // FIXME: Bad location information
4573 SourceLocation FakeLParenLoc
4574 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00004575
4576 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004577 E->getLocStart(),
4578 /*FIXME:*/FakeLParenLoc,
4579 T,
4580 E->getLocEnd());
4581}
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregora16548e2009-08-11 05:31:07 +00004583template<typename Derived>
4584Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004585TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004586 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004587 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00004588 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4589 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 if (!NNS)
4591 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004592
4593 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00004594 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
4595 if (!Name)
4596 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004597
John McCalle66edc12009-11-24 19:00:30 +00004598 if (!E->hasExplicitTemplateArgs()) {
4599 if (!getDerived().AlwaysRebuild() &&
4600 NNS == E->getQualifier() &&
4601 Name == E->getDeclName())
4602 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004603
John McCalle66edc12009-11-24 19:00:30 +00004604 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4605 E->getQualifierRange(),
4606 Name, E->getLocation(),
4607 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00004608 }
John McCall6b51f282009-11-23 01:53:49 +00004609
4610 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00004611 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004612 TemplateArgumentLoc Loc;
4613 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004615 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00004616 }
4617
John McCalle66edc12009-11-24 19:00:30 +00004618 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
4619 E->getQualifierRange(),
4620 Name, E->getLocation(),
4621 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004622}
4623
4624template<typename Derived>
4625Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004626TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
4628
4629 QualType T = getDerived().TransformType(E->getType());
4630 if (T.isNull())
4631 return SemaRef.ExprError();
4632
4633 CXXConstructorDecl *Constructor
4634 = cast_or_null<CXXConstructorDecl>(
4635 getDerived().TransformDecl(E->getConstructor()));
4636 if (!Constructor)
4637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 bool ArgumentChanged = false;
4640 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004641 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 ArgEnd = E->arg_end();
4643 Arg != ArgEnd; ++Arg) {
4644 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4645 if (TransArg.isInvalid())
4646 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4649 Args.push_back(TransArg.takeAs<Expr>());
4650 }
4651
4652 if (!getDerived().AlwaysRebuild() &&
4653 T == E->getType() &&
4654 Constructor == E->getConstructor() &&
4655 !ArgumentChanged)
4656 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 return getDerived().RebuildCXXConstructExpr(T, Constructor, E->isElidable(),
4659 move_arg(Args));
4660}
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662/// \brief Transform a C++ temporary-binding expression.
4663///
Mike Stump11289f42009-09-09 15:08:12 +00004664/// The transformation of a temporary-binding expression always attempts to
4665/// bind a new temporary variable to its subexpression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004666/// subexpression itself did not change, because the temporary variable itself
4667/// must be unique.
4668template<typename Derived>
4669Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004670TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4672 if (SubExpr.isInvalid())
4673 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004674
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 return SemaRef.MaybeBindToTemporary(SubExpr.takeAs<Expr>());
4676}
Mike Stump11289f42009-09-09 15:08:12 +00004677
4678/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00004679/// be destroyed after the expression is evaluated.
4680///
Mike Stump11289f42009-09-09 15:08:12 +00004681/// The transformation of a full expression always attempts to build a new
4682/// CXXExprWithTemporaries expression, even if the
Douglas Gregora16548e2009-08-11 05:31:07 +00004683/// subexpression itself did not change, because it will need to capture the
4684/// the new temporary variables introduced in the subexpression.
4685template<typename Derived>
4686Sema::OwningExprResult
4687TreeTransform<Derived>::TransformCXXExprWithTemporaries(
John McCall47f29ea2009-12-08 09:21:05 +00004688 CXXExprWithTemporaries *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004689 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4690 if (SubExpr.isInvalid())
4691 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 return SemaRef.Owned(
4694 SemaRef.MaybeCreateCXXExprWithTemporaries(SubExpr.takeAs<Expr>(),
4695 E->shouldDestroyTemporaries()));
4696}
Mike Stump11289f42009-09-09 15:08:12 +00004697
Douglas Gregora16548e2009-08-11 05:31:07 +00004698template<typename Derived>
4699Sema::OwningExprResult
4700TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004701 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4703 QualType T = getDerived().TransformType(E->getType());
4704 if (T.isNull())
4705 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004706
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 CXXConstructorDecl *Constructor
4708 = cast_or_null<CXXConstructorDecl>(
4709 getDerived().TransformDecl(E->getConstructor()));
4710 if (!Constructor)
4711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 bool ArgumentChanged = false;
4714 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4715 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00004716 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 ArgEnd = E->arg_end();
4718 Arg != ArgEnd; ++Arg) {
4719 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4720 if (TransArg.isInvalid())
4721 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004722
Douglas Gregora16548e2009-08-11 05:31:07 +00004723 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4724 Args.push_back((Expr *)TransArg.release());
4725 }
Mike Stump11289f42009-09-09 15:08:12 +00004726
Douglas Gregora16548e2009-08-11 05:31:07 +00004727 if (!getDerived().AlwaysRebuild() &&
4728 T == E->getType() &&
4729 Constructor == E->getConstructor() &&
4730 !ArgumentChanged)
4731 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733 // FIXME: Bogus location information
4734 SourceLocation CommaLoc;
4735 if (Args.size() > 1) {
4736 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00004737 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004738 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
4739 }
4740 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
4741 T,
4742 /*FIXME:*/E->getTypeBeginLoc(),
4743 move_arg(Args),
4744 &CommaLoc,
4745 E->getLocEnd());
4746}
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748template<typename Derived>
4749Sema::OwningExprResult
4750TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004751 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4753 QualType T = getDerived().TransformType(E->getTypeAsWritten());
4754 if (T.isNull())
4755 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004756
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 bool ArgumentChanged = false;
4758 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4759 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
4760 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
4761 ArgEnd = E->arg_end();
4762 Arg != ArgEnd; ++Arg) {
4763 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
4764 if (TransArg.isInvalid())
4765 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004766
Douglas Gregora16548e2009-08-11 05:31:07 +00004767 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
4768 FakeCommaLocs.push_back(
4769 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
4770 Args.push_back(TransArg.takeAs<Expr>());
4771 }
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 if (!getDerived().AlwaysRebuild() &&
4774 T == E->getTypeAsWritten() &&
4775 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004776 return SemaRef.Owned(E->Retain());
4777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 // FIXME: we're faking the locations of the commas
4779 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
4780 T,
4781 E->getLParenLoc(),
4782 move_arg(Args),
4783 FakeCommaLocs.data(),
4784 E->getRParenLoc());
4785}
Mike Stump11289f42009-09-09 15:08:12 +00004786
Douglas Gregora16548e2009-08-11 05:31:07 +00004787template<typename Derived>
4788Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00004789TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004790 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004792 OwningExprResult Base(SemaRef, (Expr*) 0);
4793 Expr *OldBase;
4794 QualType BaseType;
4795 QualType ObjectType;
4796 if (!E->isImplicitAccess()) {
4797 OldBase = E->getBase();
4798 Base = getDerived().TransformExpr(OldBase);
4799 if (Base.isInvalid())
4800 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004801
John McCall2d74de92009-12-01 22:10:20 +00004802 // Start the member reference and compute the object's type.
4803 Sema::TypeTy *ObjectTy = 0;
4804 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
4805 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004806 E->isArrow()? tok::arrow : tok::period,
John McCall2d74de92009-12-01 22:10:20 +00004807 ObjectTy);
4808 if (Base.isInvalid())
4809 return SemaRef.ExprError();
4810
4811 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
4812 BaseType = ((Expr*) Base.get())->getType();
4813 } else {
4814 OldBase = 0;
4815 BaseType = getDerived().TransformType(E->getBaseType());
4816 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
4817 }
Mike Stump11289f42009-09-09 15:08:12 +00004818
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004819 // Transform the first part of the nested-name-specifier that qualifies
4820 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00004821 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00004822 = getDerived().TransformFirstQualifierInScope(
4823 E->getFirstQualifierFoundInScope(),
4824 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004826 NestedNameSpecifier *Qualifier = 0;
4827 if (E->getQualifier()) {
4828 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
4829 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00004830 ObjectType,
4831 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004832 if (!Qualifier)
4833 return SemaRef.ExprError();
4834 }
Mike Stump11289f42009-09-09 15:08:12 +00004835
4836 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00004837 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00004838 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00004839 if (!Name)
4840 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004841
John McCall2d74de92009-12-01 22:10:20 +00004842 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00004843 // This is a reference to a member without an explicitly-specified
4844 // template argument list. Optimize for this common case.
4845 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00004846 Base.get() == OldBase &&
4847 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00004848 Qualifier == E->getQualifier() &&
4849 Name == E->getMember() &&
4850 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00004851 return SemaRef.Owned(E->Retain());
4852
John McCall8cd78132009-11-19 22:55:06 +00004853 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004854 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00004855 E->isArrow(),
4856 E->getOperatorLoc(),
4857 Qualifier,
4858 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00004859 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00004860 Name,
4861 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00004862 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00004863 }
4864
John McCall6b51f282009-11-23 01:53:49 +00004865 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00004866 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004867 TemplateArgumentLoc Loc;
4868 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00004869 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004870 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00004871 }
Mike Stump11289f42009-09-09 15:08:12 +00004872
John McCall8cd78132009-11-19 22:55:06 +00004873 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004874 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 E->isArrow(),
4876 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00004877 Qualifier,
4878 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00004879 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00004880 Name,
4881 E->getMemberLoc(),
4882 &TransArgs);
4883}
4884
4885template<typename Derived>
4886Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004887TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00004888 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00004889 OwningExprResult Base(SemaRef, (Expr*) 0);
4890 QualType BaseType;
4891 if (!Old->isImplicitAccess()) {
4892 Base = getDerived().TransformExpr(Old->getBase());
4893 if (Base.isInvalid())
4894 return SemaRef.ExprError();
4895 BaseType = ((Expr*) Base.get())->getType();
4896 } else {
4897 BaseType = getDerived().TransformType(Old->getBaseType());
4898 }
John McCall10eae182009-11-30 22:42:35 +00004899
4900 NestedNameSpecifier *Qualifier = 0;
4901 if (Old->getQualifier()) {
4902 Qualifier
4903 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
4904 Old->getQualifierRange());
4905 if (Qualifier == 0)
4906 return SemaRef.ExprError();
4907 }
4908
4909 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
4910 Sema::LookupOrdinaryName);
4911
4912 // Transform all the decls.
4913 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
4914 E = Old->decls_end(); I != E; ++I) {
4915 NamedDecl *InstD = static_cast<NamedDecl*>(getDerived().TransformDecl(*I));
4916 if (!InstD)
4917 return SemaRef.ExprError();
4918
4919 // Expand using declarations.
4920 if (isa<UsingDecl>(InstD)) {
4921 UsingDecl *UD = cast<UsingDecl>(InstD);
4922 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
4923 E = UD->shadow_end(); I != E; ++I)
4924 R.addDecl(*I);
4925 continue;
4926 }
4927
4928 R.addDecl(InstD);
4929 }
4930
4931 R.resolveKind();
4932
4933 TemplateArgumentListInfo TransArgs;
4934 if (Old->hasExplicitTemplateArgs()) {
4935 TransArgs.setLAngleLoc(Old->getLAngleLoc());
4936 TransArgs.setRAngleLoc(Old->getRAngleLoc());
4937 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
4938 TemplateArgumentLoc Loc;
4939 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
4940 Loc))
4941 return SemaRef.ExprError();
4942 TransArgs.addArgument(Loc);
4943 }
4944 }
4945
4946 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00004947 BaseType,
John McCall10eae182009-11-30 22:42:35 +00004948 Old->getOperatorLoc(),
4949 Old->isArrow(),
4950 Qualifier,
4951 Old->getQualifierRange(),
4952 R,
4953 (Old->hasExplicitTemplateArgs()
4954 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004955}
4956
4957template<typename Derived>
4958Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004959TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004960 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004961}
4962
Mike Stump11289f42009-09-09 15:08:12 +00004963template<typename Derived>
4964Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004965TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 // FIXME: poor source location
4967 TemporaryBase Rebase(*this, E->getAtLoc(), DeclarationName());
4968 QualType EncodedType = getDerived().TransformType(E->getEncodedType());
4969 if (EncodedType.isNull())
4970 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004971
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 if (!getDerived().AlwaysRebuild() &&
4973 EncodedType == E->getEncodedType())
Mike Stump11289f42009-09-09 15:08:12 +00004974 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004975
4976 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
4977 EncodedType,
4978 E->getRParenLoc());
4979}
Mike Stump11289f42009-09-09 15:08:12 +00004980
Douglas Gregora16548e2009-08-11 05:31:07 +00004981template<typename Derived>
4982Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004983TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004984 // FIXME: Implement this!
4985 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00004986 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004987}
4988
Mike Stump11289f42009-09-09 15:08:12 +00004989template<typename Derived>
4990Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004991TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004992 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004993}
4994
Mike Stump11289f42009-09-09 15:08:12 +00004995template<typename Derived>
4996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004997TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004998 ObjCProtocolDecl *Protocol
Douglas Gregora16548e2009-08-11 05:31:07 +00004999 = cast_or_null<ObjCProtocolDecl>(
5000 getDerived().TransformDecl(E->getProtocol()));
5001 if (!Protocol)
5002 return SemaRef.ExprError();
5003
5004 if (!getDerived().AlwaysRebuild() &&
5005 Protocol == E->getProtocol())
Mike Stump11289f42009-09-09 15:08:12 +00005006 return SemaRef.Owned(E->Retain());
5007
Douglas Gregora16548e2009-08-11 05:31:07 +00005008 return getDerived().RebuildObjCProtocolExpr(Protocol,
5009 E->getAtLoc(),
5010 /*FIXME:*/E->getAtLoc(),
5011 /*FIXME:*/E->getAtLoc(),
5012 E->getRParenLoc());
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregora16548e2009-08-11 05:31:07 +00005014}
5015
Mike Stump11289f42009-09-09 15:08:12 +00005016template<typename Derived>
5017Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005018TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 // FIXME: Implement this!
5020 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005021 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005022}
5023
Mike Stump11289f42009-09-09 15:08:12 +00005024template<typename Derived>
5025Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005026TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005027 // FIXME: Implement this!
5028 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005029 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005030}
5031
Mike Stump11289f42009-09-09 15:08:12 +00005032template<typename Derived>
5033Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005034TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005035 ObjCImplicitSetterGetterRefExpr *E) {
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
John McCall47f29ea2009-12-08 09:21:05 +00005043TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 // FIXME: Implement this!
5045 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005046 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005047}
5048
Mike Stump11289f42009-09-09 15:08:12 +00005049template<typename Derived>
5050Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005051TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 // FIXME: Implement this!
5053 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005054 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005055}
5056
Mike Stump11289f42009-09-09 15:08:12 +00005057template<typename Derived>
5058Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005059TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 bool ArgumentChanged = false;
5061 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5062 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5063 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5064 if (SubExpr.isInvalid())
5065 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5068 SubExprs.push_back(SubExpr.takeAs<Expr>());
5069 }
Mike Stump11289f42009-09-09 15:08:12 +00005070
Douglas Gregora16548e2009-08-11 05:31:07 +00005071 if (!getDerived().AlwaysRebuild() &&
5072 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005073 return SemaRef.Owned(E->Retain());
5074
Douglas Gregora16548e2009-08-11 05:31:07 +00005075 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5076 move_arg(SubExprs),
5077 E->getRParenLoc());
5078}
5079
Mike Stump11289f42009-09-09 15:08:12 +00005080template<typename Derived>
5081Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005083 // FIXME: Implement this!
5084 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005085 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005086}
5087
Mike Stump11289f42009-09-09 15:08:12 +00005088template<typename Derived>
5089Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005090TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005091 // FIXME: Implement this!
5092 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005093 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
Douglas Gregora16548e2009-08-11 05:31:07 +00005096//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005097// Type reconstruction
5098//===----------------------------------------------------------------------===//
5099
Mike Stump11289f42009-09-09 15:08:12 +00005100template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005101QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5102 SourceLocation Star) {
5103 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005104 getDerived().getBaseEntity());
5105}
5106
Mike Stump11289f42009-09-09 15:08:12 +00005107template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005108QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5109 SourceLocation Star) {
5110 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005111 getDerived().getBaseEntity());
5112}
5113
Mike Stump11289f42009-09-09 15:08:12 +00005114template<typename Derived>
5115QualType
John McCall70dd5f62009-10-30 00:06:24 +00005116TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5117 bool WrittenAsLValue,
5118 SourceLocation Sigil) {
5119 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5120 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005121}
5122
5123template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005124QualType
John McCall70dd5f62009-10-30 00:06:24 +00005125TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5126 QualType ClassType,
5127 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005128 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005129 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005130}
5131
5132template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005133QualType
John McCall70dd5f62009-10-30 00:06:24 +00005134TreeTransform<Derived>::RebuildObjCObjectPointerType(QualType PointeeType,
5135 SourceLocation Sigil) {
5136 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Sigil,
John McCall550e0c22009-10-21 00:40:46 +00005137 getDerived().getBaseEntity());
5138}
5139
5140template<typename Derived>
5141QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005142TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5143 ArrayType::ArraySizeModifier SizeMod,
5144 const llvm::APInt *Size,
5145 Expr *SizeExpr,
5146 unsigned IndexTypeQuals,
5147 SourceRange BracketsRange) {
5148 if (SizeExpr || !Size)
5149 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5150 IndexTypeQuals, BracketsRange,
5151 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005152
5153 QualType Types[] = {
5154 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5155 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5156 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005157 };
5158 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5159 QualType SizeType;
5160 for (unsigned I = 0; I != NumTypes; ++I)
5161 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5162 SizeType = Types[I];
5163 break;
5164 }
Mike Stump11289f42009-09-09 15:08:12 +00005165
Douglas Gregord6ff3322009-08-04 16:50:30 +00005166 if (SizeType.isNull())
5167 SizeType = SemaRef.Context.getFixedWidthIntType(Size->getBitWidth(), false);
Mike Stump11289f42009-09-09 15:08:12 +00005168
Douglas Gregord6ff3322009-08-04 16:50:30 +00005169 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005170 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005171 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005172 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005173}
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregord6ff3322009-08-04 16:50:30 +00005175template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005176QualType
5177TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005178 ArrayType::ArraySizeModifier SizeMod,
5179 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005180 unsigned IndexTypeQuals,
5181 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005182 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005183 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005184}
5185
5186template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005187QualType
Mike Stump11289f42009-09-09 15:08:12 +00005188TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005189 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005190 unsigned IndexTypeQuals,
5191 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005192 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005193 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005194}
Mike Stump11289f42009-09-09 15:08:12 +00005195
Douglas Gregord6ff3322009-08-04 16:50:30 +00005196template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005197QualType
5198TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005199 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005200 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005201 unsigned IndexTypeQuals,
5202 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005203 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005204 SizeExpr.takeAs<Expr>(),
5205 IndexTypeQuals, BracketsRange);
5206}
5207
5208template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005209QualType
5210TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005211 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005212 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005213 unsigned IndexTypeQuals,
5214 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005215 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005216 SizeExpr.takeAs<Expr>(),
5217 IndexTypeQuals, BracketsRange);
5218}
5219
5220template<typename Derived>
5221QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
5222 unsigned NumElements) {
5223 // FIXME: semantic checking!
5224 return SemaRef.Context.getVectorType(ElementType, NumElements);
5225}
Mike Stump11289f42009-09-09 15:08:12 +00005226
Douglas Gregord6ff3322009-08-04 16:50:30 +00005227template<typename Derived>
5228QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5229 unsigned NumElements,
5230 SourceLocation AttributeLoc) {
5231 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5232 NumElements, true);
5233 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005234 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005235 AttributeLoc);
5236 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5237 AttributeLoc);
5238}
Mike Stump11289f42009-09-09 15:08:12 +00005239
Douglas Gregord6ff3322009-08-04 16:50:30 +00005240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005241QualType
5242TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005244 SourceLocation AttributeLoc) {
5245 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5246}
Mike Stump11289f42009-09-09 15:08:12 +00005247
Douglas Gregord6ff3322009-08-04 16:50:30 +00005248template<typename Derived>
5249QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005250 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005251 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005252 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005253 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005254 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005255 Quals,
5256 getDerived().getBaseLocation(),
5257 getDerived().getBaseEntity());
5258}
Mike Stump11289f42009-09-09 15:08:12 +00005259
Douglas Gregord6ff3322009-08-04 16:50:30 +00005260template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005261QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5262 return SemaRef.Context.getFunctionNoProtoType(T);
5263}
5264
5265template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005266QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5267 assert(D && "no decl found");
5268 if (D->isInvalidDecl()) return QualType();
5269
5270 TypeDecl *Ty;
5271 if (isa<UsingDecl>(D)) {
5272 UsingDecl *Using = cast<UsingDecl>(D);
5273 assert(Using->isTypeName() &&
5274 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5275
5276 // A valid resolved using typename decl points to exactly one type decl.
5277 assert(++Using->shadow_begin() == Using->shadow_end());
5278 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5279
5280 } else {
5281 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5282 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5283 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5284 }
5285
5286 return SemaRef.Context.getTypeDeclType(Ty);
5287}
5288
5289template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005290QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005291 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5292}
5293
5294template<typename Derived>
5295QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5296 return SemaRef.Context.getTypeOfType(Underlying);
5297}
5298
5299template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005300QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005301 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5302}
5303
5304template<typename Derived>
5305QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005306 TemplateName Template,
5307 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005308 const TemplateArgumentListInfo &TemplateArgs) {
5309 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005310}
Mike Stump11289f42009-09-09 15:08:12 +00005311
Douglas Gregor1135c352009-08-06 05:28:30 +00005312template<typename Derived>
5313NestedNameSpecifier *
5314TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5315 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005316 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005317 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005318 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005319 CXXScopeSpec SS;
5320 // FIXME: The source location information is all wrong.
5321 SS.setRange(Range);
5322 SS.setScopeRep(Prefix);
5323 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005324 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005325 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005326 ObjectType,
5327 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005328 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005329}
5330
5331template<typename Derived>
5332NestedNameSpecifier *
5333TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5334 SourceRange Range,
5335 NamespaceDecl *NS) {
5336 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5337}
5338
5339template<typename Derived>
5340NestedNameSpecifier *
5341TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5342 SourceRange Range,
5343 bool TemplateKW,
5344 QualType T) {
5345 if (T->isDependentType() || T->isRecordType() ||
5346 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005347 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005348 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
5349 T.getTypePtr());
5350 }
Mike Stump11289f42009-09-09 15:08:12 +00005351
Douglas Gregor1135c352009-08-06 05:28:30 +00005352 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
5353 return 0;
5354}
Mike Stump11289f42009-09-09 15:08:12 +00005355
Douglas Gregor71dc5092009-08-06 06:41:21 +00005356template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005357TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005358TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5359 bool TemplateKW,
5360 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00005361 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00005362 Template);
5363}
5364
5365template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005366TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00005367TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00005368 const IdentifierInfo &II,
5369 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00005370 CXXScopeSpec SS;
5371 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00005372 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00005373 UnqualifiedId Name;
5374 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00005375 return getSema().ActOnDependentTemplateName(
5376 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005377 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00005378 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005379 ObjectType.getAsOpaquePtr(),
5380 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00005381 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00005382}
Mike Stump11289f42009-09-09 15:08:12 +00005383
Douglas Gregora16548e2009-08-11 05:31:07 +00005384template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00005385TemplateName
5386TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
5387 OverloadedOperatorKind Operator,
5388 QualType ObjectType) {
5389 CXXScopeSpec SS;
5390 SS.setRange(SourceRange(getDerived().getBaseLocation()));
5391 SS.setScopeRep(Qualifier);
5392 UnqualifiedId Name;
5393 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
5394 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
5395 Operator, SymbolLocations);
5396 return getSema().ActOnDependentTemplateName(
5397 /*FIXME:*/getDerived().getBaseLocation(),
5398 SS,
5399 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00005400 ObjectType.getAsOpaquePtr(),
5401 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00005402 .template getAsVal<TemplateName>();
5403}
5404
5405template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005406Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005407TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
5408 SourceLocation OpLoc,
5409 ExprArg Callee,
5410 ExprArg First,
5411 ExprArg Second) {
5412 Expr *FirstExpr = (Expr *)First.get();
5413 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00005414 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00005415 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00005416
Douglas Gregora16548e2009-08-11 05:31:07 +00005417 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00005418 if (Op == OO_Subscript) {
5419 if (!FirstExpr->getType()->isOverloadableType() &&
5420 !SecondExpr->getType()->isOverloadableType())
5421 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00005422 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00005423 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00005424 } else if (Op == OO_Arrow) {
5425 // -> is never a builtin operation.
5426 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00005427 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 if (!FirstExpr->getType()->isOverloadableType()) {
5429 // The argument is not of overloadable type, so try to create a
5430 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00005431 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005432 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00005433
Douglas Gregora16548e2009-08-11 05:31:07 +00005434 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
5435 }
5436 } else {
Mike Stump11289f42009-09-09 15:08:12 +00005437 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005438 !SecondExpr->getType()->isOverloadableType()) {
5439 // Neither of the arguments is an overloadable type, so try to
5440 // create a built-in binary operation.
5441 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005442 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005443 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
5444 if (Result.isInvalid())
5445 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005446
Douglas Gregora16548e2009-08-11 05:31:07 +00005447 First.release();
5448 Second.release();
5449 return move(Result);
5450 }
5451 }
Mike Stump11289f42009-09-09 15:08:12 +00005452
5453 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 // used during overload resolution.
5455 Sema::FunctionSet Functions;
Mike Stump11289f42009-09-09 15:08:12 +00005456
John McCalld14a8642009-11-21 08:51:07 +00005457 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
5458 assert(ULE->requiresADL());
5459
5460 // FIXME: Do we have to check
5461 // IsAcceptableNonMemberOperatorCandidate for each of these?
5462 for (UnresolvedLookupExpr::decls_iterator I = ULE->decls_begin(),
5463 E = ULE->decls_end(); I != E; ++I)
5464 Functions.insert(AnyFunctionDecl::getFromNamedDecl(*I));
5465 } else {
5466 Functions.insert(AnyFunctionDecl::getFromNamedDecl(
5467 cast<DeclRefExpr>(CalleeExpr)->getDecl()));
5468 }
Mike Stump11289f42009-09-09 15:08:12 +00005469
Douglas Gregora16548e2009-08-11 05:31:07 +00005470 // Add any functions found via argument-dependent lookup.
5471 Expr *Args[2] = { FirstExpr, SecondExpr };
5472 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00005473 DeclarationName OpName
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
Sebastian Redlc057f422009-10-23 19:23:15 +00005475 SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
5476 Functions);
Mike Stump11289f42009-09-09 15:08:12 +00005477
Douglas Gregora16548e2009-08-11 05:31:07 +00005478 // Create the overloaded operator invocation for unary operators.
5479 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00005480 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00005481 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
5482 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
5483 }
Mike Stump11289f42009-09-09 15:08:12 +00005484
Sebastian Redladba46e2009-10-29 20:17:01 +00005485 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00005486 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
5487 OpLoc,
5488 move(First),
5489 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00005490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00005492 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00005494 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
5496 if (Result.isInvalid())
5497 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005498
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 First.release();
5500 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00005501 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00005502}
Mike Stump11289f42009-09-09 15:08:12 +00005503
Douglas Gregord6ff3322009-08-04 16:50:30 +00005504} // end namespace clang
5505
5506#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H