blob: 7bcfeb1006350811630f4da2b7919ad0cdd54944 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//===----------------------------------------------------------------------===/
8//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
16#include "Sema.h"
John McCalle66edc12009-11-24 19:00:30 +000017#include "Lookup.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000018#include "clang/Sema/SemaDiagnostic.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000019#include "clang/AST/Decl.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000020#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000021#include "clang/AST/ExprCXX.h"
22#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000023#include "clang/AST/Stmt.h"
24#include "clang/AST/StmtCXX.h"
25#include "clang/AST/StmtObjC.h"
John McCall550e0c22009-10-21 00:40:46 +000026#include "clang/AST/TypeLocBuilder.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000027#include "clang/Parse/Ownership.h"
28#include "clang/Parse/Designator.h"
29#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000030#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000031#include <algorithm>
32
33namespace clang {
Mike Stump11289f42009-09-09 15:08:12 +000034
Douglas Gregord6ff3322009-08-04 16:50:30 +000035/// \brief A semantic tree transformation that allows one to transform one
36/// abstract syntax tree into another.
37///
Mike Stump11289f42009-09-09 15:08:12 +000038/// A new tree transformation is defined by creating a new subclass \c X of
39/// \c TreeTransform<X> and then overriding certain operations to provide
40/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000041/// instantiation is implemented as a tree transformation where the
42/// transformation of TemplateTypeParmType nodes involves substituting the
43/// template arguments for their corresponding template parameters; a similar
44/// transformation is performed for non-type template parameters and
45/// template template parameters.
46///
47/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000048/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// override any of the transformation or rebuild operators by providing an
50/// operation with the same signature as the default implementation. The
51/// overridding function should not be virtual.
52///
53/// Semantic tree transformations are split into two stages, either of which
54/// can be replaced by a subclass. The "transform" step transforms an AST node
55/// or the parts of an AST node using the various transformation functions,
56/// then passes the pieces on to the "rebuild" step, which constructs a new AST
57/// node of the appropriate kind from the pieces. The default transformation
58/// routines recursively transform the operands to composite AST nodes (e.g.,
59/// the pointee type of a PointerType node) and, if any of those operand nodes
60/// were changed by the transformation, invokes the rebuild operation to create
61/// a new AST node.
62///
Mike Stump11289f42009-09-09 15:08:12 +000063/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000064/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000065/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
66/// TransformTemplateName(), or TransformTemplateArgument() with entirely
67/// new implementations.
68///
69/// For more fine-grained transformations, subclasses can replace any of the
70/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000071/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000072/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000073/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// parameters. Additionally, subclasses can override the \c RebuildXXX
75/// functions to control how AST nodes are rebuilt when their operands change.
76/// By default, \c TreeTransform will invoke semantic analysis to rebuild
77/// AST nodes. However, certain other tree transformations (e.g, cloning) may
78/// be able to use more efficient rebuild steps.
79///
80/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000081/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
83/// operands have not changed (\c AlwaysRebuild()), and customize the
84/// default locations and entity names used for type-checking
85/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000086template<typename Derived>
87class TreeTransform {
88protected:
89 Sema &SemaRef;
Mike Stump11289f42009-09-09 15:08:12 +000090
91public:
Douglas Gregora16548e2009-08-11 05:31:07 +000092 typedef Sema::OwningStmtResult OwningStmtResult;
93 typedef Sema::OwningExprResult OwningExprResult;
94 typedef Sema::StmtArg StmtArg;
95 typedef Sema::ExprArg ExprArg;
96 typedef Sema::MultiExprArg MultiExprArg;
Douglas Gregorebe10102009-08-20 07:17:43 +000097 typedef Sema::MultiStmtArg MultiStmtArg;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +000098 typedef Sema::DeclPtrTy DeclPtrTy;
99
Douglas Gregord6ff3322009-08-04 16:50:30 +0000100 /// \brief Initializes a new tree transformer.
101 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000102
Douglas Gregord6ff3322009-08-04 16:50:30 +0000103 /// \brief Retrieves a reference to the derived class.
104 Derived &getDerived() { return static_cast<Derived&>(*this); }
105
106 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000107 const Derived &getDerived() const {
108 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000109 }
110
111 /// \brief Retrieves a reference to the semantic analysis object used for
112 /// this tree transform.
113 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000114
Douglas Gregord6ff3322009-08-04 16:50:30 +0000115 /// \brief Whether the transformation should always rebuild AST nodes, even
116 /// if none of the children have changed.
117 ///
118 /// Subclasses may override this function to specify when the transformation
119 /// should rebuild all AST nodes.
120 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000121
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Returns the location of the entity being transformed, if that
123 /// information was not available elsewhere in the AST.
124 ///
Mike Stump11289f42009-09-09 15:08:12 +0000125 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000126 /// provide an alternative implementation that provides better location
127 /// information.
128 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Returns the name of the entity being transformed, if that
131 /// information was not available elsewhere in the AST.
132 ///
133 /// By default, returns an empty name. Subclasses can provide an alternative
134 /// implementation with a more precise name.
135 DeclarationName getBaseEntity() { return DeclarationName(); }
136
Douglas Gregora16548e2009-08-11 05:31:07 +0000137 /// \brief Sets the "base" location and entity when that
138 /// information is known based on another transformation.
139 ///
140 /// By default, the source location and entity are ignored. Subclasses can
141 /// override this function to provide a customized implementation.
142 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000143
Douglas Gregora16548e2009-08-11 05:31:07 +0000144 /// \brief RAII object that temporarily sets the base location and entity
145 /// used for reporting diagnostics in types.
146 class TemporaryBase {
147 TreeTransform &Self;
148 SourceLocation OldLocation;
149 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregora16548e2009-08-11 05:31:07 +0000151 public:
152 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000153 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 OldLocation = Self.getDerived().getBaseLocation();
155 OldEntity = Self.getDerived().getBaseEntity();
156 Self.getDerived().setBase(Location, Entity);
157 }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregora16548e2009-08-11 05:31:07 +0000159 ~TemporaryBase() {
160 Self.getDerived().setBase(OldLocation, OldEntity);
161 }
162 };
Mike Stump11289f42009-09-09 15:08:12 +0000163
164 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000165 /// transformed.
166 ///
167 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000168 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000169 /// not change. For example, template instantiation need not traverse
170 /// non-dependent types.
171 bool AlreadyTransformed(QualType T) {
172 return T.isNull();
173 }
174
Douglas Gregord196a582009-12-14 19:27:10 +0000175 /// \brief Determine whether the given call argument should be dropped, e.g.,
176 /// because it is a default argument.
177 ///
178 /// Subclasses can provide an alternative implementation of this routine to
179 /// determine which kinds of call arguments get dropped. By default,
180 /// CXXDefaultArgument nodes are dropped (prior to transformation).
181 bool DropCallArgument(Expr *E) {
182 return E->isDefaultArgument();
183 }
184
Douglas Gregord6ff3322009-08-04 16:50:30 +0000185 /// \brief Transforms the given type into another type.
186 ///
John McCall550e0c22009-10-21 00:40:46 +0000187 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000188 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000189 /// function. This is expensive, but we don't mind, because
190 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000191 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000192 ///
193 /// \returns the transformed type.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000194 QualType TransformType(QualType T, QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000195
John McCall550e0c22009-10-21 00:40:46 +0000196 /// \brief Transforms the given type-with-location into a new
197 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000198 ///
John McCall550e0c22009-10-21 00:40:46 +0000199 /// By default, this routine transforms a type by delegating to the
200 /// appropriate TransformXXXType to build a new type. Subclasses
201 /// may override this function (to take over all type
202 /// transformations) or some set of the TransformXXXType functions
203 /// to alter the transformation.
Douglas Gregorfe17d252010-02-16 19:09:40 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
205 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000206
207 /// \brief Transform the given type-with-location into a new
208 /// type, collecting location information in the given builder
209 /// as necessary.
210 ///
Douglas Gregorfe17d252010-02-16 19:09:40 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
212 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000213
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000214 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000215 ///
Mike Stump11289f42009-09-09 15:08:12 +0000216 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000217 /// appropriate TransformXXXStmt function to transform a specific kind of
218 /// statement or the TransformExpr() function to transform an expression.
219 /// Subclasses may override this function to transform statements using some
220 /// other mechanism.
221 ///
222 /// \returns the transformed statement.
Douglas Gregora16548e2009-08-11 05:31:07 +0000223 OwningStmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000224
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000225 /// \brief Transform the given expression.
226 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000227 /// By default, this routine transforms an expression by delegating to the
228 /// appropriate TransformXXXExpr function to build a new expression.
229 /// Subclasses may override this function to transform expressions using some
230 /// other mechanism.
231 ///
232 /// \returns the transformed expression.
John McCall47f29ea2009-12-08 09:21:05 +0000233 OwningExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000234
Douglas Gregord6ff3322009-08-04 16:50:30 +0000235 /// \brief Transform the given declaration, which is referenced from a type
236 /// or expression.
237 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000238 /// By default, acts as the identity function on declarations. Subclasses
239 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000240 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000241
242 /// \brief Transform the definition of the given declaration.
243 ///
Mike Stump11289f42009-09-09 15:08:12 +0000244 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000245 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
Douglas Gregor25289362010-03-01 17:25:41 +0000247 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000248 }
Mike Stump11289f42009-09-09 15:08:12 +0000249
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000250 /// \brief Transform the given declaration, which was the first part of a
251 /// nested-name-specifier in a member access expression.
252 ///
253 /// This specific declaration transformation only applies to the first
254 /// identifier in a nested-name-specifier of a member access expression, e.g.,
255 /// the \c T in \c x->T::member
256 ///
257 /// By default, invokes TransformDecl() to transform the declaration.
258 /// Subclasses may override this function to provide alternate behavior.
259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
262
Douglas Gregord6ff3322009-08-04 16:50:30 +0000263 /// \brief Transform the given nested-name-specifier.
264 ///
Mike Stump11289f42009-09-09 15:08:12 +0000265 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000266 /// nested-name-specifier. Subclasses may override this function to provide
267 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000268 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000269 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000270 QualType ObjectType = QualType(),
271 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000272
Douglas Gregorf816bd72009-09-03 22:13:48 +0000273 /// \brief Transform the given declaration name.
274 ///
275 /// By default, transforms the types of conversion function, constructor,
276 /// and destructor names and then (if needed) rebuilds the declaration name.
277 /// Identifiers and selectors are returned unmodified. Sublcasses may
278 /// override this function to provide alternate behavior.
279 DeclarationName TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +0000280 SourceLocation Loc,
281 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000284 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000285 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000286 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000287 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000288 TemplateName TransformTemplateName(TemplateName Name,
289 QualType ObjectType = QualType());
Mike Stump11289f42009-09-09 15:08:12 +0000290
Douglas Gregord6ff3322009-08-04 16:50:30 +0000291 /// \brief Transform the given template argument.
292 ///
Mike Stump11289f42009-09-09 15:08:12 +0000293 /// By default, this operation transforms the type, expression, or
294 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000295 /// new template argument from the transformed result. Subclasses may
296 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000297 ///
298 /// Returns true if there was an error.
299 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
300 TemplateArgumentLoc &Output);
301
302 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
303 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
304 TemplateArgumentLoc &ArgLoc);
305
John McCallbcd03502009-12-07 02:54:59 +0000306 /// \brief Fakes up a TypeSourceInfo for a type.
307 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
308 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000309 getDerived().getBaseLocation());
310 }
Mike Stump11289f42009-09-09 15:08:12 +0000311
John McCall550e0c22009-10-21 00:40:46 +0000312#define ABSTRACT_TYPELOC(CLASS, PARENT)
313#define TYPELOC(CLASS, PARENT) \
Douglas Gregorfe17d252010-02-16 19:09:40 +0000314 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T, \
315 QualType ObjectType = QualType());
John McCall550e0c22009-10-21 00:40:46 +0000316#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000317
John McCall58f10c32010-03-11 09:03:00 +0000318 /// \brief Transforms the parameters of a function type into the
319 /// given vectors.
320 ///
321 /// The result vectors should be kept in sync; null entries in the
322 /// variables vector are acceptable.
323 ///
324 /// Return true on error.
325 bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
326 llvm::SmallVectorImpl<QualType> &PTypes,
327 llvm::SmallVectorImpl<ParmVarDecl*> &PVars);
328
329 /// \brief Transforms a single function-type parameter. Return null
330 /// on error.
331 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
332
Douglas Gregorfe17d252010-02-16 19:09:40 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Douglas Gregorc59e5612009-10-19 22:04:39 +0000336 QualType
337 TransformTemplateSpecializationType(const TemplateSpecializationType *T,
338 QualType ObjectType);
John McCall0ad16662009-10-29 08:12:44 +0000339
Douglas Gregorebe10102009-08-20 07:17:43 +0000340 OwningStmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
Zhongxing Xu105dfb52010-04-21 06:32:25 +0000341 OwningExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000342
Douglas Gregorebe10102009-08-20 07:17:43 +0000343#define STMT(Node, Parent) \
344 OwningStmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000345#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +0000346 OwningExprResult Transform##Node(Node *E);
Douglas Gregora16548e2009-08-11 05:31:07 +0000347#define ABSTRACT_EXPR(Node, Parent)
348#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +0000349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Build a new pointer type given its pointee type.
351 ///
352 /// By default, performs semantic analysis when building the pointer type.
353 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000354 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000355
356 /// \brief Build a new block pointer type given its pointee type.
357 ///
Mike Stump11289f42009-09-09 15:08:12 +0000358 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000359 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000360 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000361
John McCall70dd5f62009-10-30 00:06:24 +0000362 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000363 ///
John McCall70dd5f62009-10-30 00:06:24 +0000364 /// By default, performs semantic analysis when building the
365 /// reference type. Subclasses may override this routine to provide
366 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000367 ///
John McCall70dd5f62009-10-30 00:06:24 +0000368 /// \param LValue whether the type was written with an lvalue sigil
369 /// or an rvalue sigil.
370 QualType RebuildReferenceType(QualType ReferentType,
371 bool LValue,
372 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000373
Douglas Gregord6ff3322009-08-04 16:50:30 +0000374 /// \brief Build a new member pointer type given the pointee type and the
375 /// class type it refers into.
376 ///
377 /// By default, performs semantic analysis when building the member pointer
378 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000379 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
380 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000381
Douglas Gregord6ff3322009-08-04 16:50:30 +0000382 /// \brief Build a new array type given the element type, size
383 /// modifier, size of the array (if known), size expression, and index type
384 /// qualifiers.
385 ///
386 /// By default, performs semantic analysis when building the array type.
387 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000388 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000389 QualType RebuildArrayType(QualType ElementType,
390 ArrayType::ArraySizeModifier SizeMod,
391 const llvm::APInt *Size,
392 Expr *SizeExpr,
393 unsigned IndexTypeQuals,
394 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000395
Douglas Gregord6ff3322009-08-04 16:50:30 +0000396 /// \brief Build a new constant array type given the element type, size
397 /// modifier, (known) size of the array, and index type qualifiers.
398 ///
399 /// By default, performs semantic analysis when building the array type.
400 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000401 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000402 ArrayType::ArraySizeModifier SizeMod,
403 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000404 unsigned IndexTypeQuals,
405 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000406
Douglas Gregord6ff3322009-08-04 16:50:30 +0000407 /// \brief Build a new incomplete array type given the element type, size
408 /// modifier, and index type qualifiers.
409 ///
410 /// By default, performs semantic analysis when building the array type.
411 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000412 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000413 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000414 unsigned IndexTypeQuals,
415 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000416
Mike Stump11289f42009-09-09 15:08:12 +0000417 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000418 /// size modifier, size expression, and index type qualifiers.
419 ///
420 /// By default, performs semantic analysis when building the array type.
421 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000422 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000423 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000424 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 unsigned IndexTypeQuals,
426 SourceRange BracketsRange);
427
Mike Stump11289f42009-09-09 15:08:12 +0000428 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000429 /// size modifier, size expression, and index type qualifiers.
430 ///
431 /// By default, performs semantic analysis when building the array type.
432 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000433 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000434 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +0000435 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000436 unsigned IndexTypeQuals,
437 SourceRange BracketsRange);
438
439 /// \brief Build a new vector type given the element type and
440 /// number of elements.
441 ///
442 /// By default, performs semantic analysis when building the vector type.
443 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000444 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
445 bool IsAltiVec, bool IsPixel);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Douglas Gregore677daf2010-03-31 22:19:08 +0000537 /// By default, builds a new DependentNameType type from the
538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
567
568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
577 // FIXME: Note the lack of the "typename" specifier!
578 // Fall through
579 case ETK_Typename:
580 return SemaRef.CheckTypenameType(NNS, *Id, SR);
581
582 case ETK_Class: Kind = TagDecl::TK_class; break;
583 case ETK_Struct: Kind = TagDecl::TK_struct; break;
584 case ETK_Union: Kind = TagDecl::TK_union; break;
585 case ETK_Enum: Kind = TagDecl::TK_enum; break;
586 }
587
588 // We had a dependent elaborated-type-specifier that as been transformed
589 // into a non-dependent elaborated-type-specifier. Find the tag we're
590 // referring to.
591 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
592 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
593 if (!DC)
594 return QualType();
595
596 TagDecl *Tag = 0;
597 SemaRef.LookupQualifiedName(Result, DC);
598 switch (Result.getResultKind()) {
599 case LookupResult::NotFound:
600 case LookupResult::NotFoundInCurrentInstantiation:
601 break;
602
603 case LookupResult::Found:
604 Tag = Result.getAsSingle<TagDecl>();
605 break;
606
607 case LookupResult::FoundOverloaded:
608 case LookupResult::FoundUnresolvedValue:
609 llvm_unreachable("Tag lookup cannot find non-tags");
610 return QualType();
611
612 case LookupResult::Ambiguous:
613 // Let the LookupResult structure handle ambiguities.
614 return QualType();
615 }
616
617 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000618 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000619 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000620 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000621 return QualType();
622 }
623
624 // FIXME: Terrible location information
625 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
626 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
627 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
628 return QualType();
629 }
630
631 // Build the elaborated-type-specifier type.
632 QualType T = SemaRef.Context.getTypeDeclType(Tag);
633 T = SemaRef.Context.getQualifiedNameType(NNS, T);
634 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000635 }
Mike Stump11289f42009-09-09 15:08:12 +0000636
Douglas Gregor1135c352009-08-06 05:28:30 +0000637 /// \brief Build a new nested-name-specifier given the prefix and an
638 /// identifier that names the next step in the nested-name-specifier.
639 ///
640 /// By default, performs semantic analysis when building the new
641 /// nested-name-specifier. Subclasses may override this routine to provide
642 /// different behavior.
643 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
644 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000645 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000646 QualType ObjectType,
647 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000648
649 /// \brief Build a new nested-name-specifier given the prefix and the
650 /// namespace named in the next step in the nested-name-specifier.
651 ///
652 /// By default, performs semantic analysis when building the new
653 /// nested-name-specifier. Subclasses may override this routine to provide
654 /// different behavior.
655 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
656 SourceRange Range,
657 NamespaceDecl *NS);
658
659 /// \brief Build a new nested-name-specifier given the prefix and the
660 /// type named in the next step in the nested-name-specifier.
661 ///
662 /// By default, performs semantic analysis when building the new
663 /// nested-name-specifier. Subclasses may override this routine to provide
664 /// different behavior.
665 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
666 SourceRange Range,
667 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000668 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000669
670 /// \brief Build a new template name given a nested name specifier, a flag
671 /// indicating whether the "template" keyword was provided, and the template
672 /// that the template name refers to.
673 ///
674 /// By default, builds the new template name directly. Subclasses may override
675 /// this routine to provide different behavior.
676 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
677 bool TemplateKW,
678 TemplateDecl *Template);
679
Douglas Gregor71dc5092009-08-06 06:41:21 +0000680 /// \brief Build a new template name given a nested name specifier and the
681 /// name that is referred to as a template.
682 ///
683 /// By default, performs semantic analysis to determine whether the name can
684 /// be resolved to a specific template, then builds the appropriate kind of
685 /// template name. Subclasses may override this routine to provide different
686 /// behavior.
687 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000688 const IdentifierInfo &II,
689 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000690
Douglas Gregor71395fa2009-11-04 00:56:37 +0000691 /// \brief Build a new template name given a nested name specifier and the
692 /// overloaded operator name that is referred to as a template.
693 ///
694 /// By default, performs semantic analysis to determine whether the name can
695 /// be resolved to a specific template, then builds the appropriate kind of
696 /// template name. Subclasses may override this routine to provide different
697 /// behavior.
698 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
699 OverloadedOperatorKind Operator,
700 QualType ObjectType);
701
Douglas Gregorebe10102009-08-20 07:17:43 +0000702 /// \brief Build a new compound statement.
703 ///
704 /// By default, performs semantic analysis to build the new statement.
705 /// Subclasses may override this routine to provide different behavior.
706 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
707 MultiStmtArg Statements,
708 SourceLocation RBraceLoc,
709 bool IsStmtExpr) {
710 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
711 IsStmtExpr);
712 }
713
714 /// \brief Build a new case statement.
715 ///
716 /// By default, performs semantic analysis to build the new statement.
717 /// Subclasses may override this routine to provide different behavior.
718 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
719 ExprArg LHS,
720 SourceLocation EllipsisLoc,
721 ExprArg RHS,
722 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000723 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000724 ColonLoc);
725 }
Mike Stump11289f42009-09-09 15:08:12 +0000726
Douglas Gregorebe10102009-08-20 07:17:43 +0000727 /// \brief Attach the body to a new case statement.
728 ///
729 /// By default, performs semantic analysis to build the new statement.
730 /// Subclasses may override this routine to provide different behavior.
731 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
732 getSema().ActOnCaseStmtBody(S.get(), move(Body));
733 return move(S);
734 }
Mike Stump11289f42009-09-09 15:08:12 +0000735
Douglas Gregorebe10102009-08-20 07:17:43 +0000736 /// \brief Build a new default statement.
737 ///
738 /// By default, performs semantic analysis to build the new statement.
739 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000740 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000741 SourceLocation ColonLoc,
742 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000743 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000744 /*CurScope=*/0);
745 }
Mike Stump11289f42009-09-09 15:08:12 +0000746
Douglas Gregorebe10102009-08-20 07:17:43 +0000747 /// \brief Build a new label statement.
748 ///
749 /// By default, performs semantic analysis to build the new statement.
750 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000751 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 IdentifierInfo *Id,
753 SourceLocation ColonLoc,
754 StmtArg SubStmt) {
755 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
756 }
Mike Stump11289f42009-09-09 15:08:12 +0000757
Douglas Gregorebe10102009-08-20 07:17:43 +0000758 /// \brief Build a new "if" statement.
759 ///
760 /// By default, performs semantic analysis to build the new statement.
761 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000762 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000763 VarDecl *CondVar, StmtArg Then,
764 SourceLocation ElseLoc, StmtArg Else) {
765 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
766 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000767 }
Mike Stump11289f42009-09-09 15:08:12 +0000768
Douglas Gregorebe10102009-08-20 07:17:43 +0000769 /// \brief Start building a new switch statement.
770 ///
771 /// By default, performs semantic analysis to build the new statement.
772 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000773 OwningStmtResult RebuildSwitchStmtStart(Sema::FullExprArg Cond,
774 VarDecl *CondVar) {
775 return getSema().ActOnStartOfSwitchStmt(Cond, DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 }
Mike Stump11289f42009-09-09 15:08:12 +0000777
Douglas Gregorebe10102009-08-20 07:17:43 +0000778 /// \brief Attach the body to the switch statement.
779 ///
780 /// By default, performs semantic analysis to build the new statement.
781 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000782 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000783 StmtArg Switch, StmtArg Body) {
784 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
785 move(Body));
786 }
787
788 /// \brief Build a new while statement.
789 ///
790 /// By default, performs semantic analysis to build the new statement.
791 /// Subclasses may override this routine to provide different behavior.
792 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
793 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000794 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000795 StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000796 return getSema().ActOnWhileStmt(WhileLoc, Cond, DeclPtrTy::make(CondVar),
797 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000798 }
Mike Stump11289f42009-09-09 15:08:12 +0000799
Douglas Gregorebe10102009-08-20 07:17:43 +0000800 /// \brief Build a new do-while statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
804 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
805 SourceLocation WhileLoc,
806 SourceLocation LParenLoc,
807 ExprArg Cond,
808 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000809 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000810 move(Cond), RParenLoc);
811 }
812
813 /// \brief Build a new for statement.
814 ///
815 /// By default, performs semantic analysis to build the new statement.
816 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000817 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000818 SourceLocation LParenLoc,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000819 StmtArg Init, Sema::FullExprArg Cond,
820 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000821 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000822 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
823 DeclPtrTy::make(CondVar),
824 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000825 }
Mike Stump11289f42009-09-09 15:08:12 +0000826
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 /// \brief Build a new goto statement.
828 ///
829 /// By default, performs semantic analysis to build the new statement.
830 /// Subclasses may override this routine to provide different behavior.
831 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
832 SourceLocation LabelLoc,
833 LabelStmt *Label) {
834 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
835 }
836
837 /// \brief Build a new indirect goto statement.
838 ///
839 /// By default, performs semantic analysis to build the new statement.
840 /// Subclasses may override this routine to provide different behavior.
841 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
842 SourceLocation StarLoc,
843 ExprArg Target) {
844 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
845 }
Mike Stump11289f42009-09-09 15:08:12 +0000846
Douglas Gregorebe10102009-08-20 07:17:43 +0000847 /// \brief Build a new return statement.
848 ///
849 /// By default, performs semantic analysis to build the new statement.
850 /// Subclasses may override this routine to provide different behavior.
851 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
852 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000853
Douglas Gregorebe10102009-08-20 07:17:43 +0000854 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
855 }
Mike Stump11289f42009-09-09 15:08:12 +0000856
Douglas Gregorebe10102009-08-20 07:17:43 +0000857 /// \brief Build a new declaration statement.
858 ///
859 /// By default, performs semantic analysis to build the new statement.
860 /// Subclasses may override this routine to provide different behavior.
861 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000862 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 SourceLocation EndLoc) {
864 return getSema().Owned(
865 new (getSema().Context) DeclStmt(
866 DeclGroupRef::Create(getSema().Context,
867 Decls, NumDecls),
868 StartLoc, EndLoc));
869 }
Mike Stump11289f42009-09-09 15:08:12 +0000870
Anders Carlssonaaeef072010-01-24 05:50:09 +0000871 /// \brief Build a new inline asm statement.
872 ///
873 /// By default, performs semantic analysis to build the new statement.
874 /// Subclasses may override this routine to provide different behavior.
875 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
876 bool IsSimple,
877 bool IsVolatile,
878 unsigned NumOutputs,
879 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000880 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000881 MultiExprArg Constraints,
882 MultiExprArg Exprs,
883 ExprArg AsmString,
884 MultiExprArg Clobbers,
885 SourceLocation RParenLoc,
886 bool MSAsm) {
887 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
888 NumInputs, Names, move(Constraints),
889 move(Exprs), move(AsmString), move(Clobbers),
890 RParenLoc, MSAsm);
891 }
892
Douglas Gregor6148de72010-04-22 22:01:21 +0000893 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000894 ///
895 /// By default, performs semantic analysis to build the new statement.
896 /// Subclasses may override this routine to provide different behavior.
897 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
898 ExprArg Operand) {
899 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
900 }
901
Douglas Gregor6148de72010-04-22 22:01:21 +0000902 /// \brief Build a new Objective-C @synchronized statement.
903 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000904 /// By default, performs semantic analysis to build the new statement.
905 /// Subclasses may override this routine to provide different behavior.
906 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
907 ExprArg Object,
908 StmtArg Body) {
909 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
910 move(Body));
911 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000912
913 /// \brief Build a new Objective-C fast enumeration statement.
914 ///
915 /// By default, performs semantic analysis to build the new statement.
916 /// Subclasses may override this routine to provide different behavior.
917 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
918 SourceLocation LParenLoc,
919 StmtArg Element,
920 ExprArg Collection,
921 SourceLocation RParenLoc,
922 StmtArg Body) {
923 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
924 move(Element),
925 move(Collection),
926 RParenLoc,
927 move(Body));
928 }
Douglas Gregor6148de72010-04-22 22:01:21 +0000929
Douglas Gregorebe10102009-08-20 07:17:43 +0000930 /// \brief Build a new C++ exception declaration.
931 ///
932 /// By default, performs semantic analysis to build the new decaration.
933 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000934 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000935 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000936 IdentifierInfo *Name,
937 SourceLocation Loc,
938 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000939 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000940 TypeRange);
941 }
942
943 /// \brief Build a new C++ catch statement.
944 ///
945 /// By default, performs semantic analysis to build the new statement.
946 /// Subclasses may override this routine to provide different behavior.
947 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
948 VarDecl *ExceptionDecl,
949 StmtArg Handler) {
950 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000951 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000952 Handler.takeAs<Stmt>()));
953 }
Mike Stump11289f42009-09-09 15:08:12 +0000954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Build a new C++ try statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
959 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
960 StmtArg TryBlock,
961 MultiStmtArg Handlers) {
962 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
963 }
Mike Stump11289f42009-09-09 15:08:12 +0000964
Douglas Gregora16548e2009-08-11 05:31:07 +0000965 /// \brief Build a new expression that references a declaration.
966 ///
967 /// By default, performs semantic analysis to build the new expression.
968 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +0000969 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
970 LookupResult &R,
971 bool RequiresADL) {
972 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
973 }
974
975
976 /// \brief Build a new expression that references a declaration.
977 ///
978 /// By default, performs semantic analysis to build the new expression.
979 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000980 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
981 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +0000982 ValueDecl *VD, SourceLocation Loc,
983 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +0000984 CXXScopeSpec SS;
985 SS.setScopeRep(Qualifier);
986 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +0000987
988 // FIXME: loses template args.
989
990 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +0000991 }
Mike Stump11289f42009-09-09 15:08:12 +0000992
Douglas Gregora16548e2009-08-11 05:31:07 +0000993 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +0000994 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000995 /// By default, performs semantic analysis to build the new expression.
996 /// Subclasses may override this routine to provide different behavior.
997 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
998 SourceLocation RParen) {
999 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1000 }
1001
Douglas Gregorad8a3362009-09-04 17:36:40 +00001002 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001003 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001004 /// By default, performs semantic analysis to build the new expression.
1005 /// Subclasses may override this routine to provide different behavior.
1006 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1007 SourceLocation OperatorLoc,
1008 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001009 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001010 SourceRange QualifierRange,
1011 TypeSourceInfo *ScopeType,
1012 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001013 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001014 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
1020 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1021 UnaryOperator::Opcode Opc,
1022 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001023 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001024 }
Mike Stump11289f42009-09-09 15:08:12 +00001025
Douglas Gregora16548e2009-08-11 05:31:07 +00001026 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001027 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001028 /// By default, performs semantic analysis to build the new expression.
1029 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001030 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001031 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001032 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001033 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001034 }
1035
Mike Stump11289f42009-09-09 15:08:12 +00001036 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001037 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001038 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001039 /// By default, performs semantic analysis to build the new expression.
1040 /// Subclasses may override this routine to provide different behavior.
1041 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1042 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001043 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1045 OpLoc, isSizeOf, R);
1046 if (Result.isInvalid())
1047 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregora16548e2009-08-11 05:31:07 +00001049 SubExpr.release();
1050 return move(Result);
1051 }
Mike Stump11289f42009-09-09 15:08:12 +00001052
Douglas Gregora16548e2009-08-11 05:31:07 +00001053 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001054 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001057 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001058 SourceLocation LBracketLoc,
1059 ExprArg RHS,
1060 SourceLocation RBracketLoc) {
1061 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001062 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001063 RBracketLoc);
1064 }
1065
1066 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001067 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001068 /// By default, performs semantic analysis to build the new expression.
1069 /// Subclasses may override this routine to provide different behavior.
1070 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1071 MultiExprArg Args,
1072 SourceLocation *CommaLocs,
1073 SourceLocation RParenLoc) {
1074 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1075 move(Args), CommaLocs, RParenLoc);
1076 }
1077
1078 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001079 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001080 /// By default, performs semantic analysis to build the new expression.
1081 /// Subclasses may override this routine to provide different behavior.
1082 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001083 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001084 NestedNameSpecifier *Qualifier,
1085 SourceRange QualifierRange,
1086 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001087 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001088 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001089 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001090 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001091 if (!Member->getDeclName()) {
1092 // We have a reference to an unnamed field.
1093 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001094
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001095 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001096 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1097 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001098 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001099
Mike Stump11289f42009-09-09 15:08:12 +00001100 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001101 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001102 Member, MemberLoc,
1103 cast<FieldDecl>(Member)->getType());
1104 return getSema().Owned(ME);
1105 }
Mike Stump11289f42009-09-09 15:08:12 +00001106
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001107 CXXScopeSpec SS;
1108 if (Qualifier) {
1109 SS.setRange(QualifierRange);
1110 SS.setScopeRep(Qualifier);
1111 }
1112
John McCall2d74de92009-12-01 22:10:20 +00001113 QualType BaseType = ((Expr*) Base.get())->getType();
1114
John McCall16df1e52010-03-30 21:47:33 +00001115 // FIXME: this involves duplicating earlier analysis in a lot of
1116 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001117 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1118 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001119 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001120 R.resolveKind();
1121
John McCall2d74de92009-12-01 22:10:20 +00001122 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1123 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001124 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001125 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001126 }
Mike Stump11289f42009-09-09 15:08:12 +00001127
Douglas Gregora16548e2009-08-11 05:31:07 +00001128 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001129 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001130 /// By default, performs semantic analysis to build the new expression.
1131 /// Subclasses may override this routine to provide different behavior.
1132 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1133 BinaryOperator::Opcode Opc,
1134 ExprArg LHS, ExprArg RHS) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001135 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
1136 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001137 }
1138
1139 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001140 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 /// By default, performs semantic analysis to build the new expression.
1142 /// Subclasses may override this routine to provide different behavior.
1143 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1144 SourceLocation QuestionLoc,
1145 ExprArg LHS,
1146 SourceLocation ColonLoc,
1147 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001148 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001149 move(LHS), move(RHS));
1150 }
1151
Douglas Gregora16548e2009-08-11 05:31:07 +00001152 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001153 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001154 /// By default, performs semantic analysis to build the new expression.
1155 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001156 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1157 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001158 SourceLocation RParenLoc,
1159 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001160 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1161 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001162 }
Mike Stump11289f42009-09-09 15:08:12 +00001163
Douglas Gregora16548e2009-08-11 05:31:07 +00001164 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001165 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001166 /// By default, performs semantic analysis to build the new expression.
1167 /// Subclasses may override this routine to provide different behavior.
1168 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001169 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001170 SourceLocation RParenLoc,
1171 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001172 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1173 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001174 }
Mike Stump11289f42009-09-09 15:08:12 +00001175
Douglas Gregora16548e2009-08-11 05:31:07 +00001176 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001177 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001178 /// By default, performs semantic analysis to build the new expression.
1179 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001180 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001181 SourceLocation OpLoc,
1182 SourceLocation AccessorLoc,
1183 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001184
John McCall10eae182009-11-30 22:42:35 +00001185 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001186 QualType BaseType = ((Expr*) Base.get())->getType();
1187 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001188 OpLoc, /*IsArrow*/ false,
1189 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001190 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001191 AccessorLoc,
1192 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Douglas Gregora16548e2009-08-11 05:31:07 +00001195 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001196 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// By default, performs semantic analysis to build the new expression.
1198 /// Subclasses may override this routine to provide different behavior.
1199 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1200 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001201 SourceLocation RBraceLoc,
1202 QualType ResultTy) {
1203 OwningExprResult Result
1204 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1205 if (Result.isInvalid() || ResultTy->isDependentType())
1206 return move(Result);
1207
1208 // Patch in the result type we were given, which may have been computed
1209 // when the initial InitListExpr was built.
1210 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1211 ILE->setType(ResultTy);
1212 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001216 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001217 /// By default, performs semantic analysis to build the new expression.
1218 /// Subclasses may override this routine to provide different behavior.
1219 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1220 MultiExprArg ArrayExprs,
1221 SourceLocation EqualOrColonLoc,
1222 bool GNUSyntax,
1223 ExprArg Init) {
1224 OwningExprResult Result
1225 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1226 move(Init));
1227 if (Result.isInvalid())
1228 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 ArrayExprs.release();
1231 return move(Result);
1232 }
Mike Stump11289f42009-09-09 15:08:12 +00001233
Douglas Gregora16548e2009-08-11 05:31:07 +00001234 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001235 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 /// By default, builds the implicit value initialization without performing
1237 /// any semantic analysis. Subclasses may override this routine to provide
1238 /// different behavior.
1239 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1240 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1241 }
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001244 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
1247 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1248 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001249 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001250 RParenLoc);
1251 }
1252
1253 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001254 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
1257 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1258 MultiExprArg SubExprs,
1259 SourceLocation RParenLoc) {
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001260 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
1261 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001265 ///
1266 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001267 /// rather than attempting to map the label statement itself.
1268 /// Subclasses may override this routine to provide different behavior.
1269 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1270 SourceLocation LabelLoc,
1271 LabelStmt *Label) {
1272 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1273 }
Mike Stump11289f42009-09-09 15:08:12 +00001274
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001276 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 /// By default, performs semantic analysis to build the new expression.
1278 /// Subclasses may override this routine to provide different behavior.
1279 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1280 StmtArg SubStmt,
1281 SourceLocation RParenLoc) {
1282 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1283 }
Mike Stump11289f42009-09-09 15:08:12 +00001284
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 /// \brief Build a new __builtin_types_compatible_p expression.
1286 ///
1287 /// By default, performs semantic analysis to build the new expression.
1288 /// Subclasses may override this routine to provide different behavior.
1289 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1290 QualType T1, QualType T2,
1291 SourceLocation RParenLoc) {
1292 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1293 T1.getAsOpaquePtr(),
1294 T2.getAsOpaquePtr(),
1295 RParenLoc);
1296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new __builtin_choose_expr expression.
1299 ///
1300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1303 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1304 SourceLocation RParenLoc) {
1305 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1306 move(Cond), move(LHS), move(RHS),
1307 RParenLoc);
1308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 /// \brief Build a new overloaded operator call expression.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// The semantic analysis provides the behavior of template instantiation,
1314 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001315 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 /// argument-dependent lookup, etc. Subclasses may override this routine to
1317 /// provide different behavior.
1318 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1319 SourceLocation OpLoc,
1320 ExprArg Callee,
1321 ExprArg First,
1322 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001323
1324 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001325 /// reinterpret_cast.
1326 ///
1327 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001328 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// Subclasses may override this routine to provide different behavior.
1330 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1331 Stmt::StmtClass Class,
1332 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001333 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 SourceLocation RAngleLoc,
1335 SourceLocation LParenLoc,
1336 ExprArg SubExpr,
1337 SourceLocation RParenLoc) {
1338 switch (Class) {
1339 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001340 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001341 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 move(SubExpr), RParenLoc);
1343
1344 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001345 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001346 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001350 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001351 RAngleLoc, LParenLoc,
1352 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001356 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001357 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001359
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 default:
1361 assert(false && "Invalid C++ named cast");
1362 break;
1363 }
Mike Stump11289f42009-09-09 15:08:12 +00001364
Douglas Gregora16548e2009-08-11 05:31:07 +00001365 return getSema().ExprError();
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// \brief Build a new C++ static_cast expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1373 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001374 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001375 SourceLocation RAngleLoc,
1376 SourceLocation LParenLoc,
1377 ExprArg SubExpr,
1378 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001379 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1380 TInfo, move(SubExpr),
1381 SourceRange(LAngleLoc, RAngleLoc),
1382 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001383 }
1384
1385 /// \brief Build a new C++ dynamic_cast expression.
1386 ///
1387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
1389 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1390 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001391 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 SourceLocation RAngleLoc,
1393 SourceLocation LParenLoc,
1394 ExprArg SubExpr,
1395 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001396 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1397 TInfo, move(SubExpr),
1398 SourceRange(LAngleLoc, RAngleLoc),
1399 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 }
1401
1402 /// \brief Build a new C++ reinterpret_cast expression.
1403 ///
1404 /// By default, performs semantic analysis to build the new expression.
1405 /// Subclasses may override this routine to provide different behavior.
1406 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1407 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001408 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 SourceLocation RAngleLoc,
1410 SourceLocation LParenLoc,
1411 ExprArg SubExpr,
1412 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001413 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1414 TInfo, move(SubExpr),
1415 SourceRange(LAngleLoc, RAngleLoc),
1416 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 }
1418
1419 /// \brief Build a new C++ const_cast expression.
1420 ///
1421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
1423 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1424 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001425 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 SourceLocation RAngleLoc,
1427 SourceLocation LParenLoc,
1428 ExprArg SubExpr,
1429 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001430 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1431 TInfo, move(SubExpr),
1432 SourceRange(LAngleLoc, RAngleLoc),
1433 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 }
Mike Stump11289f42009-09-09 15:08:12 +00001435
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// \brief Build a new C++ functional-style cast expression.
1437 ///
1438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
1440 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001441 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 SourceLocation LParenLoc,
1443 ExprArg SubExpr,
1444 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001445 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001447 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001449 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001450 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 RParenLoc);
1452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 /// \brief Build a new C++ typeid(type) expression.
1455 ///
1456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
1458 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1459 SourceLocation LParenLoc,
1460 QualType T,
1461 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001462 return getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, true,
Douglas Gregora16548e2009-08-11 05:31:07 +00001463 T.getAsOpaquePtr(), RParenLoc);
1464 }
Mike Stump11289f42009-09-09 15:08:12 +00001465
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 /// \brief Build a new C++ typeid(expr) expression.
1467 ///
1468 /// By default, performs semantic analysis to build the new expression.
1469 /// Subclasses may override this routine to provide different behavior.
1470 OwningExprResult RebuildCXXTypeidExpr(SourceLocation TypeidLoc,
1471 SourceLocation LParenLoc,
1472 ExprArg Operand,
1473 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001474 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 = getSema().ActOnCXXTypeid(TypeidLoc, LParenLoc, false, Operand.get(),
1476 RParenLoc);
1477 if (Result.isInvalid())
1478 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001479
Douglas Gregora16548e2009-08-11 05:31:07 +00001480 Operand.release(); // FIXME: since ActOnCXXTypeid silently took ownership
1481 return move(Result);
Mike Stump11289f42009-09-09 15:08:12 +00001482 }
1483
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 /// \brief Build a new C++ "this" expression.
1485 ///
1486 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001487 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001489 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001490 QualType ThisType,
1491 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001493 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1494 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001495 }
1496
1497 /// \brief Build a new C++ throw expression.
1498 ///
1499 /// By default, performs semantic analysis to build the new expression.
1500 /// Subclasses may override this routine to provide different behavior.
1501 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1502 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1503 }
1504
1505 /// \brief Build a new C++ default-argument expression.
1506 ///
1507 /// By default, builds a new default-argument expression, which does not
1508 /// require any semantic analysis. Subclasses may override this routine to
1509 /// provide different behavior.
Douglas Gregor033f6752009-12-23 23:03:06 +00001510 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
1511 ParmVarDecl *Param) {
1512 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1513 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 }
1515
1516 /// \brief Build a new C++ zero-initialization expression.
1517 ///
1518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001520 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 SourceLocation LParenLoc,
1522 QualType T,
1523 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001524 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1525 T.getAsOpaquePtr(), LParenLoc,
1526 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 0, RParenLoc);
1528 }
Mike Stump11289f42009-09-09 15:08:12 +00001529
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 /// \brief Build a new C++ "new" expression.
1531 ///
1532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001534 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 bool UseGlobal,
1536 SourceLocation PlacementLParen,
1537 MultiExprArg PlacementArgs,
1538 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001539 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001540 QualType AllocType,
1541 SourceLocation TypeLoc,
1542 SourceRange TypeRange,
1543 ExprArg ArraySize,
1544 SourceLocation ConstructorLParen,
1545 MultiExprArg ConstructorArgs,
1546 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001547 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 PlacementLParen,
1549 move(PlacementArgs),
1550 PlacementRParen,
1551 ParenTypeId,
1552 AllocType,
1553 TypeLoc,
1554 TypeRange,
1555 move(ArraySize),
1556 ConstructorLParen,
1557 move(ConstructorArgs),
1558 ConstructorRParen);
1559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new C++ "delete" expression.
1562 ///
1563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
1565 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1566 bool IsGlobalDelete,
1567 bool IsArrayForm,
1568 ExprArg Operand) {
1569 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1570 move(Operand));
1571 }
Mike Stump11289f42009-09-09 15:08:12 +00001572
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 /// \brief Build a new unary type trait expression.
1574 ///
1575 /// By default, performs semantic analysis to build the new expression.
1576 /// Subclasses may override this routine to provide different behavior.
1577 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1578 SourceLocation StartLoc,
1579 SourceLocation LParenLoc,
1580 QualType T,
1581 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001582 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 T.getAsOpaquePtr(), RParenLoc);
1584 }
1585
Mike Stump11289f42009-09-09 15:08:12 +00001586 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 /// expression.
1588 ///
1589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001591 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001592 SourceRange QualifierRange,
1593 DeclarationName Name,
1594 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001595 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 CXXScopeSpec SS;
1597 SS.setRange(QualifierRange);
1598 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001599
1600 if (TemplateArgs)
1601 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1602 *TemplateArgs);
1603
1604 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001605 }
1606
1607 /// \brief Build a new template-id expression.
1608 ///
1609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001611 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1612 LookupResult &R,
1613 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001614 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001615 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 }
1617
1618 /// \brief Build a new object-construction expression.
1619 ///
1620 /// By default, performs semantic analysis to build the new expression.
1621 /// Subclasses may override this routine to provide different behavior.
1622 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001623 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001624 CXXConstructorDecl *Constructor,
1625 bool IsElidable,
1626 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001627 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
1628 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
1629 ConvertedArgs))
1630 return getSema().ExprError();
1631
1632 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1633 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 }
1635
1636 /// \brief Build a new object-construction expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
1640 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1641 QualType T,
1642 SourceLocation LParenLoc,
1643 MultiExprArg Args,
1644 SourceLocation *Commas,
1645 SourceLocation RParenLoc) {
1646 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1647 T.getAsOpaquePtr(),
1648 LParenLoc,
1649 move(Args),
1650 Commas,
1651 RParenLoc);
1652 }
1653
1654 /// \brief Build a new object-construction expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
1658 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1659 QualType T,
1660 SourceLocation LParenLoc,
1661 MultiExprArg Args,
1662 SourceLocation *Commas,
1663 SourceLocation RParenLoc) {
1664 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1665 /*FIXME*/LParenLoc),
1666 T.getAsOpaquePtr(),
1667 LParenLoc,
1668 move(Args),
1669 Commas,
1670 RParenLoc);
1671 }
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 /// \brief Build a new member reference expression.
1674 ///
1675 /// By default, performs semantic analysis to build the new expression.
1676 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001677 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001678 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 bool IsArrow,
1680 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001681 NestedNameSpecifier *Qualifier,
1682 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001683 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001685 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001686 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001688 SS.setRange(QualifierRange);
1689 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001690
John McCall2d74de92009-12-01 22:10:20 +00001691 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1692 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001693 SS, FirstQualifierInScope,
1694 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 }
1696
John McCall10eae182009-11-30 22:42:35 +00001697 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001698 ///
1699 /// By default, performs semantic analysis to build the new expression.
1700 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001701 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001702 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001703 SourceLocation OperatorLoc,
1704 bool IsArrow,
1705 NestedNameSpecifier *Qualifier,
1706 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001707 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001708 LookupResult &R,
1709 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001710 CXXScopeSpec SS;
1711 SS.setRange(QualifierRange);
1712 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001713
John McCall2d74de92009-12-01 22:10:20 +00001714 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1715 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001716 SS, FirstQualifierInScope,
1717 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001718 }
Mike Stump11289f42009-09-09 15:08:12 +00001719
Douglas Gregora16548e2009-08-11 05:31:07 +00001720 /// \brief Build a new Objective-C @encode expression.
1721 ///
1722 /// By default, performs semantic analysis to build the new expression.
1723 /// Subclasses may override this routine to provide different behavior.
1724 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001725 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001727 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001729 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001730
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001731 /// \brief Build a new Objective-C class message.
1732 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1733 Selector Sel,
1734 ObjCMethodDecl *Method,
1735 SourceLocation LBracLoc,
1736 MultiExprArg Args,
1737 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001738 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1739 ReceiverTypeInfo->getType(),
1740 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001741 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001742 move(Args));
1743 }
1744
1745 /// \brief Build a new Objective-C instance message.
1746 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1747 Selector Sel,
1748 ObjCMethodDecl *Method,
1749 SourceLocation LBracLoc,
1750 MultiExprArg Args,
1751 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001752 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1753 return SemaRef.BuildInstanceMessage(move(Receiver),
1754 ReceiverType,
1755 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001756 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001757 move(Args));
1758 }
1759
Douglas Gregora16548e2009-08-11 05:31:07 +00001760 /// \brief Build a new shuffle vector expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
1764 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1765 MultiExprArg SubExprs,
1766 SourceLocation RParenLoc) {
1767 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001768 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1770 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1771 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1772 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001773
Douglas Gregora16548e2009-08-11 05:31:07 +00001774 // Build a reference to the __builtin_shufflevector builtin
1775 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001776 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001778 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001779 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001780
1781 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 unsigned NumSubExprs = SubExprs.size();
1783 Expr **Subs = (Expr **)SubExprs.release();
1784 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1785 Subs, NumSubExprs,
1786 Builtin->getResultType(),
1787 RParenLoc);
1788 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001789
Douglas Gregora16548e2009-08-11 05:31:07 +00001790 // Type-check the __builtin_shufflevector expression.
1791 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1792 if (Result.isInvalid())
1793 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001794
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001796 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001798};
Douglas Gregora16548e2009-08-11 05:31:07 +00001799
Douglas Gregorebe10102009-08-20 07:17:43 +00001800template<typename Derived>
1801Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1802 if (!S)
1803 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregorebe10102009-08-20 07:17:43 +00001805 switch (S->getStmtClass()) {
1806 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001807
Douglas Gregorebe10102009-08-20 07:17:43 +00001808 // Transform individual statement nodes
1809#define STMT(Node, Parent) \
1810 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1811#define EXPR(Node, Parent)
1812#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001813
Douglas Gregorebe10102009-08-20 07:17:43 +00001814 // Transform expressions by calling TransformExpr.
1815#define STMT(Node, Parent)
John McCall2adddca2010-02-03 00:55:45 +00001816#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregorebe10102009-08-20 07:17:43 +00001817#define EXPR(Node, Parent) case Stmt::Node##Class:
1818#include "clang/AST/StmtNodes.def"
1819 {
1820 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1821 if (E.isInvalid())
1822 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001823
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001824 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001825 }
Mike Stump11289f42009-09-09 15:08:12 +00001826 }
1827
Douglas Gregorebe10102009-08-20 07:17:43 +00001828 return SemaRef.Owned(S->Retain());
1829}
Mike Stump11289f42009-09-09 15:08:12 +00001830
1831
Douglas Gregore922c772009-08-04 22:27:00 +00001832template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001833Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001834 if (!E)
1835 return SemaRef.Owned(E);
1836
1837 switch (E->getStmtClass()) {
1838 case Stmt::NoStmtClass: break;
1839#define STMT(Node, Parent) case Stmt::Node##Class: break;
John McCall2adddca2010-02-03 00:55:45 +00001840#define ABSTRACT_EXPR(Node, Parent)
Douglas Gregora16548e2009-08-11 05:31:07 +00001841#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001842 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Douglas Gregora16548e2009-08-11 05:31:07 +00001843#include "clang/AST/StmtNodes.def"
Mike Stump11289f42009-09-09 15:08:12 +00001844 }
1845
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001847}
1848
1849template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001850NestedNameSpecifier *
1851TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001852 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001853 QualType ObjectType,
1854 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00001855 if (!NNS)
1856 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001857
Douglas Gregorebe10102009-08-20 07:17:43 +00001858 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00001859 NestedNameSpecifier *Prefix = NNS->getPrefix();
1860 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00001861 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001862 ObjectType,
1863 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00001864 if (!Prefix)
1865 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001866
1867 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001868 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001869 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001870 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001871 }
Mike Stump11289f42009-09-09 15:08:12 +00001872
Douglas Gregor1135c352009-08-06 05:28:30 +00001873 switch (NNS->getKind()) {
1874 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00001875 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001876 "Identifier nested-name-specifier with no prefix or object type");
1877 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
1878 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00001879 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001880
1881 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001882 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001883 ObjectType,
1884 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001885
Douglas Gregor1135c352009-08-06 05:28:30 +00001886 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00001887 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00001888 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001889 getDerived().TransformDecl(Range.getBegin(),
1890 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00001891 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00001892 Prefix == NNS->getPrefix() &&
1893 NS == NNS->getAsNamespace())
1894 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001895
Douglas Gregor1135c352009-08-06 05:28:30 +00001896 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
1897 }
Mike Stump11289f42009-09-09 15:08:12 +00001898
Douglas Gregor1135c352009-08-06 05:28:30 +00001899 case NestedNameSpecifier::Global:
1900 // There is no meaningful transformation that one could perform on the
1901 // global scope.
1902 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001903
Douglas Gregor1135c352009-08-06 05:28:30 +00001904 case NestedNameSpecifier::TypeSpecWithTemplate:
1905 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00001906 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00001907 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
1908 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001909 if (T.isNull())
1910 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00001911
Douglas Gregor1135c352009-08-06 05:28:30 +00001912 if (!getDerived().AlwaysRebuild() &&
1913 Prefix == NNS->getPrefix() &&
1914 T == QualType(NNS->getAsType(), 0))
1915 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00001916
1917 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
1918 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00001919 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001920 }
1921 }
Mike Stump11289f42009-09-09 15:08:12 +00001922
Douglas Gregor1135c352009-08-06 05:28:30 +00001923 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00001924 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00001925}
1926
1927template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001928DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00001929TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00001930 SourceLocation Loc,
1931 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00001932 if (!Name)
1933 return Name;
1934
1935 switch (Name.getNameKind()) {
1936 case DeclarationName::Identifier:
1937 case DeclarationName::ObjCZeroArgSelector:
1938 case DeclarationName::ObjCOneArgSelector:
1939 case DeclarationName::ObjCMultiArgSelector:
1940 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00001941 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00001942 case DeclarationName::CXXUsingDirective:
1943 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001944
Douglas Gregorf816bd72009-09-03 22:13:48 +00001945 case DeclarationName::CXXConstructorName:
1946 case DeclarationName::CXXDestructorName:
1947 case DeclarationName::CXXConversionFunctionName: {
1948 TemporaryBase Rebase(*this, Loc, Name);
Douglas Gregorfe17d252010-02-16 19:09:40 +00001949 QualType T = getDerived().TransformType(Name.getCXXNameType(),
1950 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00001951 if (T.isNull())
1952 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00001953
Douglas Gregorf816bd72009-09-03 22:13:48 +00001954 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00001955 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00001956 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00001957 }
Mike Stump11289f42009-09-09 15:08:12 +00001958 }
1959
Douglas Gregorf816bd72009-09-03 22:13:48 +00001960 return DeclarationName();
1961}
1962
1963template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00001964TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00001965TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
1966 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001967 SourceLocation Loc = getDerived().getBaseLocation();
1968
Douglas Gregor71dc5092009-08-06 06:41:21 +00001969 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001970 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001971 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001972 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
1973 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00001974 if (!NNS)
1975 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregor71dc5092009-08-06 06:41:21 +00001977 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00001978 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00001979 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00001980 if (!TransTemplate)
1981 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregor71dc5092009-08-06 06:41:21 +00001983 if (!getDerived().AlwaysRebuild() &&
1984 NNS == QTN->getQualifier() &&
1985 TransTemplate == Template)
1986 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregor71dc5092009-08-06 06:41:21 +00001988 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
1989 TransTemplate);
1990 }
Mike Stump11289f42009-09-09 15:08:12 +00001991
John McCalle66edc12009-11-24 19:00:30 +00001992 // These should be getting filtered out before they make it into the AST.
1993 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995
Douglas Gregor71dc5092009-08-06 06:41:21 +00001996 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00001997 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00001998 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00001999 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2000 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002001 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002002 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002003
Douglas Gregor71dc5092009-08-06 06:41:21 +00002004 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002005 NNS == DTN->getQualifier() &&
2006 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002007 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregor71395fa2009-11-04 00:56:37 +00002009 if (DTN->isIdentifier())
2010 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
2011 ObjectType);
2012
2013 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
2014 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregor71dc5092009-08-06 06:41:21 +00002017 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002018 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002019 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002020 if (!TransTemplate)
2021 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002022
Douglas Gregor71dc5092009-08-06 06:41:21 +00002023 if (!getDerived().AlwaysRebuild() &&
2024 TransTemplate == Template)
2025 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregor71dc5092009-08-06 06:41:21 +00002027 return TemplateName(TransTemplate);
2028 }
Mike Stump11289f42009-09-09 15:08:12 +00002029
John McCalle66edc12009-11-24 19:00:30 +00002030 // These should be getting filtered out before they reach the AST.
2031 assert(false && "overloaded function decl survived to here");
2032 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002033}
2034
2035template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002036void TreeTransform<Derived>::InventTemplateArgumentLoc(
2037 const TemplateArgument &Arg,
2038 TemplateArgumentLoc &Output) {
2039 SourceLocation Loc = getDerived().getBaseLocation();
2040 switch (Arg.getKind()) {
2041 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002042 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002043 break;
2044
2045 case TemplateArgument::Type:
2046 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002047 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
John McCall0ad16662009-10-29 08:12:44 +00002048
2049 break;
2050
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002051 case TemplateArgument::Template:
2052 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2053 break;
2054
John McCall0ad16662009-10-29 08:12:44 +00002055 case TemplateArgument::Expression:
2056 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2057 break;
2058
2059 case TemplateArgument::Declaration:
2060 case TemplateArgument::Integral:
2061 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002062 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002063 break;
2064 }
2065}
2066
2067template<typename Derived>
2068bool TreeTransform<Derived>::TransformTemplateArgument(
2069 const TemplateArgumentLoc &Input,
2070 TemplateArgumentLoc &Output) {
2071 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002072 switch (Arg.getKind()) {
2073 case TemplateArgument::Null:
2074 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002075 Output = Input;
2076 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002077
Douglas Gregore922c772009-08-04 22:27:00 +00002078 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002079 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002080 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002081 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002082
2083 DI = getDerived().TransformType(DI);
2084 if (!DI) return true;
2085
2086 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2087 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002088 }
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregore922c772009-08-04 22:27:00 +00002090 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002091 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002092 DeclarationName Name;
2093 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2094 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002095 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002096 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002097 if (!D) return true;
2098
John McCall0d07eb32009-10-29 18:45:58 +00002099 Expr *SourceExpr = Input.getSourceDeclExpression();
2100 if (SourceExpr) {
2101 EnterExpressionEvaluationContext Unevaluated(getSema(),
2102 Action::Unevaluated);
2103 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2104 if (E.isInvalid())
2105 SourceExpr = NULL;
2106 else {
2107 SourceExpr = E.takeAs<Expr>();
2108 SourceExpr->Retain();
2109 }
2110 }
2111
2112 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002113 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002114 }
Mike Stump11289f42009-09-09 15:08:12 +00002115
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002116 case TemplateArgument::Template: {
2117 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
2118 TemplateName Template
2119 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2120 if (Template.isNull())
2121 return true;
2122
2123 Output = TemplateArgumentLoc(TemplateArgument(Template),
2124 Input.getTemplateQualifierRange(),
2125 Input.getTemplateNameLoc());
2126 return false;
2127 }
2128
Douglas Gregore922c772009-08-04 22:27:00 +00002129 case TemplateArgument::Expression: {
2130 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002131 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002132 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002133
John McCall0ad16662009-10-29 08:12:44 +00002134 Expr *InputExpr = Input.getSourceExpression();
2135 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2136
2137 Sema::OwningExprResult E
2138 = getDerived().TransformExpr(InputExpr);
2139 if (E.isInvalid()) return true;
2140
2141 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002142 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002143 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2144 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002145 }
Mike Stump11289f42009-09-09 15:08:12 +00002146
Douglas Gregore922c772009-08-04 22:27:00 +00002147 case TemplateArgument::Pack: {
2148 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2149 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002150 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002151 AEnd = Arg.pack_end();
2152 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002153
John McCall0ad16662009-10-29 08:12:44 +00002154 // FIXME: preserve source information here when we start
2155 // caring about parameter packs.
2156
John McCall0d07eb32009-10-29 18:45:58 +00002157 TemplateArgumentLoc InputArg;
2158 TemplateArgumentLoc OutputArg;
2159 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2160 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002161 return true;
2162
John McCall0d07eb32009-10-29 18:45:58 +00002163 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002164 }
2165 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002166 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002167 true);
John McCall0d07eb32009-10-29 18:45:58 +00002168 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002169 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002170 }
2171 }
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregore922c772009-08-04 22:27:00 +00002173 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002174 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002175}
2176
Douglas Gregord6ff3322009-08-04 16:50:30 +00002177//===----------------------------------------------------------------------===//
2178// Type transformation
2179//===----------------------------------------------------------------------===//
2180
2181template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002182QualType TreeTransform<Derived>::TransformType(QualType T,
2183 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002184 if (getDerived().AlreadyTransformed(T))
2185 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002186
John McCall550e0c22009-10-21 00:40:46 +00002187 // Temporary workaround. All of these transformations should
2188 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002189 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002190 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
John McCall550e0c22009-10-21 00:40:46 +00002191
Douglas Gregorfe17d252010-02-16 19:09:40 +00002192 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002193
John McCall550e0c22009-10-21 00:40:46 +00002194 if (!NewDI)
2195 return QualType();
2196
2197 return NewDI->getType();
2198}
2199
2200template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002201TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2202 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002203 if (getDerived().AlreadyTransformed(DI->getType()))
2204 return DI;
2205
2206 TypeLocBuilder TLB;
2207
2208 TypeLoc TL = DI->getTypeLoc();
2209 TLB.reserve(TL.getFullDataSize());
2210
Douglas Gregorfe17d252010-02-16 19:09:40 +00002211 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002212 if (Result.isNull())
2213 return 0;
2214
John McCallbcd03502009-12-07 02:54:59 +00002215 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002216}
2217
2218template<typename Derived>
2219QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002220TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2221 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002222 switch (T.getTypeLocClass()) {
2223#define ABSTRACT_TYPELOC(CLASS, PARENT)
2224#define TYPELOC(CLASS, PARENT) \
2225 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002226 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2227 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002228#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002229 }
Mike Stump11289f42009-09-09 15:08:12 +00002230
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002231 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002232 return QualType();
2233}
2234
2235/// FIXME: By default, this routine adds type qualifiers only to types
2236/// that can have qualifiers, and silently suppresses those qualifiers
2237/// that are not permitted (e.g., qualifiers on reference or function
2238/// types). This is the right thing for template instantiation, but
2239/// probably not for other clients.
2240template<typename Derived>
2241QualType
2242TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002243 QualifiedTypeLoc T,
2244 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002245 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002246
Douglas Gregorfe17d252010-02-16 19:09:40 +00002247 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2248 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002249 if (Result.isNull())
2250 return QualType();
2251
2252 // Silently suppress qualifiers if the result type can't be qualified.
2253 // FIXME: this is the right thing for template instantiation, but
2254 // probably not for other clients.
2255 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002256 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002257
John McCall550e0c22009-10-21 00:40:46 +00002258 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2259
2260 TLB.push<QualifiedTypeLoc>(Result);
2261
2262 // No location information to preserve.
2263
2264 return Result;
2265}
2266
2267template <class TyLoc> static inline
2268QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2269 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2270 NewT.setNameLoc(T.getNameLoc());
2271 return T.getType();
2272}
2273
John McCall550e0c22009-10-21 00:40:46 +00002274template<typename Derived>
2275QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002276 BuiltinTypeLoc T,
2277 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002278 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2279 NewT.setBuiltinLoc(T.getBuiltinLoc());
2280 if (T.needsExtraLocalData())
2281 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2282 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002283}
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregord6ff3322009-08-04 16:50:30 +00002285template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002286QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002287 ComplexTypeLoc T,
2288 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002289 // FIXME: recurse?
2290 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002291}
Mike Stump11289f42009-09-09 15:08:12 +00002292
Douglas Gregord6ff3322009-08-04 16:50:30 +00002293template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002294QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002295 PointerTypeLoc TL,
2296 QualType ObjectType) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002297 QualType PointeeType
2298 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2299 if (PointeeType.isNull())
2300 return QualType();
2301
2302 QualType Result = TL.getType();
2303 if (PointeeType->isObjCInterfaceType()) {
2304 // A dependent pointer type 'T *' has is being transformed such
2305 // that an Objective-C class type is being replaced for 'T'. The
2306 // resulting pointer type is an ObjCObjectPointerType, not a
2307 // PointerType.
2308 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2309 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2310 const_cast<ObjCProtocolDecl **>(
2311 IFace->qual_begin()),
2312 IFace->getNumProtocols());
2313
2314 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2315 NewT.setStarLoc(TL.getSigilLoc());
2316 NewT.setHasProtocolsAsWritten(false);
2317 NewT.setLAngleLoc(SourceLocation());
2318 NewT.setRAngleLoc(SourceLocation());
2319 NewT.setHasBaseTypeAsWritten(true);
2320 return Result;
2321 }
2322
2323 if (getDerived().AlwaysRebuild() ||
2324 PointeeType != TL.getPointeeLoc().getType()) {
2325 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2326 if (Result.isNull())
2327 return QualType();
2328 }
2329
2330 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2331 NewT.setSigilLoc(TL.getSigilLoc());
2332 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002333}
Mike Stump11289f42009-09-09 15:08:12 +00002334
2335template<typename Derived>
2336QualType
John McCall550e0c22009-10-21 00:40:46 +00002337TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002338 BlockPointerTypeLoc TL,
2339 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002340 QualType PointeeType
2341 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2342 if (PointeeType.isNull())
2343 return QualType();
2344
2345 QualType Result = TL.getType();
2346 if (getDerived().AlwaysRebuild() ||
2347 PointeeType != TL.getPointeeLoc().getType()) {
2348 Result = getDerived().RebuildBlockPointerType(PointeeType,
2349 TL.getSigilLoc());
2350 if (Result.isNull())
2351 return QualType();
2352 }
2353
Douglas Gregor049211a2010-04-22 16:50:51 +00002354 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002355 NewT.setSigilLoc(TL.getSigilLoc());
2356 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002357}
2358
John McCall70dd5f62009-10-30 00:06:24 +00002359/// Transforms a reference type. Note that somewhat paradoxically we
2360/// don't care whether the type itself is an l-value type or an r-value
2361/// type; we only care if the type was *written* as an l-value type
2362/// or an r-value type.
2363template<typename Derived>
2364QualType
2365TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002366 ReferenceTypeLoc TL,
2367 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002368 const ReferenceType *T = TL.getTypePtr();
2369
2370 // Note that this works with the pointee-as-written.
2371 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2372 if (PointeeType.isNull())
2373 return QualType();
2374
2375 QualType Result = TL.getType();
2376 if (getDerived().AlwaysRebuild() ||
2377 PointeeType != T->getPointeeTypeAsWritten()) {
2378 Result = getDerived().RebuildReferenceType(PointeeType,
2379 T->isSpelledAsLValue(),
2380 TL.getSigilLoc());
2381 if (Result.isNull())
2382 return QualType();
2383 }
2384
2385 // r-value references can be rebuilt as l-value references.
2386 ReferenceTypeLoc NewTL;
2387 if (isa<LValueReferenceType>(Result))
2388 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2389 else
2390 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2391 NewTL.setSigilLoc(TL.getSigilLoc());
2392
2393 return Result;
2394}
2395
Mike Stump11289f42009-09-09 15:08:12 +00002396template<typename Derived>
2397QualType
John McCall550e0c22009-10-21 00:40:46 +00002398TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002399 LValueReferenceTypeLoc TL,
2400 QualType ObjectType) {
2401 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002402}
2403
Mike Stump11289f42009-09-09 15:08:12 +00002404template<typename Derived>
2405QualType
John McCall550e0c22009-10-21 00:40:46 +00002406TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002407 RValueReferenceTypeLoc TL,
2408 QualType ObjectType) {
2409 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002410}
Mike Stump11289f42009-09-09 15:08:12 +00002411
Douglas Gregord6ff3322009-08-04 16:50:30 +00002412template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002413QualType
John McCall550e0c22009-10-21 00:40:46 +00002414TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002415 MemberPointerTypeLoc TL,
2416 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002417 MemberPointerType *T = TL.getTypePtr();
2418
2419 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002420 if (PointeeType.isNull())
2421 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002422
John McCall550e0c22009-10-21 00:40:46 +00002423 // TODO: preserve source information for this.
2424 QualType ClassType
2425 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002426 if (ClassType.isNull())
2427 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002428
John McCall550e0c22009-10-21 00:40:46 +00002429 QualType Result = TL.getType();
2430 if (getDerived().AlwaysRebuild() ||
2431 PointeeType != T->getPointeeType() ||
2432 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002433 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2434 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002435 if (Result.isNull())
2436 return QualType();
2437 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438
John McCall550e0c22009-10-21 00:40:46 +00002439 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2440 NewTL.setSigilLoc(TL.getSigilLoc());
2441
2442 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002443}
2444
Mike Stump11289f42009-09-09 15:08:12 +00002445template<typename Derived>
2446QualType
John McCall550e0c22009-10-21 00:40:46 +00002447TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002448 ConstantArrayTypeLoc TL,
2449 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002450 ConstantArrayType *T = TL.getTypePtr();
2451 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002452 if (ElementType.isNull())
2453 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002454
John McCall550e0c22009-10-21 00:40:46 +00002455 QualType Result = TL.getType();
2456 if (getDerived().AlwaysRebuild() ||
2457 ElementType != T->getElementType()) {
2458 Result = getDerived().RebuildConstantArrayType(ElementType,
2459 T->getSizeModifier(),
2460 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002461 T->getIndexTypeCVRQualifiers(),
2462 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002463 if (Result.isNull())
2464 return QualType();
2465 }
2466
2467 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2468 NewTL.setLBracketLoc(TL.getLBracketLoc());
2469 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002470
John McCall550e0c22009-10-21 00:40:46 +00002471 Expr *Size = TL.getSizeExpr();
2472 if (Size) {
2473 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2474 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2475 }
2476 NewTL.setSizeExpr(Size);
2477
2478 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002479}
Mike Stump11289f42009-09-09 15:08:12 +00002480
Douglas Gregord6ff3322009-08-04 16:50:30 +00002481template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002482QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002483 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002484 IncompleteArrayTypeLoc TL,
2485 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002486 IncompleteArrayType *T = TL.getTypePtr();
2487 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002488 if (ElementType.isNull())
2489 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002490
John McCall550e0c22009-10-21 00:40:46 +00002491 QualType Result = TL.getType();
2492 if (getDerived().AlwaysRebuild() ||
2493 ElementType != T->getElementType()) {
2494 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002495 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002496 T->getIndexTypeCVRQualifiers(),
2497 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002498 if (Result.isNull())
2499 return QualType();
2500 }
2501
2502 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2503 NewTL.setLBracketLoc(TL.getLBracketLoc());
2504 NewTL.setRBracketLoc(TL.getRBracketLoc());
2505 NewTL.setSizeExpr(0);
2506
2507 return Result;
2508}
2509
2510template<typename Derived>
2511QualType
2512TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002513 VariableArrayTypeLoc TL,
2514 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002515 VariableArrayType *T = TL.getTypePtr();
2516 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2517 if (ElementType.isNull())
2518 return QualType();
2519
2520 // Array bounds are not potentially evaluated contexts
2521 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2522
2523 Sema::OwningExprResult SizeResult
2524 = getDerived().TransformExpr(T->getSizeExpr());
2525 if (SizeResult.isInvalid())
2526 return QualType();
2527
2528 Expr *Size = static_cast<Expr*>(SizeResult.get());
2529
2530 QualType Result = TL.getType();
2531 if (getDerived().AlwaysRebuild() ||
2532 ElementType != T->getElementType() ||
2533 Size != T->getSizeExpr()) {
2534 Result = getDerived().RebuildVariableArrayType(ElementType,
2535 T->getSizeModifier(),
2536 move(SizeResult),
2537 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002538 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002539 if (Result.isNull())
2540 return QualType();
2541 }
2542 else SizeResult.take();
2543
2544 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2545 NewTL.setLBracketLoc(TL.getLBracketLoc());
2546 NewTL.setRBracketLoc(TL.getRBracketLoc());
2547 NewTL.setSizeExpr(Size);
2548
2549 return Result;
2550}
2551
2552template<typename Derived>
2553QualType
2554TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002555 DependentSizedArrayTypeLoc TL,
2556 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002557 DependentSizedArrayType *T = TL.getTypePtr();
2558 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2559 if (ElementType.isNull())
2560 return QualType();
2561
2562 // Array bounds are not potentially evaluated contexts
2563 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2564
2565 Sema::OwningExprResult SizeResult
2566 = getDerived().TransformExpr(T->getSizeExpr());
2567 if (SizeResult.isInvalid())
2568 return QualType();
2569
2570 Expr *Size = static_cast<Expr*>(SizeResult.get());
2571
2572 QualType Result = TL.getType();
2573 if (getDerived().AlwaysRebuild() ||
2574 ElementType != T->getElementType() ||
2575 Size != T->getSizeExpr()) {
2576 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2577 T->getSizeModifier(),
2578 move(SizeResult),
2579 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002580 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002581 if (Result.isNull())
2582 return QualType();
2583 }
2584 else SizeResult.take();
2585
2586 // We might have any sort of array type now, but fortunately they
2587 // all have the same location layout.
2588 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2589 NewTL.setLBracketLoc(TL.getLBracketLoc());
2590 NewTL.setRBracketLoc(TL.getRBracketLoc());
2591 NewTL.setSizeExpr(Size);
2592
2593 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002594}
Mike Stump11289f42009-09-09 15:08:12 +00002595
2596template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002597QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002598 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002599 DependentSizedExtVectorTypeLoc TL,
2600 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002601 DependentSizedExtVectorType *T = TL.getTypePtr();
2602
2603 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604 QualType ElementType = getDerived().TransformType(T->getElementType());
2605 if (ElementType.isNull())
2606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002607
Douglas Gregore922c772009-08-04 22:27:00 +00002608 // Vector sizes are not potentially evaluated contexts
2609 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2610
Douglas Gregord6ff3322009-08-04 16:50:30 +00002611 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2612 if (Size.isInvalid())
2613 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002614
John McCall550e0c22009-10-21 00:40:46 +00002615 QualType Result = TL.getType();
2616 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002617 ElementType != T->getElementType() ||
2618 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002619 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002620 move(Size),
2621 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002622 if (Result.isNull())
2623 return QualType();
2624 }
2625 else Size.take();
2626
2627 // Result might be dependent or not.
2628 if (isa<DependentSizedExtVectorType>(Result)) {
2629 DependentSizedExtVectorTypeLoc NewTL
2630 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2631 NewTL.setNameLoc(TL.getNameLoc());
2632 } else {
2633 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2634 NewTL.setNameLoc(TL.getNameLoc());
2635 }
2636
2637 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002638}
Mike Stump11289f42009-09-09 15:08:12 +00002639
2640template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002641QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002642 VectorTypeLoc TL,
2643 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002644 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002645 QualType ElementType = getDerived().TransformType(T->getElementType());
2646 if (ElementType.isNull())
2647 return QualType();
2648
John McCall550e0c22009-10-21 00:40:46 +00002649 QualType Result = TL.getType();
2650 if (getDerived().AlwaysRebuild() ||
2651 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002652 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2653 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002654 if (Result.isNull())
2655 return QualType();
2656 }
2657
2658 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2659 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002660
John McCall550e0c22009-10-21 00:40:46 +00002661 return Result;
2662}
2663
2664template<typename Derived>
2665QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002666 ExtVectorTypeLoc TL,
2667 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002668 VectorType *T = TL.getTypePtr();
2669 QualType ElementType = getDerived().TransformType(T->getElementType());
2670 if (ElementType.isNull())
2671 return QualType();
2672
2673 QualType Result = TL.getType();
2674 if (getDerived().AlwaysRebuild() ||
2675 ElementType != T->getElementType()) {
2676 Result = getDerived().RebuildExtVectorType(ElementType,
2677 T->getNumElements(),
2678 /*FIXME*/ SourceLocation());
2679 if (Result.isNull())
2680 return QualType();
2681 }
2682
2683 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2684 NewTL.setNameLoc(TL.getNameLoc());
2685
2686 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002687}
Mike Stump11289f42009-09-09 15:08:12 +00002688
2689template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002690ParmVarDecl *
2691TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2692 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2693 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2694 if (!NewDI)
2695 return 0;
2696
2697 if (NewDI == OldDI)
2698 return OldParm;
2699 else
2700 return ParmVarDecl::Create(SemaRef.Context,
2701 OldParm->getDeclContext(),
2702 OldParm->getLocation(),
2703 OldParm->getIdentifier(),
2704 NewDI->getType(),
2705 NewDI,
2706 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002707 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002708 /* DefArg */ NULL);
2709}
2710
2711template<typename Derived>
2712bool TreeTransform<Derived>::
2713 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2714 llvm::SmallVectorImpl<QualType> &PTypes,
2715 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2716 FunctionProtoType *T = TL.getTypePtr();
2717
2718 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2719 ParmVarDecl *OldParm = TL.getArg(i);
2720
2721 QualType NewType;
2722 ParmVarDecl *NewParm;
2723
2724 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002725 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2726 if (!NewParm)
2727 return true;
2728 NewType = NewParm->getType();
2729
2730 // Deal with the possibility that we don't have a parameter
2731 // declaration for this parameter.
2732 } else {
2733 NewParm = 0;
2734
2735 QualType OldType = T->getArgType(i);
2736 NewType = getDerived().TransformType(OldType);
2737 if (NewType.isNull())
2738 return true;
2739 }
2740
2741 PTypes.push_back(NewType);
2742 PVars.push_back(NewParm);
2743 }
2744
2745 return false;
2746}
2747
2748template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002749QualType
John McCall550e0c22009-10-21 00:40:46 +00002750TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002751 FunctionProtoTypeLoc TL,
2752 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002753 FunctionProtoType *T = TL.getTypePtr();
2754 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002755 if (ResultType.isNull())
2756 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002757
John McCall550e0c22009-10-21 00:40:46 +00002758 // Transform the parameters.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002759 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002760 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002761 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2762 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002763
John McCall550e0c22009-10-21 00:40:46 +00002764 QualType Result = TL.getType();
2765 if (getDerived().AlwaysRebuild() ||
2766 ResultType != T->getResultType() ||
2767 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2768 Result = getDerived().RebuildFunctionProtoType(ResultType,
2769 ParamTypes.data(),
2770 ParamTypes.size(),
2771 T->isVariadic(),
2772 T->getTypeQuals());
2773 if (Result.isNull())
2774 return QualType();
2775 }
Mike Stump11289f42009-09-09 15:08:12 +00002776
John McCall550e0c22009-10-21 00:40:46 +00002777 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2778 NewTL.setLParenLoc(TL.getLParenLoc());
2779 NewTL.setRParenLoc(TL.getRParenLoc());
2780 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2781 NewTL.setArg(i, ParamDecls[i]);
2782
2783 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002784}
Mike Stump11289f42009-09-09 15:08:12 +00002785
Douglas Gregord6ff3322009-08-04 16:50:30 +00002786template<typename Derived>
2787QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002788 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002789 FunctionNoProtoTypeLoc TL,
2790 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002791 FunctionNoProtoType *T = TL.getTypePtr();
2792 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2793 if (ResultType.isNull())
2794 return QualType();
2795
2796 QualType Result = TL.getType();
2797 if (getDerived().AlwaysRebuild() ||
2798 ResultType != T->getResultType())
2799 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2800
2801 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2802 NewTL.setLParenLoc(TL.getLParenLoc());
2803 NewTL.setRParenLoc(TL.getRParenLoc());
2804
2805 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002806}
Mike Stump11289f42009-09-09 15:08:12 +00002807
John McCallb96ec562009-12-04 22:46:56 +00002808template<typename Derived> QualType
2809TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002810 UnresolvedUsingTypeLoc TL,
2811 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002812 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002813 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002814 if (!D)
2815 return QualType();
2816
2817 QualType Result = TL.getType();
2818 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2819 Result = getDerived().RebuildUnresolvedUsingType(D);
2820 if (Result.isNull())
2821 return QualType();
2822 }
2823
2824 // We might get an arbitrary type spec type back. We should at
2825 // least always get a type spec type, though.
2826 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2827 NewTL.setNameLoc(TL.getNameLoc());
2828
2829 return Result;
2830}
2831
Douglas Gregord6ff3322009-08-04 16:50:30 +00002832template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002833QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002834 TypedefTypeLoc TL,
2835 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002836 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002837 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002838 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2839 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840 if (!Typedef)
2841 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002842
John McCall550e0c22009-10-21 00:40:46 +00002843 QualType Result = TL.getType();
2844 if (getDerived().AlwaysRebuild() ||
2845 Typedef != T->getDecl()) {
2846 Result = getDerived().RebuildTypedefType(Typedef);
2847 if (Result.isNull())
2848 return QualType();
2849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
John McCall550e0c22009-10-21 00:40:46 +00002851 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2852 NewTL.setNameLoc(TL.getNameLoc());
2853
2854 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002855}
Mike Stump11289f42009-09-09 15:08:12 +00002856
Douglas Gregord6ff3322009-08-04 16:50:30 +00002857template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002858QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002859 TypeOfExprTypeLoc TL,
2860 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00002861 // typeof expressions are not potentially evaluated contexts
2862 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002863
John McCalle8595032010-01-13 20:03:27 +00002864 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002865 if (E.isInvalid())
2866 return QualType();
2867
John McCall550e0c22009-10-21 00:40:46 +00002868 QualType Result = TL.getType();
2869 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00002870 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002871 Result = getDerived().RebuildTypeOfExprType(move(E));
2872 if (Result.isNull())
2873 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002874 }
John McCall550e0c22009-10-21 00:40:46 +00002875 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002876
John McCall550e0c22009-10-21 00:40:46 +00002877 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002878 NewTL.setTypeofLoc(TL.getTypeofLoc());
2879 NewTL.setLParenLoc(TL.getLParenLoc());
2880 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00002881
2882 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002883}
Mike Stump11289f42009-09-09 15:08:12 +00002884
2885template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002886QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002887 TypeOfTypeLoc TL,
2888 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00002889 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
2890 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
2891 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00002892 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002893
John McCall550e0c22009-10-21 00:40:46 +00002894 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00002895 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
2896 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00002897 if (Result.isNull())
2898 return QualType();
2899 }
Mike Stump11289f42009-09-09 15:08:12 +00002900
John McCall550e0c22009-10-21 00:40:46 +00002901 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00002902 NewTL.setTypeofLoc(TL.getTypeofLoc());
2903 NewTL.setLParenLoc(TL.getLParenLoc());
2904 NewTL.setRParenLoc(TL.getRParenLoc());
2905 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00002906
2907 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002908}
Mike Stump11289f42009-09-09 15:08:12 +00002909
2910template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002911QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002912 DecltypeTypeLoc TL,
2913 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002914 DecltypeType *T = TL.getTypePtr();
2915
Douglas Gregore922c772009-08-04 22:27:00 +00002916 // decltype expressions are not potentially evaluated contexts
2917 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002918
Douglas Gregord6ff3322009-08-04 16:50:30 +00002919 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
2920 if (E.isInvalid())
2921 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002922
John McCall550e0c22009-10-21 00:40:46 +00002923 QualType Result = TL.getType();
2924 if (getDerived().AlwaysRebuild() ||
2925 E.get() != T->getUnderlyingExpr()) {
2926 Result = getDerived().RebuildDecltypeType(move(E));
2927 if (Result.isNull())
2928 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002929 }
John McCall550e0c22009-10-21 00:40:46 +00002930 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00002931
John McCall550e0c22009-10-21 00:40:46 +00002932 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
2933 NewTL.setNameLoc(TL.getNameLoc());
2934
2935 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002936}
2937
2938template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002939QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002940 RecordTypeLoc TL,
2941 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002942 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002944 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2945 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002946 if (!Record)
2947 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002948
John McCall550e0c22009-10-21 00:40:46 +00002949 QualType Result = TL.getType();
2950 if (getDerived().AlwaysRebuild() ||
2951 Record != T->getDecl()) {
2952 Result = getDerived().RebuildRecordType(Record);
2953 if (Result.isNull())
2954 return QualType();
2955 }
Mike Stump11289f42009-09-09 15:08:12 +00002956
John McCall550e0c22009-10-21 00:40:46 +00002957 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
2958 NewTL.setNameLoc(TL.getNameLoc());
2959
2960 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961}
Mike Stump11289f42009-09-09 15:08:12 +00002962
2963template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002964QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002965 EnumTypeLoc TL,
2966 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002967 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002968 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002969 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2970 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002971 if (!Enum)
2972 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002973
John McCall550e0c22009-10-21 00:40:46 +00002974 QualType Result = TL.getType();
2975 if (getDerived().AlwaysRebuild() ||
2976 Enum != T->getDecl()) {
2977 Result = getDerived().RebuildEnumType(Enum);
2978 if (Result.isNull())
2979 return QualType();
2980 }
Mike Stump11289f42009-09-09 15:08:12 +00002981
John McCall550e0c22009-10-21 00:40:46 +00002982 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
2983 NewTL.setNameLoc(TL.getNameLoc());
2984
2985 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002986}
John McCallfcc33b02009-09-05 00:15:47 +00002987
2988template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002989QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002990 ElaboratedTypeLoc TL,
2991 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002992 ElaboratedType *T = TL.getTypePtr();
2993
2994 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00002995 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
2996 if (Underlying.isNull())
2997 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002998
John McCall550e0c22009-10-21 00:40:46 +00002999 QualType Result = TL.getType();
3000 if (getDerived().AlwaysRebuild() ||
3001 Underlying != T->getUnderlyingType()) {
3002 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3003 if (Result.isNull())
3004 return QualType();
3005 }
Mike Stump11289f42009-09-09 15:08:12 +00003006
John McCall550e0c22009-10-21 00:40:46 +00003007 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3008 NewTL.setNameLoc(TL.getNameLoc());
3009
3010 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003011}
Mike Stump11289f42009-09-09 15:08:12 +00003012
John McCalle78aac42010-03-10 03:28:59 +00003013template<typename Derived>
3014QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3015 TypeLocBuilder &TLB,
3016 InjectedClassNameTypeLoc TL,
3017 QualType ObjectType) {
3018 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3019 TL.getTypePtr()->getDecl());
3020 if (!D) return QualType();
3021
3022 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3023 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3024 return T;
3025}
3026
Mike Stump11289f42009-09-09 15:08:12 +00003027
Douglas Gregord6ff3322009-08-04 16:50:30 +00003028template<typename Derived>
3029QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003030 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003031 TemplateTypeParmTypeLoc TL,
3032 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003033 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003034}
3035
Mike Stump11289f42009-09-09 15:08:12 +00003036template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003037QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003038 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003039 SubstTemplateTypeParmTypeLoc TL,
3040 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003041 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003042}
3043
3044template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003045QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3046 const TemplateSpecializationType *TST,
3047 QualType ObjectType) {
3048 // FIXME: this entire method is a temporary workaround; callers
3049 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003050
John McCall0ad16662009-10-29 08:12:44 +00003051 // Fake up a TemplateSpecializationTypeLoc.
3052 TypeLocBuilder TLB;
3053 TemplateSpecializationTypeLoc TL
3054 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3055
John McCall0d07eb32009-10-29 18:45:58 +00003056 SourceLocation BaseLoc = getDerived().getBaseLocation();
3057
3058 TL.setTemplateNameLoc(BaseLoc);
3059 TL.setLAngleLoc(BaseLoc);
3060 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003061 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3062 const TemplateArgument &TA = TST->getArg(i);
3063 TemplateArgumentLoc TAL;
3064 getDerived().InventTemplateArgumentLoc(TA, TAL);
3065 TL.setArgLocInfo(i, TAL.getLocInfo());
3066 }
3067
3068 TypeLocBuilder IgnoredTLB;
3069 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003070}
3071
3072template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003073QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003074 TypeLocBuilder &TLB,
3075 TemplateSpecializationTypeLoc TL,
3076 QualType ObjectType) {
3077 const TemplateSpecializationType *T = TL.getTypePtr();
3078
Mike Stump11289f42009-09-09 15:08:12 +00003079 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003080 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003081 if (Template.isNull())
3082 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003083
John McCall6b51f282009-11-23 01:53:49 +00003084 TemplateArgumentListInfo NewTemplateArgs;
3085 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3086 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3087
3088 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3089 TemplateArgumentLoc Loc;
3090 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003092 NewTemplateArgs.addArgument(Loc);
3093 }
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCall0ad16662009-10-29 08:12:44 +00003095 // FIXME: maybe don't rebuild if all the template arguments are the same.
3096
3097 QualType Result =
3098 getDerived().RebuildTemplateSpecializationType(Template,
3099 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003100 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003101
3102 if (!Result.isNull()) {
3103 TemplateSpecializationTypeLoc NewTL
3104 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3105 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3106 NewTL.setLAngleLoc(TL.getLAngleLoc());
3107 NewTL.setRAngleLoc(TL.getRAngleLoc());
3108 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3109 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall0ad16662009-10-29 08:12:44 +00003112 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003113}
Mike Stump11289f42009-09-09 15:08:12 +00003114
3115template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003116QualType
3117TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003118 QualifiedNameTypeLoc TL,
3119 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003120 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121 NestedNameSpecifier *NNS
3122 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003123 SourceRange(),
3124 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003125 if (!NNS)
3126 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003127
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 QualType Named = getDerived().TransformType(T->getNamedType());
3129 if (Named.isNull())
3130 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003131
John McCall550e0c22009-10-21 00:40:46 +00003132 QualType Result = TL.getType();
3133 if (getDerived().AlwaysRebuild() ||
3134 NNS != T->getQualifier() ||
3135 Named != T->getNamedType()) {
3136 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3137 if (Result.isNull())
3138 return QualType();
3139 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003140
John McCall550e0c22009-10-21 00:40:46 +00003141 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3142 NewTL.setNameLoc(TL.getNameLoc());
3143
3144 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003145}
Mike Stump11289f42009-09-09 15:08:12 +00003146
3147template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003148QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3149 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003150 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003151 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003152
3153 /* FIXME: preserve source information better than this */
3154 SourceRange SR(TL.getNameLoc());
3155
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003157 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003158 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003159 if (!NNS)
3160 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003161
John McCall550e0c22009-10-21 00:40:46 +00003162 QualType Result;
3163
Douglas Gregord6ff3322009-08-04 16:50:30 +00003164 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003165 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003166 = getDerived().TransformType(QualType(TemplateId, 0));
3167 if (NewTemplateId.isNull())
3168 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003169
Douglas Gregord6ff3322009-08-04 16:50:30 +00003170 if (!getDerived().AlwaysRebuild() &&
3171 NNS == T->getQualifier() &&
3172 NewTemplateId == QualType(TemplateId, 0))
3173 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003174
Douglas Gregor02085352010-03-31 20:19:30 +00003175 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3176 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003177 } else {
Douglas Gregor02085352010-03-31 20:19:30 +00003178 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3179 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180 }
John McCall550e0c22009-10-21 00:40:46 +00003181 if (Result.isNull())
3182 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003183
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003184 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003185 NewTL.setNameLoc(TL.getNameLoc());
3186
3187 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003188}
Mike Stump11289f42009-09-09 15:08:12 +00003189
Douglas Gregord6ff3322009-08-04 16:50:30 +00003190template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003191QualType
3192TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003193 ObjCInterfaceTypeLoc TL,
3194 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003195 // ObjCInterfaceType is never dependent.
3196 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003197}
Mike Stump11289f42009-09-09 15:08:12 +00003198
3199template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003200QualType
3201TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003202 ObjCObjectPointerTypeLoc TL,
3203 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003204 // ObjCObjectPointerType is never dependent.
3205 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003206}
3207
Douglas Gregord6ff3322009-08-04 16:50:30 +00003208//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003209// Statement transformation
3210//===----------------------------------------------------------------------===//
3211template<typename Derived>
3212Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003213TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3214 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003215}
3216
3217template<typename Derived>
3218Sema::OwningStmtResult
3219TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3220 return getDerived().TransformCompoundStmt(S, false);
3221}
3222
3223template<typename Derived>
3224Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003225TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003226 bool IsStmtExpr) {
3227 bool SubStmtChanged = false;
3228 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3229 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3230 B != BEnd; ++B) {
3231 OwningStmtResult Result = getDerived().TransformStmt(*B);
3232 if (Result.isInvalid())
3233 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003234
Douglas Gregorebe10102009-08-20 07:17:43 +00003235 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3236 Statements.push_back(Result.takeAs<Stmt>());
3237 }
Mike Stump11289f42009-09-09 15:08:12 +00003238
Douglas Gregorebe10102009-08-20 07:17:43 +00003239 if (!getDerived().AlwaysRebuild() &&
3240 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003241 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003242
3243 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3244 move_arg(Statements),
3245 S->getRBracLoc(),
3246 IsStmtExpr);
3247}
Mike Stump11289f42009-09-09 15:08:12 +00003248
Douglas Gregorebe10102009-08-20 07:17:43 +00003249template<typename Derived>
3250Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003251TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003252 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3253 {
3254 // The case value expressions are not potentially evaluated.
3255 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003256
Eli Friedman06577382009-11-19 03:14:00 +00003257 // Transform the left-hand case value.
3258 LHS = getDerived().TransformExpr(S->getLHS());
3259 if (LHS.isInvalid())
3260 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003261
Eli Friedman06577382009-11-19 03:14:00 +00003262 // Transform the right-hand case value (for the GNU case-range extension).
3263 RHS = getDerived().TransformExpr(S->getRHS());
3264 if (RHS.isInvalid())
3265 return SemaRef.StmtError();
3266 }
Mike Stump11289f42009-09-09 15:08:12 +00003267
Douglas Gregorebe10102009-08-20 07:17:43 +00003268 // Build the case statement.
3269 // Case statements are always rebuilt so that they will attached to their
3270 // transformed switch statement.
3271 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3272 move(LHS),
3273 S->getEllipsisLoc(),
3274 move(RHS),
3275 S->getColonLoc());
3276 if (Case.isInvalid())
3277 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003278
Douglas Gregorebe10102009-08-20 07:17:43 +00003279 // Transform the statement following the case
3280 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3281 if (SubStmt.isInvalid())
3282 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003283
Douglas Gregorebe10102009-08-20 07:17:43 +00003284 // Attach the body to the case statement
3285 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3286}
3287
3288template<typename Derived>
3289Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003290TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003291 // Transform the statement following the default case
3292 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3293 if (SubStmt.isInvalid())
3294 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregorebe10102009-08-20 07:17:43 +00003296 // Default statements are always rebuilt
3297 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3298 move(SubStmt));
3299}
Mike Stump11289f42009-09-09 15:08:12 +00003300
Douglas Gregorebe10102009-08-20 07:17:43 +00003301template<typename Derived>
3302Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003303TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003304 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3305 if (SubStmt.isInvalid())
3306 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003307
Douglas Gregorebe10102009-08-20 07:17:43 +00003308 // FIXME: Pass the real colon location in.
3309 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3310 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3311 move(SubStmt));
3312}
Mike Stump11289f42009-09-09 15:08:12 +00003313
Douglas Gregorebe10102009-08-20 07:17:43 +00003314template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003315Sema::OwningStmtResult
3316TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003317 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003318 OwningExprResult Cond(SemaRef);
3319 VarDecl *ConditionVar = 0;
3320 if (S->getConditionVariable()) {
3321 ConditionVar
3322 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003323 getDerived().TransformDefinition(
3324 S->getConditionVariable()->getLocation(),
3325 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003326 if (!ConditionVar)
3327 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003328 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003329 Cond = getDerived().TransformExpr(S->getCond());
3330
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003331 if (Cond.isInvalid())
3332 return SemaRef.StmtError();
3333 }
Douglas Gregor633caca2009-11-23 23:44:04 +00003334
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003335 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003336
Douglas Gregorebe10102009-08-20 07:17:43 +00003337 // Transform the "then" branch.
3338 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3339 if (Then.isInvalid())
3340 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003341
Douglas Gregorebe10102009-08-20 07:17:43 +00003342 // Transform the "else" branch.
3343 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3344 if (Else.isInvalid())
3345 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003346
Douglas Gregorebe10102009-08-20 07:17:43 +00003347 if (!getDerived().AlwaysRebuild() &&
3348 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003349 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003350 Then.get() == S->getThen() &&
3351 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003352 return SemaRef.Owned(S->Retain());
3353
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003354 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
3355 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003356 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003357}
3358
3359template<typename Derived>
3360Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003361TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003362 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003363 OwningExprResult Cond(SemaRef);
3364 VarDecl *ConditionVar = 0;
3365 if (S->getConditionVariable()) {
3366 ConditionVar
3367 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003368 getDerived().TransformDefinition(
3369 S->getConditionVariable()->getLocation(),
3370 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003371 if (!ConditionVar)
3372 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003373 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003374 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003375
3376 if (Cond.isInvalid())
3377 return SemaRef.StmtError();
3378 }
Mike Stump11289f42009-09-09 15:08:12 +00003379
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003380 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003381
Douglas Gregorebe10102009-08-20 07:17:43 +00003382 // Rebuild the switch statement.
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003383 OwningStmtResult Switch = getDerived().RebuildSwitchStmtStart(FullCond,
3384 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003385 if (Switch.isInvalid())
3386 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003387
Douglas Gregorebe10102009-08-20 07:17:43 +00003388 // Transform the body of the switch statement.
3389 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3390 if (Body.isInvalid())
3391 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003392
Douglas Gregorebe10102009-08-20 07:17:43 +00003393 // Complete the switch statement.
3394 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3395 move(Body));
3396}
Mike Stump11289f42009-09-09 15:08:12 +00003397
Douglas Gregorebe10102009-08-20 07:17:43 +00003398template<typename Derived>
3399Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003400TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003401 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003402 OwningExprResult Cond(SemaRef);
3403 VarDecl *ConditionVar = 0;
3404 if (S->getConditionVariable()) {
3405 ConditionVar
3406 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003407 getDerived().TransformDefinition(
3408 S->getConditionVariable()->getLocation(),
3409 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003410 if (!ConditionVar)
3411 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003412 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003413 Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003414
3415 if (Cond.isInvalid())
3416 return SemaRef.StmtError();
3417 }
Mike Stump11289f42009-09-09 15:08:12 +00003418
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003419 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
Mike Stump11289f42009-09-09 15:08:12 +00003420
Douglas Gregorebe10102009-08-20 07:17:43 +00003421 // Transform the body
3422 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3423 if (Body.isInvalid())
3424 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003425
Douglas Gregorebe10102009-08-20 07:17:43 +00003426 if (!getDerived().AlwaysRebuild() &&
3427 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003428 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003429 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003430 return SemaRef.Owned(S->Retain());
3431
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003432 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, ConditionVar,
3433 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003434}
Mike Stump11289f42009-09-09 15:08:12 +00003435
Douglas Gregorebe10102009-08-20 07:17:43 +00003436template<typename Derived>
3437Sema::OwningStmtResult
3438TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3439 // Transform the condition
3440 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3441 if (Cond.isInvalid())
3442 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003443
Douglas Gregorebe10102009-08-20 07:17:43 +00003444 // Transform the body
3445 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3446 if (Body.isInvalid())
3447 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003448
Douglas Gregorebe10102009-08-20 07:17:43 +00003449 if (!getDerived().AlwaysRebuild() &&
3450 Cond.get() == S->getCond() &&
3451 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003452 return SemaRef.Owned(S->Retain());
3453
Douglas Gregorebe10102009-08-20 07:17:43 +00003454 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3455 /*FIXME:*/S->getWhileLoc(), move(Cond),
3456 S->getRParenLoc());
3457}
Mike Stump11289f42009-09-09 15:08:12 +00003458
Douglas Gregorebe10102009-08-20 07:17:43 +00003459template<typename Derived>
3460Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003461TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003462 // Transform the initialization statement
3463 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3464 if (Init.isInvalid())
3465 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003466
Douglas Gregorebe10102009-08-20 07:17:43 +00003467 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003468 OwningExprResult Cond(SemaRef);
3469 VarDecl *ConditionVar = 0;
3470 if (S->getConditionVariable()) {
3471 ConditionVar
3472 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003473 getDerived().TransformDefinition(
3474 S->getConditionVariable()->getLocation(),
3475 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003476 if (!ConditionVar)
3477 return SemaRef.StmtError();
3478 } else {
3479 Cond = getDerived().TransformExpr(S->getCond());
3480
3481 if (Cond.isInvalid())
3482 return SemaRef.StmtError();
3483 }
Mike Stump11289f42009-09-09 15:08:12 +00003484
Douglas Gregorebe10102009-08-20 07:17:43 +00003485 // Transform the increment
3486 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3487 if (Inc.isInvalid())
3488 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003489
Douglas Gregorebe10102009-08-20 07:17:43 +00003490 // Transform the body
3491 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3492 if (Body.isInvalid())
3493 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003494
Douglas Gregorebe10102009-08-20 07:17:43 +00003495 if (!getDerived().AlwaysRebuild() &&
3496 Init.get() == S->getInit() &&
3497 Cond.get() == S->getCond() &&
3498 Inc.get() == S->getInc() &&
3499 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003500 return SemaRef.Owned(S->Retain());
3501
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003503 move(Init), getSema().MakeFullExpr(Cond),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003504 ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003505 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003506 S->getRParenLoc(), move(Body));
3507}
3508
3509template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003510Sema::OwningStmtResult
3511TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003512 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003513 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003514 S->getLabel());
3515}
3516
3517template<typename Derived>
3518Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003519TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003520 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3521 if (Target.isInvalid())
3522 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524 if (!getDerived().AlwaysRebuild() &&
3525 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003526 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003527
3528 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3529 move(Target));
3530}
3531
3532template<typename Derived>
3533Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003534TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3535 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003536}
Mike Stump11289f42009-09-09 15:08:12 +00003537
Douglas Gregorebe10102009-08-20 07:17:43 +00003538template<typename Derived>
3539Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003540TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3541 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003542}
Mike Stump11289f42009-09-09 15:08:12 +00003543
Douglas Gregorebe10102009-08-20 07:17:43 +00003544template<typename Derived>
3545Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003546TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3548 if (Result.isInvalid())
3549 return SemaRef.StmtError();
3550
Mike Stump11289f42009-09-09 15:08:12 +00003551 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003552 // to tell whether the return type of the function has changed.
3553 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3554}
Mike Stump11289f42009-09-09 15:08:12 +00003555
Douglas Gregorebe10102009-08-20 07:17:43 +00003556template<typename Derived>
3557Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003558TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003559 bool DeclChanged = false;
3560 llvm::SmallVector<Decl *, 4> Decls;
3561 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3562 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003563 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3564 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003565 if (!Transformed)
3566 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregorebe10102009-08-20 07:17:43 +00003568 if (Transformed != *D)
3569 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003570
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 Decls.push_back(Transformed);
3572 }
Mike Stump11289f42009-09-09 15:08:12 +00003573
Douglas Gregorebe10102009-08-20 07:17:43 +00003574 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003575 return SemaRef.Owned(S->Retain());
3576
3577 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 S->getStartLoc(), S->getEndLoc());
3579}
Mike Stump11289f42009-09-09 15:08:12 +00003580
Douglas Gregorebe10102009-08-20 07:17:43 +00003581template<typename Derived>
3582Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003583TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003584 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003585 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003586}
3587
3588template<typename Derived>
3589Sema::OwningStmtResult
3590TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Anders Carlssonaaeef072010-01-24 05:50:09 +00003591
3592 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3593 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003594 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003595
Anders Carlssonaaeef072010-01-24 05:50:09 +00003596 OwningExprResult AsmString(SemaRef);
3597 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3598
3599 bool ExprsChanged = false;
3600
3601 // Go through the outputs.
3602 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003603 Names.push_back(S->getOutputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003604
Anders Carlssonaaeef072010-01-24 05:50:09 +00003605 // No need to transform the constraint literal.
3606 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
3607
3608 // Transform the output expr.
3609 Expr *OutputExpr = S->getOutputExpr(I);
3610 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3611 if (Result.isInvalid())
3612 return SemaRef.StmtError();
3613
3614 ExprsChanged |= Result.get() != OutputExpr;
3615
3616 Exprs.push_back(Result.takeAs<Expr>());
3617 }
3618
3619 // Go through the inputs.
3620 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003621 Names.push_back(S->getInputIdentifier(I));
Anders Carlsson087bc132010-01-30 20:05:21 +00003622
Anders Carlssonaaeef072010-01-24 05:50:09 +00003623 // No need to transform the constraint literal.
3624 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
3625
3626 // Transform the input expr.
3627 Expr *InputExpr = S->getInputExpr(I);
3628 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3629 if (Result.isInvalid())
3630 return SemaRef.StmtError();
3631
3632 ExprsChanged |= Result.get() != InputExpr;
3633
3634 Exprs.push_back(Result.takeAs<Expr>());
3635 }
3636
3637 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3638 return SemaRef.Owned(S->Retain());
3639
3640 // Go through the clobbers.
3641 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3642 Clobbers.push_back(S->getClobber(I)->Retain());
3643
3644 // No need to transform the asm string literal.
3645 AsmString = SemaRef.Owned(S->getAsmString());
3646
3647 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3648 S->isSimple(),
3649 S->isVolatile(),
3650 S->getNumOutputs(),
3651 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003652 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003653 move_arg(Constraints),
3654 move_arg(Exprs),
3655 move(AsmString),
3656 move_arg(Clobbers),
3657 S->getRParenLoc(),
3658 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003659}
3660
3661
3662template<typename Derived>
3663Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003664TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 // FIXME: Implement this
3666 assert(false && "Cannot transform an Objective-C @try statement");
Mike Stump11289f42009-09-09 15:08:12 +00003667 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003668}
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregorebe10102009-08-20 07:17:43 +00003670template<typename Derived>
3671Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003672TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 // FIXME: Implement this
3674 assert(false && "Cannot transform an Objective-C @catch statement");
3675 return SemaRef.Owned(S->Retain());
3676}
Mike Stump11289f42009-09-09 15:08:12 +00003677
Douglas Gregorebe10102009-08-20 07:17:43 +00003678template<typename Derived>
3679Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003680TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 // FIXME: Implement this
3682 assert(false && "Cannot transform an Objective-C @finally statement");
Mike Stump11289f42009-09-09 15:08:12 +00003683 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003684}
Mike Stump11289f42009-09-09 15:08:12 +00003685
Douglas Gregorebe10102009-08-20 07:17:43 +00003686template<typename Derived>
3687Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003688TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003689 OwningExprResult Operand(SemaRef);
3690 if (S->getThrowExpr()) {
3691 Operand = getDerived().TransformExpr(S->getThrowExpr());
3692 if (Operand.isInvalid())
3693 return getSema().StmtError();
3694 }
3695
3696 if (!getDerived().AlwaysRebuild() &&
3697 Operand.get() == S->getThrowExpr())
3698 return getSema().Owned(S->Retain());
3699
3700 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003701}
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregorebe10102009-08-20 07:17:43 +00003703template<typename Derived>
3704Sema::OwningStmtResult
3705TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003706 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003707 // Transform the object we are locking.
3708 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3709 if (Object.isInvalid())
3710 return SemaRef.StmtError();
3711
3712 // Transform the body.
3713 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3714 if (Body.isInvalid())
3715 return SemaRef.StmtError();
3716
3717 // If nothing change, just retain the current statement.
3718 if (!getDerived().AlwaysRebuild() &&
3719 Object.get() == S->getSynchExpr() &&
3720 Body.get() == S->getSynchBody())
3721 return SemaRef.Owned(S->Retain());
3722
3723 // Build a new statement.
3724 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3725 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003726}
3727
3728template<typename Derived>
3729Sema::OwningStmtResult
3730TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003731 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003732 // Transform the element statement.
3733 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3734 if (Element.isInvalid())
3735 return SemaRef.StmtError();
3736
3737 // Transform the collection expression.
3738 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3739 if (Collection.isInvalid())
3740 return SemaRef.StmtError();
3741
3742 // Transform the body.
3743 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3744 if (Body.isInvalid())
3745 return SemaRef.StmtError();
3746
3747 // If nothing changed, just retain this statement.
3748 if (!getDerived().AlwaysRebuild() &&
3749 Element.get() == S->getElement() &&
3750 Collection.get() == S->getCollection() &&
3751 Body.get() == S->getBody())
3752 return SemaRef.Owned(S->Retain());
3753
3754 // Build a new statement.
3755 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3756 /*FIXME:*/S->getForLoc(),
3757 move(Element),
3758 move(Collection),
3759 S->getRParenLoc(),
3760 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003761}
3762
3763
3764template<typename Derived>
3765Sema::OwningStmtResult
3766TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
3767 // Transform the exception declaration, if any.
3768 VarDecl *Var = 0;
3769 if (S->getExceptionDecl()) {
3770 VarDecl *ExceptionDecl = S->getExceptionDecl();
3771 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
3772 ExceptionDecl->getDeclName());
3773
3774 QualType T = getDerived().TransformType(ExceptionDecl->getType());
3775 if (T.isNull())
3776 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003777
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
3779 T,
John McCallbcd03502009-12-07 02:54:59 +00003780 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003781 ExceptionDecl->getIdentifier(),
3782 ExceptionDecl->getLocation(),
3783 /*FIXME: Inaccurate*/
3784 SourceRange(ExceptionDecl->getLocation()));
3785 if (!Var || Var->isInvalidDecl()) {
3786 if (Var)
3787 Var->Destroy(SemaRef.Context);
3788 return SemaRef.StmtError();
3789 }
3790 }
Mike Stump11289f42009-09-09 15:08:12 +00003791
Douglas Gregorebe10102009-08-20 07:17:43 +00003792 // Transform the actual exception handler.
3793 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
3794 if (Handler.isInvalid()) {
3795 if (Var)
3796 Var->Destroy(SemaRef.Context);
3797 return SemaRef.StmtError();
3798 }
Mike Stump11289f42009-09-09 15:08:12 +00003799
Douglas Gregorebe10102009-08-20 07:17:43 +00003800 if (!getDerived().AlwaysRebuild() &&
3801 !Var &&
3802 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00003803 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003804
3805 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
3806 Var,
3807 move(Handler));
3808}
Mike Stump11289f42009-09-09 15:08:12 +00003809
Douglas Gregorebe10102009-08-20 07:17:43 +00003810template<typename Derived>
3811Sema::OwningStmtResult
3812TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
3813 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00003814 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00003815 = getDerived().TransformCompoundStmt(S->getTryBlock());
3816 if (TryBlock.isInvalid())
3817 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003818
Douglas Gregorebe10102009-08-20 07:17:43 +00003819 // Transform the handlers.
3820 bool HandlerChanged = false;
3821 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
3822 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00003823 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00003824 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
3825 if (Handler.isInvalid())
3826 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003827
Douglas Gregorebe10102009-08-20 07:17:43 +00003828 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
3829 Handlers.push_back(Handler.takeAs<Stmt>());
3830 }
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (!getDerived().AlwaysRebuild() &&
3833 TryBlock.get() == S->getTryBlock() &&
3834 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003835 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003836
3837 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00003838 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00003839}
Mike Stump11289f42009-09-09 15:08:12 +00003840
Douglas Gregorebe10102009-08-20 07:17:43 +00003841//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00003842// Expression transformation
3843//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00003844template<typename Derived>
3845Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003846TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003847 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003848}
Mike Stump11289f42009-09-09 15:08:12 +00003849
3850template<typename Derived>
3851Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003852TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003853 NestedNameSpecifier *Qualifier = 0;
3854 if (E->getQualifier()) {
3855 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003856 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003857 if (!Qualifier)
3858 return SemaRef.ExprError();
3859 }
John McCallce546572009-12-08 09:08:17 +00003860
3861 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003862 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
3863 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00003864 if (!ND)
3865 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003866
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003867 if (!getDerived().AlwaysRebuild() &&
3868 Qualifier == E->getQualifier() &&
3869 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00003870 !E->hasExplicitTemplateArgumentList()) {
3871
3872 // Mark it referenced in the new context regardless.
3873 // FIXME: this is a bit instantiation-specific.
3874 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
3875
Mike Stump11289f42009-09-09 15:08:12 +00003876 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003877 }
John McCallce546572009-12-08 09:08:17 +00003878
3879 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
3880 if (E->hasExplicitTemplateArgumentList()) {
3881 TemplateArgs = &TransArgs;
3882 TransArgs.setLAngleLoc(E->getLAngleLoc());
3883 TransArgs.setRAngleLoc(E->getRAngleLoc());
3884 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
3885 TemplateArgumentLoc Loc;
3886 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
3887 return SemaRef.ExprError();
3888 TransArgs.addArgument(Loc);
3889 }
3890 }
3891
Douglas Gregor4bd90e52009-10-23 18:54:35 +00003892 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00003893 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00003894}
Mike Stump11289f42009-09-09 15:08:12 +00003895
Douglas Gregora16548e2009-08-11 05:31:07 +00003896template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003897Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003898TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003899 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003900}
Mike Stump11289f42009-09-09 15:08:12 +00003901
Douglas Gregora16548e2009-08-11 05:31:07 +00003902template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003903Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003904TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003905 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003906}
Mike Stump11289f42009-09-09 15:08:12 +00003907
Douglas Gregora16548e2009-08-11 05:31:07 +00003908template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003909Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003910TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003911 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003912}
Mike Stump11289f42009-09-09 15:08:12 +00003913
Douglas Gregora16548e2009-08-11 05:31:07 +00003914template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003915Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003916TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003917 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00003918}
Mike Stump11289f42009-09-09 15:08:12 +00003919
Douglas Gregora16548e2009-08-11 05:31:07 +00003920template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003921Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003922TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00003923 return SemaRef.Owned(E->Retain());
3924}
3925
3926template<typename Derived>
3927Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003928TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003929 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
3930 if (SubExpr.isInvalid())
3931 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003932
Douglas Gregora16548e2009-08-11 05:31:07 +00003933 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003934 return SemaRef.Owned(E->Retain());
3935
3936 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003937 E->getRParen());
3938}
3939
Mike Stump11289f42009-09-09 15:08:12 +00003940template<typename Derived>
3941Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003942TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
3943 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00003944 if (SubExpr.isInvalid())
3945 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003946
Douglas Gregora16548e2009-08-11 05:31:07 +00003947 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00003948 return SemaRef.Owned(E->Retain());
3949
Douglas Gregora16548e2009-08-11 05:31:07 +00003950 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
3951 E->getOpcode(),
3952 move(SubExpr));
3953}
Mike Stump11289f42009-09-09 15:08:12 +00003954
Douglas Gregora16548e2009-08-11 05:31:07 +00003955template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003956Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003957TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003958 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00003959 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00003960
John McCallbcd03502009-12-07 02:54:59 +00003961 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00003962 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003963 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003964
John McCall4c98fd82009-11-04 07:28:41 +00003965 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00003966 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00003967
John McCall4c98fd82009-11-04 07:28:41 +00003968 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00003969 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00003970 E->getSourceRange());
3971 }
Mike Stump11289f42009-09-09 15:08:12 +00003972
Douglas Gregora16548e2009-08-11 05:31:07 +00003973 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00003974 {
Douglas Gregora16548e2009-08-11 05:31:07 +00003975 // C++0x [expr.sizeof]p1:
3976 // The operand is either an expression, which is an unevaluated operand
3977 // [...]
3978 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregora16548e2009-08-11 05:31:07 +00003980 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
3981 if (SubExpr.isInvalid())
3982 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003983
Douglas Gregora16548e2009-08-11 05:31:07 +00003984 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
3985 return SemaRef.Owned(E->Retain());
3986 }
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregora16548e2009-08-11 05:31:07 +00003988 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
3989 E->isSizeOf(),
3990 E->getSourceRange());
3991}
Mike Stump11289f42009-09-09 15:08:12 +00003992
Douglas Gregora16548e2009-08-11 05:31:07 +00003993template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003994Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00003995TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003996 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
3997 if (LHS.isInvalid())
3998 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00003999
Douglas Gregora16548e2009-08-11 05:31:07 +00004000 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4001 if (RHS.isInvalid())
4002 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004003
4004
Douglas Gregora16548e2009-08-11 05:31:07 +00004005 if (!getDerived().AlwaysRebuild() &&
4006 LHS.get() == E->getLHS() &&
4007 RHS.get() == E->getRHS())
4008 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004009
Douglas Gregora16548e2009-08-11 05:31:07 +00004010 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4011 /*FIXME:*/E->getLHS()->getLocStart(),
4012 move(RHS),
4013 E->getRBracketLoc());
4014}
Mike Stump11289f42009-09-09 15:08:12 +00004015
4016template<typename Derived>
4017Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004018TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004019 // Transform the callee.
4020 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4021 if (Callee.isInvalid())
4022 return SemaRef.ExprError();
4023
4024 // Transform arguments.
4025 bool ArgChanged = false;
4026 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4027 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4028 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4029 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4030 if (Arg.isInvalid())
4031 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004032
Douglas Gregora16548e2009-08-11 05:31:07 +00004033 // FIXME: Wrong source location information for the ','.
4034 FakeCommaLocs.push_back(
4035 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004036
4037 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004038 Args.push_back(Arg.takeAs<Expr>());
4039 }
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregora16548e2009-08-11 05:31:07 +00004041 if (!getDerived().AlwaysRebuild() &&
4042 Callee.get() == E->getCallee() &&
4043 !ArgChanged)
4044 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004045
Douglas Gregora16548e2009-08-11 05:31:07 +00004046 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004047 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004048 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4049 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4050 move_arg(Args),
4051 FakeCommaLocs.data(),
4052 E->getRParenLoc());
4053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
4055template<typename Derived>
4056Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004057TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004058 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4059 if (Base.isInvalid())
4060 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004061
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004062 NestedNameSpecifier *Qualifier = 0;
4063 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004064 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004065 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004066 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004067 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004068 return SemaRef.ExprError();
4069 }
Mike Stump11289f42009-09-09 15:08:12 +00004070
Eli Friedman2cfcef62009-12-04 06:40:45 +00004071 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004072 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4073 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004074 if (!Member)
4075 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004076
John McCall16df1e52010-03-30 21:47:33 +00004077 NamedDecl *FoundDecl = E->getFoundDecl();
4078 if (FoundDecl == E->getMemberDecl()) {
4079 FoundDecl = Member;
4080 } else {
4081 FoundDecl = cast_or_null<NamedDecl>(
4082 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4083 if (!FoundDecl)
4084 return SemaRef.ExprError();
4085 }
4086
Douglas Gregora16548e2009-08-11 05:31:07 +00004087 if (!getDerived().AlwaysRebuild() &&
4088 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004089 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004090 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004091 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004092 !E->hasExplicitTemplateArgumentList()) {
4093
4094 // Mark it referenced in the new context regardless.
4095 // FIXME: this is a bit instantiation-specific.
4096 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004097 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004098 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004099
John McCall6b51f282009-11-23 01:53:49 +00004100 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004101 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004102 TransArgs.setLAngleLoc(E->getLAngleLoc());
4103 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004104 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004105 TemplateArgumentLoc Loc;
4106 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004107 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004108 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004109 }
4110 }
4111
Douglas Gregora16548e2009-08-11 05:31:07 +00004112 // FIXME: Bogus source location for the operator
4113 SourceLocation FakeOperatorLoc
4114 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4115
John McCall38836f02010-01-15 08:34:02 +00004116 // FIXME: to do this check properly, we will need to preserve the
4117 // first-qualifier-in-scope here, just in case we had a dependent
4118 // base (and therefore couldn't do the check) and a
4119 // nested-name-qualifier (and therefore could do the lookup).
4120 NamedDecl *FirstQualifierInScope = 0;
4121
Douglas Gregora16548e2009-08-11 05:31:07 +00004122 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4123 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004124 Qualifier,
4125 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004126 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004127 Member,
John McCall16df1e52010-03-30 21:47:33 +00004128 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004129 (E->hasExplicitTemplateArgumentList()
4130 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004131 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004132}
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregora16548e2009-08-11 05:31:07 +00004134template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004135Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004136TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004137 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4138 if (LHS.isInvalid())
4139 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregora16548e2009-08-11 05:31:07 +00004141 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4142 if (RHS.isInvalid())
4143 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregora16548e2009-08-11 05:31:07 +00004145 if (!getDerived().AlwaysRebuild() &&
4146 LHS.get() == E->getLHS() &&
4147 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
4149
Douglas Gregora16548e2009-08-11 05:31:07 +00004150 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4151 move(LHS), move(RHS));
4152}
4153
Mike Stump11289f42009-09-09 15:08:12 +00004154template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004155Sema::OwningExprResult
4156TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004157 CompoundAssignOperator *E) {
4158 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004159}
Mike Stump11289f42009-09-09 15:08:12 +00004160
Douglas Gregora16548e2009-08-11 05:31:07 +00004161template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004162Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004163TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004164 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4165 if (Cond.isInvalid())
4166 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004167
Douglas Gregora16548e2009-08-11 05:31:07 +00004168 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4169 if (LHS.isInvalid())
4170 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004171
Douglas Gregora16548e2009-08-11 05:31:07 +00004172 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4173 if (RHS.isInvalid())
4174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregora16548e2009-08-11 05:31:07 +00004176 if (!getDerived().AlwaysRebuild() &&
4177 Cond.get() == E->getCond() &&
4178 LHS.get() == E->getLHS() &&
4179 RHS.get() == E->getRHS())
4180 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004181
4182 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004183 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004184 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004185 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 move(RHS));
4187}
Mike Stump11289f42009-09-09 15:08:12 +00004188
4189template<typename Derived>
4190Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004191TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004192 // Implicit casts are eliminated during transformation, since they
4193 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004194 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004195}
Mike Stump11289f42009-09-09 15:08:12 +00004196
Douglas Gregora16548e2009-08-11 05:31:07 +00004197template<typename Derived>
4198Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004199TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004200 TypeSourceInfo *OldT;
4201 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004202 {
4203 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004204 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004205 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4206 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004207
John McCall97513962010-01-15 18:39:57 +00004208 OldT = E->getTypeInfoAsWritten();
4209 NewT = getDerived().TransformType(OldT);
4210 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004211 return SemaRef.ExprError();
4212 }
Mike Stump11289f42009-09-09 15:08:12 +00004213
Douglas Gregor6131b442009-12-12 18:16:41 +00004214 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004215 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004216 if (SubExpr.isInvalid())
4217 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004218
Douglas Gregora16548e2009-08-11 05:31:07 +00004219 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004220 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004221 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004222 return SemaRef.Owned(E->Retain());
4223
John McCall97513962010-01-15 18:39:57 +00004224 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4225 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004226 E->getRParenLoc(),
4227 move(SubExpr));
4228}
Mike Stump11289f42009-09-09 15:08:12 +00004229
Douglas Gregora16548e2009-08-11 05:31:07 +00004230template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004231Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004232TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004233 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4234 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4235 if (!NewT)
4236 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004237
Douglas Gregora16548e2009-08-11 05:31:07 +00004238 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4239 if (Init.isInvalid())
4240 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004241
Douglas Gregora16548e2009-08-11 05:31:07 +00004242 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004243 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004244 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004245 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004246
John McCall5d7aa7f2010-01-19 22:33:45 +00004247 // Note: the expression type doesn't necessarily match the
4248 // type-as-written, but that's okay, because it should always be
4249 // derivable from the initializer.
4250
John McCalle15bbff2010-01-18 19:35:47 +00004251 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004252 /*FIXME:*/E->getInitializer()->getLocEnd(),
4253 move(Init));
4254}
Mike Stump11289f42009-09-09 15:08:12 +00004255
Douglas Gregora16548e2009-08-11 05:31:07 +00004256template<typename Derived>
4257Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004258TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004259 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4260 if (Base.isInvalid())
4261 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004262
Douglas Gregora16548e2009-08-11 05:31:07 +00004263 if (!getDerived().AlwaysRebuild() &&
4264 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004265 return SemaRef.Owned(E->Retain());
4266
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004268 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4270 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4271 E->getAccessorLoc(),
4272 E->getAccessor());
4273}
Mike Stump11289f42009-09-09 15:08:12 +00004274
Douglas Gregora16548e2009-08-11 05:31:07 +00004275template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004276Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004277TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004279
Douglas Gregora16548e2009-08-11 05:31:07 +00004280 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4281 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4282 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4283 if (Init.isInvalid())
4284 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004285
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 InitChanged = InitChanged || Init.get() != E->getInit(I);
4287 Inits.push_back(Init.takeAs<Expr>());
4288 }
Mike Stump11289f42009-09-09 15:08:12 +00004289
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004291 return SemaRef.Owned(E->Retain());
4292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004294 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004295}
Mike Stump11289f42009-09-09 15:08:12 +00004296
Douglas Gregora16548e2009-08-11 05:31:07 +00004297template<typename Derived>
4298Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004299TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004300 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004301
Douglas Gregorebe10102009-08-20 07:17:43 +00004302 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4304 if (Init.isInvalid())
4305 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004306
Douglas Gregorebe10102009-08-20 07:17:43 +00004307 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4309 bool ExprChanged = false;
4310 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4311 DEnd = E->designators_end();
4312 D != DEnd; ++D) {
4313 if (D->isFieldDesignator()) {
4314 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4315 D->getDotLoc(),
4316 D->getFieldLoc()));
4317 continue;
4318 }
Mike Stump11289f42009-09-09 15:08:12 +00004319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 if (D->isArrayDesignator()) {
4321 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4322 if (Index.isInvalid())
4323 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004324
4325 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004326 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregora16548e2009-08-11 05:31:07 +00004328 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4329 ArrayExprs.push_back(Index.release());
4330 continue;
4331 }
Mike Stump11289f42009-09-09 15:08:12 +00004332
Douglas Gregora16548e2009-08-11 05:31:07 +00004333 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004334 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004335 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4336 if (Start.isInvalid())
4337 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004338
Douglas Gregora16548e2009-08-11 05:31:07 +00004339 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4340 if (End.isInvalid())
4341 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004342
4343 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 End.get(),
4345 D->getLBracketLoc(),
4346 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4349 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004350
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 ArrayExprs.push_back(Start.release());
4352 ArrayExprs.push_back(End.release());
4353 }
Mike Stump11289f42009-09-09 15:08:12 +00004354
Douglas Gregora16548e2009-08-11 05:31:07 +00004355 if (!getDerived().AlwaysRebuild() &&
4356 Init.get() == E->getInit() &&
4357 !ExprChanged)
4358 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004359
Douglas Gregora16548e2009-08-11 05:31:07 +00004360 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4361 E->getEqualOrColonLoc(),
4362 E->usesGNUSyntax(), move(Init));
4363}
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregora16548e2009-08-11 05:31:07 +00004365template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004366Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004367TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004368 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004369 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4370
4371 // FIXME: Will we ever have proper type location here? Will we actually
4372 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004373 QualType T = getDerived().TransformType(E->getType());
4374 if (T.isNull())
4375 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 if (!getDerived().AlwaysRebuild() &&
4378 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004379 return SemaRef.Owned(E->Retain());
4380
Douglas Gregora16548e2009-08-11 05:31:07 +00004381 return getDerived().RebuildImplicitValueInitExpr(T);
4382}
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004385Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004386TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004387 // FIXME: Do we want the type as written?
4388 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 {
4391 // FIXME: Source location isn't quite accurate.
4392 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4393 T = getDerived().TransformType(E->getType());
4394 if (T.isNull())
4395 return SemaRef.ExprError();
4396 }
Mike Stump11289f42009-09-09 15:08:12 +00004397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4399 if (SubExpr.isInvalid())
4400 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 if (!getDerived().AlwaysRebuild() &&
4403 T == E->getType() &&
4404 SubExpr.get() == E->getSubExpr())
4405 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004406
Douglas Gregora16548e2009-08-11 05:31:07 +00004407 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4408 T, E->getRParenLoc());
4409}
4410
4411template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004412Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004413TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 bool ArgumentChanged = false;
4415 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4416 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4417 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4418 if (Init.isInvalid())
4419 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004420
Douglas Gregora16548e2009-08-11 05:31:07 +00004421 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4422 Inits.push_back(Init.takeAs<Expr>());
4423 }
Mike Stump11289f42009-09-09 15:08:12 +00004424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4426 move_arg(Inits),
4427 E->getRParenLoc());
4428}
Mike Stump11289f42009-09-09 15:08:12 +00004429
Douglas Gregora16548e2009-08-11 05:31:07 +00004430/// \brief Transform an address-of-label expression.
4431///
4432/// By default, the transformation of an address-of-label expression always
4433/// rebuilds the expression, so that the label identifier can be resolved to
4434/// the corresponding label statement by semantic analysis.
4435template<typename Derived>
4436Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004437TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004438 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4439 E->getLabel());
4440}
Mike Stump11289f42009-09-09 15:08:12 +00004441
4442template<typename Derived>
Douglas Gregorc95a1fa2009-11-04 07:01:15 +00004443Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004444TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004445 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004446 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4447 if (SubStmt.isInvalid())
4448 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 if (!getDerived().AlwaysRebuild() &&
4451 SubStmt.get() == E->getSubStmt())
4452 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004453
4454 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004455 move(SubStmt),
4456 E->getRParenLoc());
4457}
Mike Stump11289f42009-09-09 15:08:12 +00004458
Douglas Gregora16548e2009-08-11 05:31:07 +00004459template<typename Derived>
4460Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004461TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 QualType T1, T2;
4463 {
4464 // FIXME: Source location isn't quite accurate.
4465 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004466
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 T1 = getDerived().TransformType(E->getArgType1());
4468 if (T1.isNull())
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 T2 = getDerived().TransformType(E->getArgType2());
4472 if (T2.isNull())
4473 return SemaRef.ExprError();
4474 }
4475
4476 if (!getDerived().AlwaysRebuild() &&
4477 T1 == E->getArgType1() &&
4478 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004479 return SemaRef.Owned(E->Retain());
4480
Douglas Gregora16548e2009-08-11 05:31:07 +00004481 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4482 T1, T2, E->getRParenLoc());
4483}
Mike Stump11289f42009-09-09 15:08:12 +00004484
Douglas Gregora16548e2009-08-11 05:31:07 +00004485template<typename Derived>
4486Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004487TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004488 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4489 if (Cond.isInvalid())
4490 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004491
Douglas Gregora16548e2009-08-11 05:31:07 +00004492 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4493 if (LHS.isInvalid())
4494 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregora16548e2009-08-11 05:31:07 +00004496 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4497 if (RHS.isInvalid())
4498 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500 if (!getDerived().AlwaysRebuild() &&
4501 Cond.get() == E->getCond() &&
4502 LHS.get() == E->getLHS() &&
4503 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004504 return SemaRef.Owned(E->Retain());
4505
Douglas Gregora16548e2009-08-11 05:31:07 +00004506 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4507 move(Cond), move(LHS), move(RHS),
4508 E->getRParenLoc());
4509}
Mike Stump11289f42009-09-09 15:08:12 +00004510
Douglas Gregora16548e2009-08-11 05:31:07 +00004511template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004512Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004513TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004514 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004515}
4516
4517template<typename Derived>
4518Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004519TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004520 switch (E->getOperator()) {
4521 case OO_New:
4522 case OO_Delete:
4523 case OO_Array_New:
4524 case OO_Array_Delete:
4525 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4526 return SemaRef.ExprError();
4527
4528 case OO_Call: {
4529 // This is a call to an object's operator().
4530 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4531
4532 // Transform the object itself.
4533 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4534 if (Object.isInvalid())
4535 return SemaRef.ExprError();
4536
4537 // FIXME: Poor location information
4538 SourceLocation FakeLParenLoc
4539 = SemaRef.PP.getLocForEndOfToken(
4540 static_cast<Expr *>(Object.get())->getLocEnd());
4541
4542 // Transform the call arguments.
4543 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4544 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4545 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004546 if (getDerived().DropCallArgument(E->getArg(I)))
4547 break;
4548
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004549 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4550 if (Arg.isInvalid())
4551 return SemaRef.ExprError();
4552
4553 // FIXME: Poor source location information.
4554 SourceLocation FakeCommaLoc
4555 = SemaRef.PP.getLocForEndOfToken(
4556 static_cast<Expr *>(Arg.get())->getLocEnd());
4557 FakeCommaLocs.push_back(FakeCommaLoc);
4558 Args.push_back(Arg.release());
4559 }
4560
4561 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4562 move_arg(Args),
4563 FakeCommaLocs.data(),
4564 E->getLocEnd());
4565 }
4566
4567#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4568 case OO_##Name:
4569#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4570#include "clang/Basic/OperatorKinds.def"
4571 case OO_Subscript:
4572 // Handled below.
4573 break;
4574
4575 case OO_Conditional:
4576 llvm_unreachable("conditional operator is not actually overloadable");
4577 return SemaRef.ExprError();
4578
4579 case OO_None:
4580 case NUM_OVERLOADED_OPERATORS:
4581 llvm_unreachable("not an overloaded operator?");
4582 return SemaRef.ExprError();
4583 }
4584
Douglas Gregora16548e2009-08-11 05:31:07 +00004585 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4586 if (Callee.isInvalid())
4587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
John McCall47f29ea2009-12-08 09:21:05 +00004589 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 if (First.isInvalid())
4591 return SemaRef.ExprError();
4592
4593 OwningExprResult Second(SemaRef);
4594 if (E->getNumArgs() == 2) {
4595 Second = getDerived().TransformExpr(E->getArg(1));
4596 if (Second.isInvalid())
4597 return SemaRef.ExprError();
4598 }
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregora16548e2009-08-11 05:31:07 +00004600 if (!getDerived().AlwaysRebuild() &&
4601 Callee.get() == E->getCallee() &&
4602 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004603 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4604 return SemaRef.Owned(E->Retain());
4605
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4607 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004608 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 move(First),
4610 move(Second));
4611}
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregora16548e2009-08-11 05:31:07 +00004613template<typename Derived>
4614Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004615TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4616 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004617}
Mike Stump11289f42009-09-09 15:08:12 +00004618
Douglas Gregora16548e2009-08-11 05:31:07 +00004619template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004620Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004621TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004622 TypeSourceInfo *OldT;
4623 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004624 {
4625 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004626 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004627 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4628 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004629
John McCall97513962010-01-15 18:39:57 +00004630 OldT = E->getTypeInfoAsWritten();
4631 NewT = getDerived().TransformType(OldT);
4632 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004633 return SemaRef.ExprError();
4634 }
Mike Stump11289f42009-09-09 15:08:12 +00004635
Douglas Gregor6131b442009-12-12 18:16:41 +00004636 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004637 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 if (SubExpr.isInvalid())
4639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004640
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004642 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004644 return SemaRef.Owned(E->Retain());
4645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004647 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4649 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4650 SourceLocation FakeRParenLoc
4651 = SemaRef.PP.getLocForEndOfToken(
4652 E->getSubExpr()->getSourceRange().getEnd());
4653 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004654 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004656 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004657 FakeRAngleLoc,
4658 FakeRAngleLoc,
4659 move(SubExpr),
4660 FakeRParenLoc);
4661}
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663template<typename Derived>
4664Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004665TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4666 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004667}
Mike Stump11289f42009-09-09 15:08:12 +00004668
4669template<typename Derived>
4670Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004671TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4672 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004673}
4674
Douglas Gregora16548e2009-08-11 05:31:07 +00004675template<typename Derived>
4676Sema::OwningExprResult
4677TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004678 CXXReinterpretCastExpr *E) {
4679 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004680}
Mike Stump11289f42009-09-09 15:08:12 +00004681
Douglas Gregora16548e2009-08-11 05:31:07 +00004682template<typename Derived>
4683Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004684TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4685 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004686}
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688template<typename Derived>
4689Sema::OwningExprResult
4690TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004691 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004692 TypeSourceInfo *OldT;
4693 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 {
4695 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004696
John McCall97513962010-01-15 18:39:57 +00004697 OldT = E->getTypeInfoAsWritten();
4698 NewT = getDerived().TransformType(OldT);
4699 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004700 return SemaRef.ExprError();
4701 }
Mike Stump11289f42009-09-09 15:08:12 +00004702
Douglas Gregor6131b442009-12-12 18:16:41 +00004703 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004704 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 if (SubExpr.isInvalid())
4706 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregora16548e2009-08-11 05:31:07 +00004708 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004709 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004711 return SemaRef.Owned(E->Retain());
4712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 // FIXME: The end of the type's source range is wrong
4714 return getDerived().RebuildCXXFunctionalCastExpr(
4715 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00004716 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 /*FIXME:*/E->getSubExpr()->getLocStart(),
4718 move(SubExpr),
4719 E->getRParenLoc());
4720}
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722template<typename Derived>
4723Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 if (E->isTypeOperand()) {
4726 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 QualType T = getDerived().TransformType(E->getTypeOperand());
4729 if (T.isNull())
4730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 if (!getDerived().AlwaysRebuild() &&
4733 T == E->getTypeOperand())
4734 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4737 /*FIXME:*/E->getLocStart(),
4738 T,
4739 E->getLocEnd());
4740 }
Mike Stump11289f42009-09-09 15:08:12 +00004741
Douglas Gregora16548e2009-08-11 05:31:07 +00004742 // We don't know whether the expression is potentially evaluated until
4743 // after we perform semantic analysis, so the expression is potentially
4744 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00004745 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00004746 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004747
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
4749 if (SubExpr.isInvalid())
4750 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 if (!getDerived().AlwaysRebuild() &&
4753 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00004754 return SemaRef.Owned(E->Retain());
4755
Douglas Gregora16548e2009-08-11 05:31:07 +00004756 return getDerived().RebuildCXXTypeidExpr(E->getLocStart(),
4757 /*FIXME:*/E->getLocStart(),
4758 move(SubExpr),
4759 E->getLocEnd());
4760}
4761
4762template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004763Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004764TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004765 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004766}
Mike Stump11289f42009-09-09 15:08:12 +00004767
Douglas Gregora16548e2009-08-11 05:31:07 +00004768template<typename Derived>
4769Sema::OwningExprResult
4770TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004771 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004772 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004773}
Mike Stump11289f42009-09-09 15:08:12 +00004774
Douglas Gregora16548e2009-08-11 05:31:07 +00004775template<typename Derived>
4776Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004777TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004779
Douglas Gregora16548e2009-08-11 05:31:07 +00004780 QualType T = getDerived().TransformType(E->getType());
4781 if (T.isNull())
4782 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 if (!getDerived().AlwaysRebuild() &&
4785 T == E->getType())
4786 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregorb15af892010-01-07 23:12:05 +00004788 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00004789}
Mike Stump11289f42009-09-09 15:08:12 +00004790
Douglas Gregora16548e2009-08-11 05:31:07 +00004791template<typename Derived>
4792Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004793TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4795 if (SubExpr.isInvalid())
4796 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004797
Douglas Gregora16548e2009-08-11 05:31:07 +00004798 if (!getDerived().AlwaysRebuild() &&
4799 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004800 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004801
4802 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
4803}
Mike Stump11289f42009-09-09 15:08:12 +00004804
Douglas Gregora16548e2009-08-11 05:31:07 +00004805template<typename Derived>
4806Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004807TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004808 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004809 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
4810 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 if (!Param)
4812 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004813
Chandler Carruth794da4c2010-02-08 06:42:49 +00004814 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 Param == E->getParam())
4816 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004817
Douglas Gregor033f6752009-12-23 23:03:06 +00004818 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00004819}
Mike Stump11289f42009-09-09 15:08:12 +00004820
Douglas Gregora16548e2009-08-11 05:31:07 +00004821template<typename Derived>
4822Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004823TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004824 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
4825
4826 QualType T = getDerived().TransformType(E->getType());
4827 if (T.isNull())
4828 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004829
Douglas Gregora16548e2009-08-11 05:31:07 +00004830 if (!getDerived().AlwaysRebuild() &&
4831 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004832 return SemaRef.Owned(E->Retain());
4833
4834 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004835 /*FIXME:*/E->getTypeBeginLoc(),
4836 T,
4837 E->getRParenLoc());
4838}
Mike Stump11289f42009-09-09 15:08:12 +00004839
Douglas Gregora16548e2009-08-11 05:31:07 +00004840template<typename Derived>
4841Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004842TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004843 // Transform the type that we're allocating
4844 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
4845 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
4846 if (AllocType.isNull())
4847 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004848
Douglas Gregora16548e2009-08-11 05:31:07 +00004849 // Transform the size of the array we're allocating (if any).
4850 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
4851 if (ArraySize.isInvalid())
4852 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 // Transform the placement arguments (if any).
4855 bool ArgumentChanged = false;
4856 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
4857 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
4858 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
4859 if (Arg.isInvalid())
4860 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004861
Douglas Gregora16548e2009-08-11 05:31:07 +00004862 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
4863 PlacementArgs.push_back(Arg.take());
4864 }
Mike Stump11289f42009-09-09 15:08:12 +00004865
Douglas Gregorebe10102009-08-20 07:17:43 +00004866 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00004867 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
4868 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
4869 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
4870 if (Arg.isInvalid())
4871 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004872
Douglas Gregora16548e2009-08-11 05:31:07 +00004873 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
4874 ConstructorArgs.push_back(Arg.take());
4875 }
Mike Stump11289f42009-09-09 15:08:12 +00004876
Douglas Gregord2d9da02010-02-26 00:38:10 +00004877 // Transform constructor, new operator, and delete operator.
4878 CXXConstructorDecl *Constructor = 0;
4879 if (E->getConstructor()) {
4880 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004881 getDerived().TransformDecl(E->getLocStart(),
4882 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004883 if (!Constructor)
4884 return SemaRef.ExprError();
4885 }
4886
4887 FunctionDecl *OperatorNew = 0;
4888 if (E->getOperatorNew()) {
4889 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004890 getDerived().TransformDecl(E->getLocStart(),
4891 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004892 if (!OperatorNew)
4893 return SemaRef.ExprError();
4894 }
4895
4896 FunctionDecl *OperatorDelete = 0;
4897 if (E->getOperatorDelete()) {
4898 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004899 getDerived().TransformDecl(E->getLocStart(),
4900 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004901 if (!OperatorDelete)
4902 return SemaRef.ExprError();
4903 }
4904
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 if (!getDerived().AlwaysRebuild() &&
4906 AllocType == E->getAllocatedType() &&
4907 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004908 Constructor == E->getConstructor() &&
4909 OperatorNew == E->getOperatorNew() &&
4910 OperatorDelete == E->getOperatorDelete() &&
4911 !ArgumentChanged) {
4912 // Mark any declarations we need as referenced.
4913 // FIXME: instantiation-specific.
4914 if (Constructor)
4915 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
4916 if (OperatorNew)
4917 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
4918 if (OperatorDelete)
4919 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004920 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004921 }
Mike Stump11289f42009-09-09 15:08:12 +00004922
Douglas Gregor2e9c7952009-12-22 17:13:37 +00004923 if (!ArraySize.get()) {
4924 // If no array size was specified, but the new expression was
4925 // instantiated with an array type (e.g., "new T" where T is
4926 // instantiated with "int[4]"), extract the outer bound from the
4927 // array type as our array size. We do this with constant and
4928 // dependently-sized array types.
4929 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
4930 if (!ArrayT) {
4931 // Do nothing
4932 } else if (const ConstantArrayType *ConsArrayT
4933 = dyn_cast<ConstantArrayType>(ArrayT)) {
4934 ArraySize
4935 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
4936 ConsArrayT->getSize(),
4937 SemaRef.Context.getSizeType(),
4938 /*FIXME:*/E->getLocStart()));
4939 AllocType = ConsArrayT->getElementType();
4940 } else if (const DependentSizedArrayType *DepArrayT
4941 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
4942 if (DepArrayT->getSizeExpr()) {
4943 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
4944 AllocType = DepArrayT->getElementType();
4945 }
4946 }
4947 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
4949 E->isGlobalNew(),
4950 /*FIXME:*/E->getLocStart(),
4951 move_arg(PlacementArgs),
4952 /*FIXME:*/E->getLocStart(),
4953 E->isParenTypeId(),
4954 AllocType,
4955 /*FIXME:*/E->getLocStart(),
4956 /*FIXME:*/SourceRange(),
4957 move(ArraySize),
4958 /*FIXME:*/E->getLocStart(),
4959 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00004960 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00004961}
Mike Stump11289f42009-09-09 15:08:12 +00004962
Douglas Gregora16548e2009-08-11 05:31:07 +00004963template<typename Derived>
4964Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004965TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
4967 if (Operand.isInvalid())
4968 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004969
Douglas Gregord2d9da02010-02-26 00:38:10 +00004970 // Transform the delete operator, if known.
4971 FunctionDecl *OperatorDelete = 0;
4972 if (E->getOperatorDelete()) {
4973 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004974 getDerived().TransformDecl(E->getLocStart(),
4975 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00004976 if (!OperatorDelete)
4977 return SemaRef.ExprError();
4978 }
4979
Douglas Gregora16548e2009-08-11 05:31:07 +00004980 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00004981 Operand.get() == E->getArgument() &&
4982 OperatorDelete == E->getOperatorDelete()) {
4983 // Mark any declarations we need as referenced.
4984 // FIXME: instantiation-specific.
4985 if (OperatorDelete)
4986 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00004987 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00004988 }
Mike Stump11289f42009-09-09 15:08:12 +00004989
Douglas Gregora16548e2009-08-11 05:31:07 +00004990 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
4991 E->isGlobalDelete(),
4992 E->isArrayForm(),
4993 move(Operand));
4994}
Mike Stump11289f42009-09-09 15:08:12 +00004995
Douglas Gregora16548e2009-08-11 05:31:07 +00004996template<typename Derived>
4997Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00004998TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004999 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005000 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5001 if (Base.isInvalid())
5002 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregor678f90d2010-02-25 01:56:36 +00005004 Sema::TypeTy *ObjectTypePtr = 0;
5005 bool MayBePseudoDestructor = false;
5006 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5007 E->getOperatorLoc(),
5008 E->isArrow()? tok::arrow : tok::period,
5009 ObjectTypePtr,
5010 MayBePseudoDestructor);
5011 if (Base.isInvalid())
5012 return SemaRef.ExprError();
5013
5014 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005015 NestedNameSpecifier *Qualifier
5016 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005017 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005018 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005019 if (E->getQualifier() && !Qualifier)
5020 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005021
Douglas Gregor678f90d2010-02-25 01:56:36 +00005022 PseudoDestructorTypeStorage Destroyed;
5023 if (E->getDestroyedTypeInfo()) {
5024 TypeSourceInfo *DestroyedTypeInfo
5025 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5026 if (!DestroyedTypeInfo)
5027 return SemaRef.ExprError();
5028 Destroyed = DestroyedTypeInfo;
5029 } else if (ObjectType->isDependentType()) {
5030 // We aren't likely to be able to resolve the identifier down to a type
5031 // now anyway, so just retain the identifier.
5032 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5033 E->getDestroyedTypeLoc());
5034 } else {
5035 // Look for a destructor known with the given name.
5036 CXXScopeSpec SS;
5037 if (Qualifier) {
5038 SS.setScopeRep(Qualifier);
5039 SS.setRange(E->getQualifierRange());
5040 }
5041
5042 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5043 *E->getDestroyedTypeIdentifier(),
5044 E->getDestroyedTypeLoc(),
5045 /*Scope=*/0,
5046 SS, ObjectTypePtr,
5047 false);
5048 if (!T)
5049 return SemaRef.ExprError();
5050
5051 Destroyed
5052 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5053 E->getDestroyedTypeLoc());
5054 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005055
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005056 TypeSourceInfo *ScopeTypeInfo = 0;
5057 if (E->getScopeTypeInfo()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00005058 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
5059 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005060 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005061 return SemaRef.ExprError();
5062 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005063
Douglas Gregorad8a3362009-09-04 17:36:40 +00005064 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5065 E->getOperatorLoc(),
5066 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005067 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005068 E->getQualifierRange(),
5069 ScopeTypeInfo,
5070 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005071 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005072 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregorad8a3362009-09-04 17:36:40 +00005075template<typename Derived>
5076Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005077TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005078 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005079 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5080
5081 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5082 Sema::LookupOrdinaryName);
5083
5084 // Transform all the decls.
5085 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5086 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005087 NamedDecl *InstD = static_cast<NamedDecl*>(
5088 getDerived().TransformDecl(Old->getNameLoc(),
5089 *I));
John McCall84d87672009-12-10 09:41:52 +00005090 if (!InstD) {
5091 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5092 // This can happen because of dependent hiding.
5093 if (isa<UsingShadowDecl>(*I))
5094 continue;
5095 else
5096 return SemaRef.ExprError();
5097 }
John McCalle66edc12009-11-24 19:00:30 +00005098
5099 // Expand using declarations.
5100 if (isa<UsingDecl>(InstD)) {
5101 UsingDecl *UD = cast<UsingDecl>(InstD);
5102 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5103 E = UD->shadow_end(); I != E; ++I)
5104 R.addDecl(*I);
5105 continue;
5106 }
5107
5108 R.addDecl(InstD);
5109 }
5110
5111 // Resolve a kind, but don't do any further analysis. If it's
5112 // ambiguous, the callee needs to deal with it.
5113 R.resolveKind();
5114
5115 // Rebuild the nested-name qualifier, if present.
5116 CXXScopeSpec SS;
5117 NestedNameSpecifier *Qualifier = 0;
5118 if (Old->getQualifier()) {
5119 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005120 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005121 if (!Qualifier)
5122 return SemaRef.ExprError();
5123
5124 SS.setScopeRep(Qualifier);
5125 SS.setRange(Old->getQualifierRange());
5126 }
5127
5128 // If we have no template arguments, it's a normal declaration name.
5129 if (!Old->hasExplicitTemplateArgs())
5130 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5131
5132 // If we have template arguments, rebuild them, then rebuild the
5133 // templateid expression.
5134 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5135 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5136 TemplateArgumentLoc Loc;
5137 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5138 return SemaRef.ExprError();
5139 TransArgs.addArgument(Loc);
5140 }
5141
5142 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5143 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005144}
Mike Stump11289f42009-09-09 15:08:12 +00005145
Douglas Gregora16548e2009-08-11 05:31:07 +00005146template<typename Derived>
5147Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005148TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 QualType T = getDerived().TransformType(E->getQueriedType());
5152 if (T.isNull())
5153 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 if (!getDerived().AlwaysRebuild() &&
5156 T == E->getQueriedType())
5157 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 // FIXME: Bad location information
5160 SourceLocation FakeLParenLoc
5161 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005162
5163 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 E->getLocStart(),
5165 /*FIXME:*/FakeLParenLoc,
5166 T,
5167 E->getLocEnd());
5168}
Mike Stump11289f42009-09-09 15:08:12 +00005169
Douglas Gregora16548e2009-08-11 05:31:07 +00005170template<typename Derived>
5171Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005172TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005173 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005174 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005175 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005176 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 if (!NNS)
5178 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005179
5180 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005181 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5182 if (!Name)
5183 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005184
John McCalle66edc12009-11-24 19:00:30 +00005185 if (!E->hasExplicitTemplateArgs()) {
5186 if (!getDerived().AlwaysRebuild() &&
5187 NNS == E->getQualifier() &&
5188 Name == E->getDeclName())
5189 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005190
John McCalle66edc12009-11-24 19:00:30 +00005191 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5192 E->getQualifierRange(),
5193 Name, E->getLocation(),
5194 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005195 }
John McCall6b51f282009-11-23 01:53:49 +00005196
5197 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005198 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005199 TemplateArgumentLoc Loc;
5200 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005202 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005203 }
5204
John McCalle66edc12009-11-24 19:00:30 +00005205 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5206 E->getQualifierRange(),
5207 Name, E->getLocation(),
5208 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005209}
5210
5211template<typename Derived>
5212Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005213TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005214 // CXXConstructExprs are always implicit, so when we have a
5215 // 1-argument construction we just transform that argument.
5216 if (E->getNumArgs() == 1 ||
5217 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5218 return getDerived().TransformExpr(E->getArg(0));
5219
Douglas Gregora16548e2009-08-11 05:31:07 +00005220 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5221
5222 QualType T = getDerived().TransformType(E->getType());
5223 if (T.isNull())
5224 return SemaRef.ExprError();
5225
5226 CXXConstructorDecl *Constructor
5227 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005228 getDerived().TransformDecl(E->getLocStart(),
5229 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005230 if (!Constructor)
5231 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233 bool ArgumentChanged = false;
5234 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005235 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005236 ArgEnd = E->arg_end();
5237 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005238 if (getDerived().DropCallArgument(*Arg)) {
5239 ArgumentChanged = true;
5240 break;
5241 }
5242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5244 if (TransArg.isInvalid())
5245 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5248 Args.push_back(TransArg.takeAs<Expr>());
5249 }
5250
5251 if (!getDerived().AlwaysRebuild() &&
5252 T == E->getType() &&
5253 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005254 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005255 // Mark the constructor as referenced.
5256 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005257 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005259 }
Mike Stump11289f42009-09-09 15:08:12 +00005260
Douglas Gregordb121ba2009-12-14 16:27:04 +00005261 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5262 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005263 move_arg(Args));
5264}
Mike Stump11289f42009-09-09 15:08:12 +00005265
Douglas Gregora16548e2009-08-11 05:31:07 +00005266/// \brief Transform a C++ temporary-binding expression.
5267///
Douglas Gregor363b1512009-12-24 18:51:59 +00005268/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5269/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005270template<typename Derived>
5271Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005272TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005273 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005274}
Mike Stump11289f42009-09-09 15:08:12 +00005275
Anders Carlssonba6c4372010-01-29 02:39:32 +00005276/// \brief Transform a C++ reference-binding expression.
5277///
5278/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5279/// transform the subexpression and return that.
5280template<typename Derived>
5281Sema::OwningExprResult
5282TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5283 return getDerived().TransformExpr(E->getSubExpr());
5284}
5285
Mike Stump11289f42009-09-09 15:08:12 +00005286/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005287/// be destroyed after the expression is evaluated.
5288///
Douglas Gregor363b1512009-12-24 18:51:59 +00005289/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5290/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005291template<typename Derived>
5292Sema::OwningExprResult
5293TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005294 CXXExprWithTemporaries *E) {
5295 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005296}
Mike Stump11289f42009-09-09 15:08:12 +00005297
Douglas Gregora16548e2009-08-11 05:31:07 +00005298template<typename Derived>
5299Sema::OwningExprResult
5300TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005301 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005302 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5303 QualType T = getDerived().TransformType(E->getType());
5304 if (T.isNull())
5305 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005306
Douglas Gregora16548e2009-08-11 05:31:07 +00005307 CXXConstructorDecl *Constructor
5308 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005309 getDerived().TransformDecl(E->getLocStart(),
5310 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005311 if (!Constructor)
5312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregora16548e2009-08-11 05:31:07 +00005314 bool ArgumentChanged = false;
5315 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5316 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005317 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005318 ArgEnd = E->arg_end();
5319 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005320 if (getDerived().DropCallArgument(*Arg)) {
5321 ArgumentChanged = true;
5322 break;
5323 }
5324
Douglas Gregora16548e2009-08-11 05:31:07 +00005325 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5326 if (TransArg.isInvalid())
5327 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregora16548e2009-08-11 05:31:07 +00005329 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5330 Args.push_back((Expr *)TransArg.release());
5331 }
Mike Stump11289f42009-09-09 15:08:12 +00005332
Douglas Gregora16548e2009-08-11 05:31:07 +00005333 if (!getDerived().AlwaysRebuild() &&
5334 T == E->getType() &&
5335 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005336 !ArgumentChanged) {
5337 // FIXME: Instantiation-specific
5338 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005339 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005340 }
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregora16548e2009-08-11 05:31:07 +00005342 // FIXME: Bogus location information
5343 SourceLocation CommaLoc;
5344 if (Args.size() > 1) {
5345 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005346 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005347 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5348 }
5349 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5350 T,
5351 /*FIXME:*/E->getTypeBeginLoc(),
5352 move_arg(Args),
5353 &CommaLoc,
5354 E->getLocEnd());
5355}
Mike Stump11289f42009-09-09 15:08:12 +00005356
Douglas Gregora16548e2009-08-11 05:31:07 +00005357template<typename Derived>
5358Sema::OwningExprResult
5359TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005360 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005361 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5362 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5363 if (T.isNull())
5364 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005365
Douglas Gregora16548e2009-08-11 05:31:07 +00005366 bool ArgumentChanged = false;
5367 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5368 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5369 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5370 ArgEnd = E->arg_end();
5371 Arg != ArgEnd; ++Arg) {
5372 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5373 if (TransArg.isInvalid())
5374 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregora16548e2009-08-11 05:31:07 +00005376 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5377 FakeCommaLocs.push_back(
5378 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5379 Args.push_back(TransArg.takeAs<Expr>());
5380 }
Mike Stump11289f42009-09-09 15:08:12 +00005381
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 if (!getDerived().AlwaysRebuild() &&
5383 T == E->getTypeAsWritten() &&
5384 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005385 return SemaRef.Owned(E->Retain());
5386
Douglas Gregora16548e2009-08-11 05:31:07 +00005387 // FIXME: we're faking the locations of the commas
5388 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5389 T,
5390 E->getLParenLoc(),
5391 move_arg(Args),
5392 FakeCommaLocs.data(),
5393 E->getRParenLoc());
5394}
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396template<typename Derived>
5397Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005398TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005399 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005400 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005401 OwningExprResult Base(SemaRef, (Expr*) 0);
5402 Expr *OldBase;
5403 QualType BaseType;
5404 QualType ObjectType;
5405 if (!E->isImplicitAccess()) {
5406 OldBase = E->getBase();
5407 Base = getDerived().TransformExpr(OldBase);
5408 if (Base.isInvalid())
5409 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005410
John McCall2d74de92009-12-01 22:10:20 +00005411 // Start the member reference and compute the object's type.
5412 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005413 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005414 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5415 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005416 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005417 ObjectTy,
5418 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005419 if (Base.isInvalid())
5420 return SemaRef.ExprError();
5421
5422 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5423 BaseType = ((Expr*) Base.get())->getType();
5424 } else {
5425 OldBase = 0;
5426 BaseType = getDerived().TransformType(E->getBaseType());
5427 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5428 }
Mike Stump11289f42009-09-09 15:08:12 +00005429
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005430 // Transform the first part of the nested-name-specifier that qualifies
5431 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005432 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005433 = getDerived().TransformFirstQualifierInScope(
5434 E->getFirstQualifierFoundInScope(),
5435 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005436
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005437 NestedNameSpecifier *Qualifier = 0;
5438 if (E->getQualifier()) {
5439 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5440 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005441 ObjectType,
5442 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005443 if (!Qualifier)
5444 return SemaRef.ExprError();
5445 }
Mike Stump11289f42009-09-09 15:08:12 +00005446
5447 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005448 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005449 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005450 if (!Name)
5451 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005452
John McCall2d74de92009-12-01 22:10:20 +00005453 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005454 // This is a reference to a member without an explicitly-specified
5455 // template argument list. Optimize for this common case.
5456 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005457 Base.get() == OldBase &&
5458 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005459 Qualifier == E->getQualifier() &&
5460 Name == E->getMember() &&
5461 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005462 return SemaRef.Owned(E->Retain());
5463
John McCall8cd78132009-11-19 22:55:06 +00005464 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005465 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005466 E->isArrow(),
5467 E->getOperatorLoc(),
5468 Qualifier,
5469 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005470 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005471 Name,
5472 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005473 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005474 }
5475
John McCall6b51f282009-11-23 01:53:49 +00005476 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005477 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005478 TemplateArgumentLoc Loc;
5479 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005480 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005481 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005482 }
Mike Stump11289f42009-09-09 15:08:12 +00005483
John McCall8cd78132009-11-19 22:55:06 +00005484 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005485 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005486 E->isArrow(),
5487 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005488 Qualifier,
5489 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005490 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005491 Name,
5492 E->getMemberLoc(),
5493 &TransArgs);
5494}
5495
5496template<typename Derived>
5497Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005498TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005499 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005500 OwningExprResult Base(SemaRef, (Expr*) 0);
5501 QualType BaseType;
5502 if (!Old->isImplicitAccess()) {
5503 Base = getDerived().TransformExpr(Old->getBase());
5504 if (Base.isInvalid())
5505 return SemaRef.ExprError();
5506 BaseType = ((Expr*) Base.get())->getType();
5507 } else {
5508 BaseType = getDerived().TransformType(Old->getBaseType());
5509 }
John McCall10eae182009-11-30 22:42:35 +00005510
5511 NestedNameSpecifier *Qualifier = 0;
5512 if (Old->getQualifier()) {
5513 Qualifier
5514 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005515 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005516 if (Qualifier == 0)
5517 return SemaRef.ExprError();
5518 }
5519
5520 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5521 Sema::LookupOrdinaryName);
5522
5523 // Transform all the decls.
5524 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5525 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005526 NamedDecl *InstD = static_cast<NamedDecl*>(
5527 getDerived().TransformDecl(Old->getMemberLoc(),
5528 *I));
John McCall84d87672009-12-10 09:41:52 +00005529 if (!InstD) {
5530 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5531 // This can happen because of dependent hiding.
5532 if (isa<UsingShadowDecl>(*I))
5533 continue;
5534 else
5535 return SemaRef.ExprError();
5536 }
John McCall10eae182009-11-30 22:42:35 +00005537
5538 // Expand using declarations.
5539 if (isa<UsingDecl>(InstD)) {
5540 UsingDecl *UD = cast<UsingDecl>(InstD);
5541 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5542 E = UD->shadow_end(); I != E; ++I)
5543 R.addDecl(*I);
5544 continue;
5545 }
5546
5547 R.addDecl(InstD);
5548 }
5549
5550 R.resolveKind();
5551
5552 TemplateArgumentListInfo TransArgs;
5553 if (Old->hasExplicitTemplateArgs()) {
5554 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5555 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5556 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5557 TemplateArgumentLoc Loc;
5558 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5559 Loc))
5560 return SemaRef.ExprError();
5561 TransArgs.addArgument(Loc);
5562 }
5563 }
John McCall38836f02010-01-15 08:34:02 +00005564
5565 // FIXME: to do this check properly, we will need to preserve the
5566 // first-qualifier-in-scope here, just in case we had a dependent
5567 // base (and therefore couldn't do the check) and a
5568 // nested-name-qualifier (and therefore could do the lookup).
5569 NamedDecl *FirstQualifierInScope = 0;
John McCall10eae182009-11-30 22:42:35 +00005570
5571 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005572 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005573 Old->getOperatorLoc(),
5574 Old->isArrow(),
5575 Qualifier,
5576 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005577 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005578 R,
5579 (Old->hasExplicitTemplateArgs()
5580 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005581}
5582
5583template<typename Derived>
5584Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005585TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005586 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005587}
5588
Mike Stump11289f42009-09-09 15:08:12 +00005589template<typename Derived>
5590Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005591TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005592 TypeSourceInfo *EncodedTypeInfo
5593 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5594 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
Douglas Gregora16548e2009-08-11 05:31:07 +00005597 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005598 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005599 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005600
5601 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005602 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 E->getRParenLoc());
5604}
Mike Stump11289f42009-09-09 15:08:12 +00005605
Douglas Gregora16548e2009-08-11 05:31:07 +00005606template<typename Derived>
5607Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005608TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005609 // Transform arguments.
5610 bool ArgChanged = false;
5611 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5612 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5613 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5614 if (Arg.isInvalid())
5615 return SemaRef.ExprError();
5616
5617 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5618 Args.push_back(Arg.takeAs<Expr>());
5619 }
5620
5621 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5622 // Class message: transform the receiver type.
5623 TypeSourceInfo *ReceiverTypeInfo
5624 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5625 if (!ReceiverTypeInfo)
5626 return SemaRef.ExprError();
5627
5628 // If nothing changed, just retain the existing message send.
5629 if (!getDerived().AlwaysRebuild() &&
5630 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5631 return SemaRef.Owned(E->Retain());
5632
5633 // Build a new class message send.
5634 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5635 E->getSelector(),
5636 E->getMethodDecl(),
5637 E->getLeftLoc(),
5638 move_arg(Args),
5639 E->getRightLoc());
5640 }
5641
5642 // Instance message: transform the receiver
5643 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5644 "Only class and instance messages may be instantiated");
5645 OwningExprResult Receiver
5646 = getDerived().TransformExpr(E->getInstanceReceiver());
5647 if (Receiver.isInvalid())
5648 return SemaRef.ExprError();
5649
5650 // If nothing changed, just retain the existing message send.
5651 if (!getDerived().AlwaysRebuild() &&
5652 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5653 return SemaRef.Owned(E->Retain());
5654
5655 // Build a new instance message send.
5656 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5657 E->getSelector(),
5658 E->getMethodDecl(),
5659 E->getLeftLoc(),
5660 move_arg(Args),
5661 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005662}
5663
Mike Stump11289f42009-09-09 15:08:12 +00005664template<typename Derived>
5665Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005666TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005667 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005668}
5669
Mike Stump11289f42009-09-09 15:08:12 +00005670template<typename Derived>
5671Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005672TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005673 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005674}
5675
Mike Stump11289f42009-09-09 15:08:12 +00005676template<typename Derived>
5677Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005678TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 // FIXME: Implement this!
5680 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005681 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005682}
5683
Mike Stump11289f42009-09-09 15:08:12 +00005684template<typename Derived>
5685Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005686TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 // FIXME: Implement this!
5688 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005689 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005690}
5691
Mike Stump11289f42009-09-09 15:08:12 +00005692template<typename Derived>
5693Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00005694TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005695 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005696 // FIXME: Implement this!
5697 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005698 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699}
5700
Mike Stump11289f42009-09-09 15:08:12 +00005701template<typename Derived>
5702Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005703TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005704 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00005705 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005706}
5707
Mike Stump11289f42009-09-09 15:08:12 +00005708template<typename Derived>
5709Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005710TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005711 // FIXME: Implement this!
5712 assert(false && "Cannot transform Objective-C expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005713 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005714}
5715
Mike Stump11289f42009-09-09 15:08:12 +00005716template<typename Derived>
5717Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005718TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 bool ArgumentChanged = false;
5720 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
5721 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
5722 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
5723 if (SubExpr.isInvalid())
5724 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
Douglas Gregora16548e2009-08-11 05:31:07 +00005726 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
5727 SubExprs.push_back(SubExpr.takeAs<Expr>());
5728 }
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (!getDerived().AlwaysRebuild() &&
5731 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005732 return SemaRef.Owned(E->Retain());
5733
Douglas Gregora16548e2009-08-11 05:31:07 +00005734 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
5735 move_arg(SubExprs),
5736 E->getRParenLoc());
5737}
5738
Mike Stump11289f42009-09-09 15:08:12 +00005739template<typename Derived>
5740Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 // FIXME: Implement this!
5743 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005744 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005745}
5746
Mike Stump11289f42009-09-09 15:08:12 +00005747template<typename Derived>
5748Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005749TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 // FIXME: Implement this!
5751 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00005752 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005753}
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora16548e2009-08-11 05:31:07 +00005755//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00005756// Type reconstruction
5757//===----------------------------------------------------------------------===//
5758
Mike Stump11289f42009-09-09 15:08:12 +00005759template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005760QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
5761 SourceLocation Star) {
5762 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005763 getDerived().getBaseEntity());
5764}
5765
Mike Stump11289f42009-09-09 15:08:12 +00005766template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00005767QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
5768 SourceLocation Star) {
5769 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005770 getDerived().getBaseEntity());
5771}
5772
Mike Stump11289f42009-09-09 15:08:12 +00005773template<typename Derived>
5774QualType
John McCall70dd5f62009-10-30 00:06:24 +00005775TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
5776 bool WrittenAsLValue,
5777 SourceLocation Sigil) {
5778 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
5779 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005780}
5781
5782template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005783QualType
John McCall70dd5f62009-10-30 00:06:24 +00005784TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
5785 QualType ClassType,
5786 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00005787 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00005788 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005789}
5790
5791template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005792QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00005793TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
5794 ArrayType::ArraySizeModifier SizeMod,
5795 const llvm::APInt *Size,
5796 Expr *SizeExpr,
5797 unsigned IndexTypeQuals,
5798 SourceRange BracketsRange) {
5799 if (SizeExpr || !Size)
5800 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
5801 IndexTypeQuals, BracketsRange,
5802 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00005803
5804 QualType Types[] = {
5805 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
5806 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
5807 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00005808 };
5809 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
5810 QualType SizeType;
5811 for (unsigned I = 0; I != NumTypes; ++I)
5812 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
5813 SizeType = Types[I];
5814 break;
5815 }
Mike Stump11289f42009-09-09 15:08:12 +00005816
Douglas Gregord6ff3322009-08-04 16:50:30 +00005817 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005818 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005819 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00005820 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005821}
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregord6ff3322009-08-04 16:50:30 +00005823template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005824QualType
5825TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005826 ArrayType::ArraySizeModifier SizeMod,
5827 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00005828 unsigned IndexTypeQuals,
5829 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005830 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005831 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005832}
5833
5834template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005835QualType
Mike Stump11289f42009-09-09 15:08:12 +00005836TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005837 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00005838 unsigned IndexTypeQuals,
5839 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005840 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00005841 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005842}
Mike Stump11289f42009-09-09 15:08:12 +00005843
Douglas Gregord6ff3322009-08-04 16:50:30 +00005844template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005845QualType
5846TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005847 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005848 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005849 unsigned IndexTypeQuals,
5850 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005851 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005852 SizeExpr.takeAs<Expr>(),
5853 IndexTypeQuals, BracketsRange);
5854}
5855
5856template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005857QualType
5858TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005859 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00005860 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005861 unsigned IndexTypeQuals,
5862 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00005863 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005864 SizeExpr.takeAs<Expr>(),
5865 IndexTypeQuals, BracketsRange);
5866}
5867
5868template<typename Derived>
5869QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00005870 unsigned NumElements,
5871 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005872 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00005873 return SemaRef.Context.getVectorType(ElementType, NumElements,
5874 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005875}
Mike Stump11289f42009-09-09 15:08:12 +00005876
Douglas Gregord6ff3322009-08-04 16:50:30 +00005877template<typename Derived>
5878QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
5879 unsigned NumElements,
5880 SourceLocation AttributeLoc) {
5881 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
5882 NumElements, true);
5883 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00005884 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005885 AttributeLoc);
5886 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
5887 AttributeLoc);
5888}
Mike Stump11289f42009-09-09 15:08:12 +00005889
Douglas Gregord6ff3322009-08-04 16:50:30 +00005890template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005891QualType
5892TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005893 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005894 SourceLocation AttributeLoc) {
5895 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
5896}
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregord6ff3322009-08-04 16:50:30 +00005898template<typename Derived>
5899QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00005900 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005901 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00005902 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005903 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00005904 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00005905 Quals,
5906 getDerived().getBaseLocation(),
5907 getDerived().getBaseEntity());
5908}
Mike Stump11289f42009-09-09 15:08:12 +00005909
Douglas Gregord6ff3322009-08-04 16:50:30 +00005910template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005911QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
5912 return SemaRef.Context.getFunctionNoProtoType(T);
5913}
5914
5915template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00005916QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
5917 assert(D && "no decl found");
5918 if (D->isInvalidDecl()) return QualType();
5919
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005920 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00005921 TypeDecl *Ty;
5922 if (isa<UsingDecl>(D)) {
5923 UsingDecl *Using = cast<UsingDecl>(D);
5924 assert(Using->isTypeName() &&
5925 "UnresolvedUsingTypenameDecl transformed to non-typename using");
5926
5927 // A valid resolved using typename decl points to exactly one type decl.
5928 assert(++Using->shadow_begin() == Using->shadow_end());
5929 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
5930
5931 } else {
5932 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
5933 "UnresolvedUsingTypenameDecl transformed to non-using decl");
5934 Ty = cast<UnresolvedUsingTypenameDecl>(D);
5935 }
5936
5937 return SemaRef.Context.getTypeDeclType(Ty);
5938}
5939
5940template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005941QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005942 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
5943}
5944
5945template<typename Derived>
5946QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
5947 return SemaRef.Context.getTypeOfType(Underlying);
5948}
5949
5950template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00005951QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00005952 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
5953}
5954
5955template<typename Derived>
5956QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005957 TemplateName Template,
5958 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00005959 const TemplateArgumentListInfo &TemplateArgs) {
5960 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005961}
Mike Stump11289f42009-09-09 15:08:12 +00005962
Douglas Gregor1135c352009-08-06 05:28:30 +00005963template<typename Derived>
5964NestedNameSpecifier *
5965TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5966 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005967 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005968 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00005969 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00005970 CXXScopeSpec SS;
5971 // FIXME: The source location information is all wrong.
5972 SS.setRange(Range);
5973 SS.setScopeRep(Prefix);
5974 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00005975 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00005976 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005977 ObjectType,
5978 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00005979 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00005980}
5981
5982template<typename Derived>
5983NestedNameSpecifier *
5984TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5985 SourceRange Range,
5986 NamespaceDecl *NS) {
5987 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
5988}
5989
5990template<typename Derived>
5991NestedNameSpecifier *
5992TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
5993 SourceRange Range,
5994 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005995 QualType T) {
5996 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00005997 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00005998 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00005999 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6000 T.getTypePtr());
6001 }
Mike Stump11289f42009-09-09 15:08:12 +00006002
Douglas Gregor1135c352009-08-06 05:28:30 +00006003 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6004 return 0;
6005}
Mike Stump11289f42009-09-09 15:08:12 +00006006
Douglas Gregor71dc5092009-08-06 06:41:21 +00006007template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006008TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006009TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6010 bool TemplateKW,
6011 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006012 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006013 Template);
6014}
6015
6016template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006017TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006018TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006019 const IdentifierInfo &II,
6020 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006021 CXXScopeSpec SS;
6022 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006023 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006024 UnqualifiedId Name;
6025 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006026 return getSema().ActOnDependentTemplateName(
6027 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006028 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006029 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006030 ObjectType.getAsOpaquePtr(),
6031 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006032 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006036TemplateName
6037TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6038 OverloadedOperatorKind Operator,
6039 QualType ObjectType) {
6040 CXXScopeSpec SS;
6041 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6042 SS.setScopeRep(Qualifier);
6043 UnqualifiedId Name;
6044 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6045 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6046 Operator, SymbolLocations);
6047 return getSema().ActOnDependentTemplateName(
6048 /*FIXME:*/getDerived().getBaseLocation(),
6049 SS,
6050 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006051 ObjectType.getAsOpaquePtr(),
6052 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006053 .template getAsVal<TemplateName>();
6054}
6055
6056template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006057Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006058TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6059 SourceLocation OpLoc,
6060 ExprArg Callee,
6061 ExprArg First,
6062 ExprArg Second) {
6063 Expr *FirstExpr = (Expr *)First.get();
6064 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006065 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006066 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006069 if (Op == OO_Subscript) {
6070 if (!FirstExpr->getType()->isOverloadableType() &&
6071 !SecondExpr->getType()->isOverloadableType())
6072 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006073 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006074 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006075 } else if (Op == OO_Arrow) {
6076 // -> is never a builtin operation.
6077 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006078 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006079 if (!FirstExpr->getType()->isOverloadableType()) {
6080 // The argument is not of overloadable type, so try to create a
6081 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006082 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006083 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006084
Douglas Gregora16548e2009-08-11 05:31:07 +00006085 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6086 }
6087 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006088 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 !SecondExpr->getType()->isOverloadableType()) {
6090 // Neither of the arguments is an overloadable type, so try to
6091 // create a built-in binary operation.
6092 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006093 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006094 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6095 if (Result.isInvalid())
6096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006097
Douglas Gregora16548e2009-08-11 05:31:07 +00006098 First.release();
6099 Second.release();
6100 return move(Result);
6101 }
6102 }
Mike Stump11289f42009-09-09 15:08:12 +00006103
6104 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006106 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006107
John McCalld14a8642009-11-21 08:51:07 +00006108 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6109 assert(ULE->requiresADL());
6110
6111 // FIXME: Do we have to check
6112 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006113 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006114 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006115 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006116 }
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregora16548e2009-08-11 05:31:07 +00006118 // Add any functions found via argument-dependent lookup.
6119 Expr *Args[2] = { FirstExpr, SecondExpr };
6120 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006121
Douglas Gregora16548e2009-08-11 05:31:07 +00006122 // Create the overloaded operator invocation for unary operators.
6123 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006124 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006125 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6126 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6127 }
Mike Stump11289f42009-09-09 15:08:12 +00006128
Sebastian Redladba46e2009-10-29 20:17:01 +00006129 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006130 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6131 OpLoc,
6132 move(First),
6133 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006134
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006136 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006138 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6140 if (Result.isInvalid())
6141 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006142
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 First.release();
6144 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006145 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006146}
Mike Stump11289f42009-09-09 15:08:12 +00006147
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006148template<typename Derived>
6149Sema::OwningExprResult
6150TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6151 SourceLocation OperatorLoc,
6152 bool isArrow,
6153 NestedNameSpecifier *Qualifier,
6154 SourceRange QualifierRange,
6155 TypeSourceInfo *ScopeType,
6156 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006157 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006158 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006159 CXXScopeSpec SS;
6160 if (Qualifier) {
6161 SS.setRange(QualifierRange);
6162 SS.setScopeRep(Qualifier);
6163 }
6164
6165 Expr *BaseE = (Expr *)Base.get();
6166 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006167 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006168 (!isArrow && !BaseType->getAs<RecordType>()) ||
6169 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006170 !BaseType->getAs<PointerType>()->getPointeeType()
6171 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006172 // This pseudo-destructor expression is still a pseudo-destructor.
6173 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6174 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006175 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006176 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006177 /*FIXME?*/true);
6178 }
6179
Douglas Gregor678f90d2010-02-25 01:56:36 +00006180 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006181 DeclarationName Name
6182 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6183 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
6184
6185 // FIXME: the ScopeType should be tacked onto SS.
6186
6187 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6188 OperatorLoc, isArrow,
6189 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006190 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006191 /*TemplateArgs*/ 0);
6192}
6193
Douglas Gregord6ff3322009-08-04 16:50:30 +00006194} // end namespace clang
6195
6196#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H