blob: 35152617336ac2d48c7db13958cf39393914526b [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;
Alexis Hunta8136cc2010-05-05 15:23:54 +000099
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 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000184
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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000204 TypeSourceInfo *TransformType(TypeSourceInfo *DI,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000205 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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000211 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000212 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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000246 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
247 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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000253 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000254 /// 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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000259 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
260 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000261 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000262
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
Alexis Hunta8136cc2010-05-05 15:23:54 +0000333 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +0000334 QualType ObjectType);
John McCall70dd5f62009-10-30 00:06:24 +0000335
Alexis Hunta8136cc2010-05-05 15:23:54 +0000336 QualType
Douglas Gregorc59e5612009-10-19 22:04:39 +0000337 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);
Alexis Hunt656bb312010-05-05 15:24:00 +0000347#define ABSTRACT(Stmt)
348#include "clang/AST/StmtNodes.inc"
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
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000533 /// By default, builds a new DependentNameType type from the
Douglas Gregore677daf2010-03-31 22:19:08 +0000534 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000535 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000536 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000537 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000539 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000540 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000541 CXXScopeSpec SS;
542 SS.setScopeRep(NNS);
543 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000544 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000545 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000546 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000547
548 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000549 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550
551 /// \brief Build a new typename type that refers to an identifier.
552 ///
553 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000554 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555 /// different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000556 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000557 NestedNameSpecifier *NNS,
558 const IdentifierInfo *Id,
559 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000560 CXXScopeSpec SS;
561 SS.setScopeRep(NNS);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000562
Douglas Gregore677daf2010-03-31 22:19:08 +0000563 if (NNS->isDependent()) {
564 // If the name is still dependent, just build a new dependent name type.
565 if (!SemaRef.computeDeclContext(SS))
566 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
567 }
568
Abramo Bagnara6150c882010-05-11 21:36:43 +0000569 if (Keyword == ETK_None || Keyword == ETK_Typename)
570 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
571
572 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
573
Douglas Gregore677daf2010-03-31 22:19:08 +0000574 // We had a dependent elaborated-type-specifier that as been transformed
575 // into a non-dependent elaborated-type-specifier. Find the tag we're
576 // referring to.
577 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
578 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
579 if (!DC)
580 return QualType();
581
582 TagDecl *Tag = 0;
583 SemaRef.LookupQualifiedName(Result, DC);
584 switch (Result.getResultKind()) {
585 case LookupResult::NotFound:
586 case LookupResult::NotFoundInCurrentInstantiation:
587 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000588
Douglas Gregore677daf2010-03-31 22:19:08 +0000589 case LookupResult::Found:
590 Tag = Result.getAsSingle<TagDecl>();
591 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000592
Douglas Gregore677daf2010-03-31 22:19:08 +0000593 case LookupResult::FoundOverloaded:
594 case LookupResult::FoundUnresolvedValue:
595 llvm_unreachable("Tag lookup cannot find non-tags");
596 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000597
Douglas Gregore677daf2010-03-31 22:19:08 +0000598 case LookupResult::Ambiguous:
599 // Let the LookupResult structure handle ambiguities.
600 return QualType();
601 }
602
603 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000604 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000605 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000606 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000607 return QualType();
608 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000609
Douglas Gregore677daf2010-03-31 22:19:08 +0000610 // FIXME: Terrible location information
611 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
612 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
613 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
614 return QualType();
615 }
616
617 // Build the elaborated-type-specifier type.
618 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000619 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000620 }
Mike Stump11289f42009-09-09 15:08:12 +0000621
Douglas Gregor1135c352009-08-06 05:28:30 +0000622 /// \brief Build a new nested-name-specifier given the prefix and an
623 /// identifier that names the next step in the nested-name-specifier.
624 ///
625 /// By default, performs semantic analysis when building the new
626 /// nested-name-specifier. Subclasses may override this routine to provide
627 /// different behavior.
628 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
629 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000630 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000631 QualType ObjectType,
632 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000633
634 /// \brief Build a new nested-name-specifier given the prefix and the
635 /// namespace named in the next step in the nested-name-specifier.
636 ///
637 /// By default, performs semantic analysis when building the new
638 /// nested-name-specifier. Subclasses may override this routine to provide
639 /// different behavior.
640 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
641 SourceRange Range,
642 NamespaceDecl *NS);
643
644 /// \brief Build a new nested-name-specifier given the prefix and the
645 /// type named in the next step in the nested-name-specifier.
646 ///
647 /// By default, performs semantic analysis when building the new
648 /// nested-name-specifier. Subclasses may override this routine to provide
649 /// different behavior.
650 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
651 SourceRange Range,
652 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000653 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000654
655 /// \brief Build a new template name given a nested name specifier, a flag
656 /// indicating whether the "template" keyword was provided, and the template
657 /// that the template name refers to.
658 ///
659 /// By default, builds the new template name directly. Subclasses may override
660 /// this routine to provide different behavior.
661 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
662 bool TemplateKW,
663 TemplateDecl *Template);
664
Douglas Gregor71dc5092009-08-06 06:41:21 +0000665 /// \brief Build a new template name given a nested name specifier and the
666 /// name that is referred to as a template.
667 ///
668 /// By default, performs semantic analysis to determine whether the name can
669 /// be resolved to a specific template, then builds the appropriate kind of
670 /// template name. Subclasses may override this routine to provide different
671 /// behavior.
672 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000673 const IdentifierInfo &II,
674 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000675
Douglas Gregor71395fa2009-11-04 00:56:37 +0000676 /// \brief Build a new template name given a nested name specifier and the
677 /// overloaded operator name that is referred to as a template.
678 ///
679 /// By default, performs semantic analysis to determine whether the name can
680 /// be resolved to a specific template, then builds the appropriate kind of
681 /// template name. Subclasses may override this routine to provide different
682 /// behavior.
683 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
684 OverloadedOperatorKind Operator,
685 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000686
Douglas Gregorebe10102009-08-20 07:17:43 +0000687 /// \brief Build a new compound statement.
688 ///
689 /// By default, performs semantic analysis to build the new statement.
690 /// Subclasses may override this routine to provide different behavior.
691 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
692 MultiStmtArg Statements,
693 SourceLocation RBraceLoc,
694 bool IsStmtExpr) {
695 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
696 IsStmtExpr);
697 }
698
699 /// \brief Build a new case statement.
700 ///
701 /// By default, performs semantic analysis to build the new statement.
702 /// Subclasses may override this routine to provide different behavior.
703 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
704 ExprArg LHS,
705 SourceLocation EllipsisLoc,
706 ExprArg RHS,
707 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000708 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000709 ColonLoc);
710 }
Mike Stump11289f42009-09-09 15:08:12 +0000711
Douglas Gregorebe10102009-08-20 07:17:43 +0000712 /// \brief Attach the body to a new case statement.
713 ///
714 /// By default, performs semantic analysis to build the new statement.
715 /// Subclasses may override this routine to provide different behavior.
716 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
717 getSema().ActOnCaseStmtBody(S.get(), move(Body));
718 return move(S);
719 }
Mike Stump11289f42009-09-09 15:08:12 +0000720
Douglas Gregorebe10102009-08-20 07:17:43 +0000721 /// \brief Build a new default statement.
722 ///
723 /// By default, performs semantic analysis to build the new statement.
724 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000725 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 SourceLocation ColonLoc,
727 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000728 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000729 /*CurScope=*/0);
730 }
Mike Stump11289f42009-09-09 15:08:12 +0000731
Douglas Gregorebe10102009-08-20 07:17:43 +0000732 /// \brief Build a new label statement.
733 ///
734 /// By default, performs semantic analysis to build the new statement.
735 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000736 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000737 IdentifierInfo *Id,
738 SourceLocation ColonLoc,
739 StmtArg SubStmt) {
740 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
741 }
Mike Stump11289f42009-09-09 15:08:12 +0000742
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /// \brief Build a new "if" statement.
744 ///
745 /// By default, performs semantic analysis to build the new statement.
746 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000747 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000748 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000749 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000750 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000751 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000752 }
Mike Stump11289f42009-09-09 15:08:12 +0000753
Douglas Gregorebe10102009-08-20 07:17:43 +0000754 /// \brief Start building a new switch statement.
755 ///
756 /// By default, performs semantic analysis to build the new statement.
757 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000758 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
759 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000760 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000761 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
762 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000763 }
Mike Stump11289f42009-09-09 15:08:12 +0000764
Douglas Gregorebe10102009-08-20 07:17:43 +0000765 /// \brief Attach the body to the switch statement.
766 ///
767 /// By default, performs semantic analysis to build the new statement.
768 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000769 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000770 StmtArg Switch, StmtArg Body) {
771 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
772 move(Body));
773 }
774
775 /// \brief Build a new while statement.
776 ///
777 /// By default, performs semantic analysis to build the new statement.
778 /// Subclasses may override this routine to provide different behavior.
779 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000780 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000781 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000783 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000784 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000785 }
Mike Stump11289f42009-09-09 15:08:12 +0000786
Douglas Gregorebe10102009-08-20 07:17:43 +0000787 /// \brief Build a new do-while statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
791 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
792 SourceLocation WhileLoc,
793 SourceLocation LParenLoc,
794 ExprArg Cond,
795 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000796 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000797 move(Cond), RParenLoc);
798 }
799
800 /// \brief Build a new for statement.
801 ///
802 /// By default, performs semantic analysis to build the new statement.
803 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000804 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000805 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000806 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000807 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000808 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000809 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000810 DeclPtrTy::make(CondVar),
811 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000812 }
Mike Stump11289f42009-09-09 15:08:12 +0000813
Douglas Gregorebe10102009-08-20 07:17:43 +0000814 /// \brief Build a new goto statement.
815 ///
816 /// By default, performs semantic analysis to build the new statement.
817 /// Subclasses may override this routine to provide different behavior.
818 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
819 SourceLocation LabelLoc,
820 LabelStmt *Label) {
821 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
822 }
823
824 /// \brief Build a new indirect goto statement.
825 ///
826 /// By default, performs semantic analysis to build the new statement.
827 /// Subclasses may override this routine to provide different behavior.
828 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
829 SourceLocation StarLoc,
830 ExprArg Target) {
831 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
832 }
Mike Stump11289f42009-09-09 15:08:12 +0000833
Douglas Gregorebe10102009-08-20 07:17:43 +0000834 /// \brief Build a new return statement.
835 ///
836 /// By default, performs semantic analysis to build the new statement.
837 /// Subclasses may override this routine to provide different behavior.
838 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
839 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000840
Douglas Gregorebe10102009-08-20 07:17:43 +0000841 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
842 }
Mike Stump11289f42009-09-09 15:08:12 +0000843
Douglas Gregorebe10102009-08-20 07:17:43 +0000844 /// \brief Build a new declaration statement.
845 ///
846 /// By default, performs semantic analysis to build the new statement.
847 /// Subclasses may override this routine to provide different behavior.
848 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000849 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 SourceLocation EndLoc) {
851 return getSema().Owned(
852 new (getSema().Context) DeclStmt(
853 DeclGroupRef::Create(getSema().Context,
854 Decls, NumDecls),
855 StartLoc, EndLoc));
856 }
Mike Stump11289f42009-09-09 15:08:12 +0000857
Anders Carlssonaaeef072010-01-24 05:50:09 +0000858 /// \brief Build a new inline asm statement.
859 ///
860 /// By default, performs semantic analysis to build the new statement.
861 /// Subclasses may override this routine to provide different behavior.
862 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
863 bool IsSimple,
864 bool IsVolatile,
865 unsigned NumOutputs,
866 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000867 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000868 MultiExprArg Constraints,
869 MultiExprArg Exprs,
870 ExprArg AsmString,
871 MultiExprArg Clobbers,
872 SourceLocation RParenLoc,
873 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000874 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000875 NumInputs, Names, move(Constraints),
876 move(Exprs), move(AsmString), move(Clobbers),
877 RParenLoc, MSAsm);
878 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000879
880 /// \brief Build a new Objective-C @try statement.
881 ///
882 /// By default, performs semantic analysis to build the new statement.
883 /// Subclasses may override this routine to provide different behavior.
884 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
885 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000886 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000887 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000888 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000889 move(Finally));
890 }
891
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000892 /// \brief Rebuild an Objective-C exception declaration.
893 ///
894 /// By default, performs semantic analysis to build the new declaration.
895 /// Subclasses may override this routine to provide different behavior.
896 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
897 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000898 return getSema().BuildObjCExceptionDecl(TInfo, T,
899 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000900 ExceptionDecl->getLocation());
901 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000902
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000903 /// \brief Build a new Objective-C @catch statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
907 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
908 SourceLocation RParenLoc,
909 VarDecl *Var,
910 StmtArg Body) {
911 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
912 Sema::DeclPtrTy::make(Var),
913 move(Body));
914 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000915
Douglas Gregor306de2f2010-04-22 23:59:56 +0000916 /// \brief Build a new Objective-C @finally statement.
917 ///
918 /// By default, performs semantic analysis to build the new statement.
919 /// Subclasses may override this routine to provide different behavior.
920 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
921 StmtArg Body) {
922 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
923 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000924
Douglas Gregor6148de72010-04-22 22:01:21 +0000925 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000926 ///
927 /// By default, performs semantic analysis to build the new statement.
928 /// Subclasses may override this routine to provide different behavior.
929 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
930 ExprArg Operand) {
931 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
932 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000933
Douglas Gregor6148de72010-04-22 22:01:21 +0000934 /// \brief Build a new Objective-C @synchronized statement.
935 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000936 /// By default, performs semantic analysis to build the new statement.
937 /// Subclasses may override this routine to provide different behavior.
938 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
939 ExprArg Object,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
942 move(Body));
943 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000944
945 /// \brief Build a new Objective-C fast enumeration statement.
946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
949 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
950 SourceLocation LParenLoc,
951 StmtArg Element,
952 ExprArg Collection,
953 SourceLocation RParenLoc,
954 StmtArg Body) {
955 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000956 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000957 move(Collection),
958 RParenLoc,
959 move(Body));
960 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000961
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 /// \brief Build a new C++ exception declaration.
963 ///
964 /// By default, performs semantic analysis to build the new decaration.
965 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000966 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000967 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000968 IdentifierInfo *Name,
969 SourceLocation Loc,
970 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000971 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 TypeRange);
973 }
974
975 /// \brief Build a new C++ catch statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
979 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
980 VarDecl *ExceptionDecl,
981 StmtArg Handler) {
982 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +0000983 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +0000984 Handler.takeAs<Stmt>()));
985 }
Mike Stump11289f42009-09-09 15:08:12 +0000986
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 /// \brief Build a new C++ try statement.
988 ///
989 /// By default, performs semantic analysis to build the new statement.
990 /// Subclasses may override this routine to provide different behavior.
991 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
992 StmtArg TryBlock,
993 MultiStmtArg Handlers) {
994 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
995 }
Mike Stump11289f42009-09-09 15:08:12 +0000996
Douglas Gregora16548e2009-08-11 05:31:07 +0000997 /// \brief Build a new expression that references a declaration.
998 ///
999 /// By default, performs semantic analysis to build the new expression.
1000 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001001 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1002 LookupResult &R,
1003 bool RequiresADL) {
1004 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1005 }
1006
1007
1008 /// \brief Build a new expression that references a declaration.
1009 ///
1010 /// By default, performs semantic analysis to build the new expression.
1011 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001012 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1013 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001014 ValueDecl *VD, SourceLocation Loc,
1015 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001016 CXXScopeSpec SS;
1017 SS.setScopeRep(Qualifier);
1018 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001019
1020 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001021
John McCallce546572009-12-08 09:08:17 +00001022 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregora16548e2009-08-11 05:31:07 +00001025 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001026 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001027 /// By default, performs semantic analysis to build the new expression.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1030 SourceLocation RParen) {
1031 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1032 }
1033
Douglas Gregorad8a3362009-09-04 17:36:40 +00001034 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001035 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001036 /// By default, performs semantic analysis to build the new expression.
1037 /// Subclasses may override this routine to provide different behavior.
1038 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1039 SourceLocation OperatorLoc,
1040 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001041 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001042 SourceRange QualifierRange,
1043 TypeSourceInfo *ScopeType,
1044 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001045 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001046 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001047
Douglas Gregora16548e2009-08-11 05:31:07 +00001048 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001050 /// By default, performs semantic analysis to build the new expression.
1051 /// Subclasses may override this routine to provide different behavior.
1052 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1053 UnaryOperator::Opcode Opc,
1054 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001055 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001056 }
Mike Stump11289f42009-09-09 15:08:12 +00001057
Douglas Gregor882211c2010-04-28 22:16:22 +00001058 /// \brief Build a new builtin offsetof expression.
1059 ///
1060 /// By default, performs semantic analysis to build the new expression.
1061 /// Subclasses may override this routine to provide different behavior.
1062 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1063 TypeSourceInfo *Type,
1064 Action::OffsetOfComponent *Components,
1065 unsigned NumComponents,
1066 SourceLocation RParenLoc) {
1067 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1068 NumComponents, RParenLoc);
1069 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001070
Douglas Gregora16548e2009-08-11 05:31:07 +00001071 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001072 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001073 /// By default, performs semantic analysis to build the new expression.
1074 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001075 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001076 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001077 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001078 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001079 }
1080
Mike Stump11289f42009-09-09 15:08:12 +00001081 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001082 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001083 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001084 /// By default, performs semantic analysis to build the new expression.
1085 /// Subclasses may override this routine to provide different behavior.
1086 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1087 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001088 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001089 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1090 OpLoc, isSizeOf, R);
1091 if (Result.isInvalid())
1092 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001093
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 SubExpr.release();
1095 return move(Result);
1096 }
Mike Stump11289f42009-09-09 15:08:12 +00001097
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001099 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001100 /// By default, performs semantic analysis to build the new expression.
1101 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001102 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 SourceLocation LBracketLoc,
1104 ExprArg RHS,
1105 SourceLocation RBracketLoc) {
1106 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001107 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 RBracketLoc);
1109 }
1110
1111 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001112 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 /// By default, performs semantic analysis to build the new expression.
1114 /// Subclasses may override this routine to provide different behavior.
1115 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1116 MultiExprArg Args,
1117 SourceLocation *CommaLocs,
1118 SourceLocation RParenLoc) {
1119 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1120 move(Args), CommaLocs, RParenLoc);
1121 }
1122
1123 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001124 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001125 /// By default, performs semantic analysis to build the new expression.
1126 /// Subclasses may override this routine to provide different behavior.
1127 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001128 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001129 NestedNameSpecifier *Qualifier,
1130 SourceRange QualifierRange,
1131 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001132 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001133 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001134 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001135 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001136 if (!Member->getDeclName()) {
1137 // We have a reference to an unnamed field.
1138 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001139
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001140 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001141 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1142 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001143 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001144
Mike Stump11289f42009-09-09 15:08:12 +00001145 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001146 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001147 Member, MemberLoc,
1148 cast<FieldDecl>(Member)->getType());
1149 return getSema().Owned(ME);
1150 }
Mike Stump11289f42009-09-09 15:08:12 +00001151
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001152 CXXScopeSpec SS;
1153 if (Qualifier) {
1154 SS.setRange(QualifierRange);
1155 SS.setScopeRep(Qualifier);
1156 }
1157
John McCall2d74de92009-12-01 22:10:20 +00001158 QualType BaseType = ((Expr*) Base.get())->getType();
1159
John McCall16df1e52010-03-30 21:47:33 +00001160 // FIXME: this involves duplicating earlier analysis in a lot of
1161 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001162 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1163 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001164 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001165 R.resolveKind();
1166
John McCall2d74de92009-12-01 22:10:20 +00001167 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1168 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001169 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001170 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001171 }
Mike Stump11289f42009-09-09 15:08:12 +00001172
Douglas Gregora16548e2009-08-11 05:31:07 +00001173 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001174 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001175 /// By default, performs semantic analysis to build the new expression.
1176 /// Subclasses may override this routine to provide different behavior.
1177 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1178 BinaryOperator::Opcode Opc,
1179 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001180 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001181 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001182 }
1183
1184 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001185 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001186 /// By default, performs semantic analysis to build the new expression.
1187 /// Subclasses may override this routine to provide different behavior.
1188 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1189 SourceLocation QuestionLoc,
1190 ExprArg LHS,
1191 SourceLocation ColonLoc,
1192 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001193 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 move(LHS), move(RHS));
1195 }
1196
Douglas Gregora16548e2009-08-11 05:31:07 +00001197 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001198 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001199 /// By default, performs semantic analysis to build the new expression.
1200 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001201 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1202 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 SourceLocation RParenLoc,
1204 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001205 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1206 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 }
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001210 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// By default, performs semantic analysis to build the new expression.
1212 /// Subclasses may override this routine to provide different behavior.
1213 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001214 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 SourceLocation RParenLoc,
1216 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001217 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1218 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregora16548e2009-08-11 05:31:07 +00001221 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001222 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001223 /// By default, performs semantic analysis to build the new expression.
1224 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001225 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001226 SourceLocation OpLoc,
1227 SourceLocation AccessorLoc,
1228 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001229
John McCall10eae182009-11-30 22:42:35 +00001230 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001231 QualType BaseType = ((Expr*) Base.get())->getType();
1232 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001233 OpLoc, /*IsArrow*/ false,
1234 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001235 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001236 AccessorLoc,
1237 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001241 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// By default, performs semantic analysis to build the new expression.
1243 /// Subclasses may override this routine to provide different behavior.
1244 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1245 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001246 SourceLocation RBraceLoc,
1247 QualType ResultTy) {
1248 OwningExprResult Result
1249 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1250 if (Result.isInvalid() || ResultTy->isDependentType())
1251 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001252
Douglas Gregord3d93062009-11-09 17:16:50 +00001253 // Patch in the result type we were given, which may have been computed
1254 // when the initial InitListExpr was built.
1255 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1256 ILE->setType(ResultTy);
1257 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001258 }
Mike Stump11289f42009-09-09 15:08:12 +00001259
Douglas Gregora16548e2009-08-11 05:31:07 +00001260 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001261 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001262 /// By default, performs semantic analysis to build the new expression.
1263 /// Subclasses may override this routine to provide different behavior.
1264 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1265 MultiExprArg ArrayExprs,
1266 SourceLocation EqualOrColonLoc,
1267 bool GNUSyntax,
1268 ExprArg Init) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1271 move(Init));
1272 if (Result.isInvalid())
1273 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001274
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 ArrayExprs.release();
1276 return move(Result);
1277 }
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001280 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// By default, builds the implicit value initialization without performing
1282 /// any semantic analysis. Subclasses may override this routine to provide
1283 /// different behavior.
1284 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1285 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1286 }
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001289 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001290 /// By default, performs semantic analysis to build the new expression.
1291 /// Subclasses may override this routine to provide different behavior.
1292 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1293 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001294 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 RParenLoc);
1296 }
1297
1298 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001299 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// By default, performs semantic analysis to build the new expression.
1301 /// Subclasses may override this routine to provide different behavior.
1302 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1303 MultiExprArg SubExprs,
1304 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001305 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001306 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
1311 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001312 /// rather than attempting to map the label statement itself.
1313 /// Subclasses may override this routine to provide different behavior.
1314 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1315 SourceLocation LabelLoc,
1316 LabelStmt *Label) {
1317 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1318 }
Mike Stump11289f42009-09-09 15:08:12 +00001319
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001321 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001322 /// By default, performs semantic analysis to build the new expression.
1323 /// Subclasses may override this routine to provide different behavior.
1324 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1325 StmtArg SubStmt,
1326 SourceLocation RParenLoc) {
1327 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new __builtin_types_compatible_p expression.
1331 ///
1332 /// By default, performs semantic analysis to build the new expression.
1333 /// Subclasses may override this routine to provide different behavior.
1334 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1335 QualType T1, QualType T2,
1336 SourceLocation RParenLoc) {
1337 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1338 T1.getAsOpaquePtr(),
1339 T2.getAsOpaquePtr(),
1340 RParenLoc);
1341 }
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new __builtin_choose_expr expression.
1344 ///
1345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
1347 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1348 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1349 SourceLocation RParenLoc) {
1350 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1351 move(Cond), move(LHS), move(RHS),
1352 RParenLoc);
1353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Douglas Gregora16548e2009-08-11 05:31:07 +00001355 /// \brief Build a new overloaded operator call expression.
1356 ///
1357 /// By default, performs semantic analysis to build the new expression.
1358 /// The semantic analysis provides the behavior of template instantiation,
1359 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001360 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 /// argument-dependent lookup, etc. Subclasses may override this routine to
1362 /// provide different behavior.
1363 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1364 SourceLocation OpLoc,
1365 ExprArg Callee,
1366 ExprArg First,
1367 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001368
1369 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// reinterpret_cast.
1371 ///
1372 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001373 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001374 /// Subclasses may override this routine to provide different behavior.
1375 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1376 Stmt::StmtClass Class,
1377 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001378 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001379 SourceLocation RAngleLoc,
1380 SourceLocation LParenLoc,
1381 ExprArg SubExpr,
1382 SourceLocation RParenLoc) {
1383 switch (Class) {
1384 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001385 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001386 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001387 move(SubExpr), RParenLoc);
1388
1389 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001390 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001391 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001393
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001395 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001396 RAngleLoc, LParenLoc,
1397 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001399
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001401 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001402 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001403 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001404
Douglas Gregora16548e2009-08-11 05:31:07 +00001405 default:
1406 assert(false && "Invalid C++ named cast");
1407 break;
1408 }
Mike Stump11289f42009-09-09 15:08:12 +00001409
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 return getSema().ExprError();
1411 }
Mike Stump11289f42009-09-09 15:08:12 +00001412
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 /// \brief Build a new C++ static_cast expression.
1414 ///
1415 /// By default, performs semantic analysis to build the new expression.
1416 /// Subclasses may override this routine to provide different behavior.
1417 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1418 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001419 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 SourceLocation RAngleLoc,
1421 SourceLocation LParenLoc,
1422 ExprArg SubExpr,
1423 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001424 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1425 TInfo, move(SubExpr),
1426 SourceRange(LAngleLoc, RAngleLoc),
1427 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001428 }
1429
1430 /// \brief Build a new C++ dynamic_cast expression.
1431 ///
1432 /// By default, performs semantic analysis to build the new expression.
1433 /// Subclasses may override this routine to provide different behavior.
1434 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1435 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001436 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001437 SourceLocation RAngleLoc,
1438 SourceLocation LParenLoc,
1439 ExprArg SubExpr,
1440 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001441 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1442 TInfo, move(SubExpr),
1443 SourceRange(LAngleLoc, RAngleLoc),
1444 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001445 }
1446
1447 /// \brief Build a new C++ reinterpret_cast expression.
1448 ///
1449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
1451 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1452 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001453 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 SourceLocation RAngleLoc,
1455 SourceLocation LParenLoc,
1456 ExprArg SubExpr,
1457 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001458 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1459 TInfo, move(SubExpr),
1460 SourceRange(LAngleLoc, RAngleLoc),
1461 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 }
1463
1464 /// \brief Build a new C++ const_cast expression.
1465 ///
1466 /// By default, performs semantic analysis to build the new expression.
1467 /// Subclasses may override this routine to provide different behavior.
1468 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1469 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001470 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001471 SourceLocation RAngleLoc,
1472 SourceLocation LParenLoc,
1473 ExprArg SubExpr,
1474 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001475 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1476 TInfo, move(SubExpr),
1477 SourceRange(LAngleLoc, RAngleLoc),
1478 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 }
Mike Stump11289f42009-09-09 15:08:12 +00001480
Douglas Gregora16548e2009-08-11 05:31:07 +00001481 /// \brief Build a new C++ functional-style cast expression.
1482 ///
1483 /// By default, performs semantic analysis to build the new expression.
1484 /// Subclasses may override this routine to provide different behavior.
1485 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001486 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001487 SourceLocation LParenLoc,
1488 ExprArg SubExpr,
1489 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001490 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001492 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001493 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001494 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001495 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 RParenLoc);
1497 }
Mike Stump11289f42009-09-09 15:08:12 +00001498
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 /// \brief Build a new C++ typeid(type) expression.
1500 ///
1501 /// By default, performs semantic analysis to build the new expression.
1502 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001503 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1504 SourceLocation TypeidLoc,
1505 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001507 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001508 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 }
Mike Stump11289f42009-09-09 15:08:12 +00001510
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 /// \brief Build a new C++ typeid(expr) expression.
1512 ///
1513 /// By default, performs semantic analysis to build the new expression.
1514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001515 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1516 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 ExprArg Operand,
1518 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001519 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1520 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001521 }
1522
Douglas Gregora16548e2009-08-11 05:31:07 +00001523 /// \brief Build a new C++ "this" expression.
1524 ///
1525 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001526 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001528 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001529 QualType ThisType,
1530 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001532 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1533 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 }
1535
1536 /// \brief Build a new C++ throw expression.
1537 ///
1538 /// By default, performs semantic analysis to build the new expression.
1539 /// Subclasses may override this routine to provide different behavior.
1540 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1541 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1542 }
1543
1544 /// \brief Build a new C++ default-argument expression.
1545 ///
1546 /// By default, builds a new default-argument expression, which does not
1547 /// require any semantic analysis. Subclasses may override this routine to
1548 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001549 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001550 ParmVarDecl *Param) {
1551 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1552 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 }
1554
1555 /// \brief Build a new C++ zero-initialization expression.
1556 ///
1557 /// By default, performs semantic analysis to build the new expression.
1558 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001559 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 SourceLocation LParenLoc,
1561 QualType T,
1562 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001563 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1564 T.getAsOpaquePtr(), LParenLoc,
1565 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001566 0, RParenLoc);
1567 }
Mike Stump11289f42009-09-09 15:08:12 +00001568
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// \brief Build a new C++ "new" expression.
1570 ///
1571 /// By default, performs semantic analysis to build the new expression.
1572 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001573 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 bool UseGlobal,
1575 SourceLocation PlacementLParen,
1576 MultiExprArg PlacementArgs,
1577 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001578 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 QualType AllocType,
1580 SourceLocation TypeLoc,
1581 SourceRange TypeRange,
1582 ExprArg ArraySize,
1583 SourceLocation ConstructorLParen,
1584 MultiExprArg ConstructorArgs,
1585 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001586 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 PlacementLParen,
1588 move(PlacementArgs),
1589 PlacementRParen,
1590 ParenTypeId,
1591 AllocType,
1592 TypeLoc,
1593 TypeRange,
1594 move(ArraySize),
1595 ConstructorLParen,
1596 move(ConstructorArgs),
1597 ConstructorRParen);
1598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new C++ "delete" expression.
1601 ///
1602 /// By default, performs semantic analysis to build the new expression.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1605 bool IsGlobalDelete,
1606 bool IsArrayForm,
1607 ExprArg Operand) {
1608 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1609 move(Operand));
1610 }
Mike Stump11289f42009-09-09 15:08:12 +00001611
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 /// \brief Build a new unary type trait expression.
1613 ///
1614 /// By default, performs semantic analysis to build the new expression.
1615 /// Subclasses may override this routine to provide different behavior.
1616 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1617 SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 QualType T,
1620 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001621 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001622 T.getAsOpaquePtr(), RParenLoc);
1623 }
1624
Mike Stump11289f42009-09-09 15:08:12 +00001625 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 /// expression.
1627 ///
1628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001630 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001631 SourceRange QualifierRange,
1632 DeclarationName Name,
1633 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001634 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 CXXScopeSpec SS;
1636 SS.setRange(QualifierRange);
1637 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001638
1639 if (TemplateArgs)
1640 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1641 *TemplateArgs);
1642
1643 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 }
1645
1646 /// \brief Build a new template-id expression.
1647 ///
1648 /// By default, performs semantic analysis to build the new expression.
1649 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001650 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1651 LookupResult &R,
1652 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001653 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001654 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001655 }
1656
1657 /// \brief Build a new object-construction expression.
1658 ///
1659 /// By default, performs semantic analysis to build the new expression.
1660 /// Subclasses may override this routine to provide different behavior.
1661 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001662 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001663 CXXConstructorDecl *Constructor,
1664 bool IsElidable,
1665 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001666 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001667 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001668 ConvertedArgs))
1669 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001670
Douglas Gregordb121ba2009-12-14 16:27:04 +00001671 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1672 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 }
1674
1675 /// \brief Build a new object-construction expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
1679 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1680 QualType T,
1681 SourceLocation LParenLoc,
1682 MultiExprArg Args,
1683 SourceLocation *Commas,
1684 SourceLocation RParenLoc) {
1685 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1686 T.getAsOpaquePtr(),
1687 LParenLoc,
1688 move(Args),
1689 Commas,
1690 RParenLoc);
1691 }
1692
1693 /// \brief Build a new object-construction expression.
1694 ///
1695 /// By default, performs semantic analysis to build the new expression.
1696 /// Subclasses may override this routine to provide different behavior.
1697 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1698 QualType T,
1699 SourceLocation LParenLoc,
1700 MultiExprArg Args,
1701 SourceLocation *Commas,
1702 SourceLocation RParenLoc) {
1703 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1704 /*FIXME*/LParenLoc),
1705 T.getAsOpaquePtr(),
1706 LParenLoc,
1707 move(Args),
1708 Commas,
1709 RParenLoc);
1710 }
Mike Stump11289f42009-09-09 15:08:12 +00001711
Douglas Gregora16548e2009-08-11 05:31:07 +00001712 /// \brief Build a new member reference expression.
1713 ///
1714 /// By default, performs semantic analysis to build the new expression.
1715 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001716 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001717 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001718 bool IsArrow,
1719 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001720 NestedNameSpecifier *Qualifier,
1721 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001722 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001724 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001725 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001727 SS.setRange(QualifierRange);
1728 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001729
John McCall2d74de92009-12-01 22:10:20 +00001730 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1731 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001732 SS, FirstQualifierInScope,
1733 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 }
1735
John McCall10eae182009-11-30 22:42:35 +00001736 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001737 ///
1738 /// By default, performs semantic analysis to build the new expression.
1739 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001740 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001741 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001742 SourceLocation OperatorLoc,
1743 bool IsArrow,
1744 NestedNameSpecifier *Qualifier,
1745 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001746 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001747 LookupResult &R,
1748 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001749 CXXScopeSpec SS;
1750 SS.setRange(QualifierRange);
1751 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001752
John McCall2d74de92009-12-01 22:10:20 +00001753 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1754 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001755 SS, FirstQualifierInScope,
1756 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001757 }
Mike Stump11289f42009-09-09 15:08:12 +00001758
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 /// \brief Build a new Objective-C @encode expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
1763 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001764 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001766 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001767 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001768 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001769
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001770 /// \brief Build a new Objective-C class message.
1771 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1772 Selector Sel,
1773 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001774 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001775 MultiExprArg Args,
1776 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001777 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1778 ReceiverTypeInfo->getType(),
1779 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001780 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001781 move(Args));
1782 }
1783
1784 /// \brief Build a new Objective-C instance message.
1785 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1786 Selector Sel,
1787 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001788 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001789 MultiExprArg Args,
1790 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001791 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1792 return SemaRef.BuildInstanceMessage(move(Receiver),
1793 ReceiverType,
1794 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001795 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 move(Args));
1797 }
1798
Douglas Gregord51d90d2010-04-26 20:11:03 +00001799 /// \brief Build a new Objective-C ivar reference expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
1803 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1804 SourceLocation IvarLoc,
1805 bool IsArrow, bool IsFreeIvar) {
1806 // FIXME: We lose track of the IsFreeIvar bit.
1807 CXXScopeSpec SS;
1808 Expr *Base = BaseArg.takeAs<Expr>();
1809 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1810 Sema::LookupMemberName);
1811 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1812 /*FIME:*/IvarLoc,
1813 SS, DeclPtrTy());
1814 if (Result.isInvalid())
1815 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001816
Douglas Gregord51d90d2010-04-26 20:11:03 +00001817 if (Result.get())
1818 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001819
1820 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001821 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001822 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001823 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001824 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001825 /*TemplateArgs=*/0);
1826 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001827
1828 /// \brief Build a new Objective-C property reference expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001832 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001833 ObjCPropertyDecl *Property,
1834 SourceLocation PropertyLoc) {
1835 CXXScopeSpec SS;
1836 Expr *Base = BaseArg.takeAs<Expr>();
1837 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1838 Sema::LookupMemberName);
1839 bool IsArrow = false;
1840 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1841 /*FIME:*/PropertyLoc,
1842 SS, DeclPtrTy());
1843 if (Result.isInvalid())
1844 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001845
Douglas Gregor9faee212010-04-26 20:47:02 +00001846 if (Result.get())
1847 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001848
1849 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001850 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001851 /*FIXME:*/PropertyLoc, IsArrow,
1852 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001853 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 /*TemplateArgs=*/0);
1856 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857
1858 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001859 /// expression.
1860 ///
1861 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001862 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001863 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1864 ObjCMethodDecl *Getter,
1865 QualType T,
1866 ObjCMethodDecl *Setter,
1867 SourceLocation NameLoc,
1868 ExprArg Base) {
1869 // Since these expressions can only be value-dependent, we do not need to
1870 // perform semantic analysis again.
1871 return getSema().Owned(
1872 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1873 Setter,
1874 NameLoc,
1875 Base.takeAs<Expr>()));
1876 }
1877
Douglas Gregord51d90d2010-04-26 20:11:03 +00001878 /// \brief Build a new Objective-C "isa" expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
1882 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1883 bool IsArrow) {
1884 CXXScopeSpec SS;
1885 Expr *Base = BaseArg.takeAs<Expr>();
1886 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1887 Sema::LookupMemberName);
1888 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1889 /*FIME:*/IsaLoc,
1890 SS, DeclPtrTy());
1891 if (Result.isInvalid())
1892 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001893
Douglas Gregord51d90d2010-04-26 20:11:03 +00001894 if (Result.get())
1895 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001896
1897 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001898 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001899 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001900 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001901 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001902 /*TemplateArgs=*/0);
1903 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001904
Douglas Gregora16548e2009-08-11 05:31:07 +00001905 /// \brief Build a new shuffle vector expression.
1906 ///
1907 /// By default, performs semantic analysis to build the new expression.
1908 /// Subclasses may override this routine to provide different behavior.
1909 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1910 MultiExprArg SubExprs,
1911 SourceLocation RParenLoc) {
1912 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001913 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1915 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1916 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1917 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001918
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 // Build a reference to the __builtin_shufflevector builtin
1920 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001921 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001923 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001925
1926 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 unsigned NumSubExprs = SubExprs.size();
1928 Expr **Subs = (Expr **)SubExprs.release();
1929 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1930 Subs, NumSubExprs,
1931 Builtin->getResultType(),
1932 RParenLoc);
1933 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001934
Douglas Gregora16548e2009-08-11 05:31:07 +00001935 // Type-check the __builtin_shufflevector expression.
1936 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1937 if (Result.isInvalid())
1938 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001939
Douglas Gregora16548e2009-08-11 05:31:07 +00001940 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001941 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001942 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001943};
Douglas Gregora16548e2009-08-11 05:31:07 +00001944
Douglas Gregorebe10102009-08-20 07:17:43 +00001945template<typename Derived>
1946Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1947 if (!S)
1948 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001949
Douglas Gregorebe10102009-08-20 07:17:43 +00001950 switch (S->getStmtClass()) {
1951 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregorebe10102009-08-20 07:17:43 +00001953 // Transform individual statement nodes
1954#define STMT(Node, Parent) \
1955 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1956#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001957#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregorebe10102009-08-20 07:17:43 +00001959 // Transform expressions by calling TransformExpr.
1960#define STMT(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001961#define ABSTRACT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001962#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001963#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001964 {
1965 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1966 if (E.isInvalid())
1967 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001968
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001969 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001970 }
Mike Stump11289f42009-09-09 15:08:12 +00001971 }
1972
Douglas Gregorebe10102009-08-20 07:17:43 +00001973 return SemaRef.Owned(S->Retain());
1974}
Mike Stump11289f42009-09-09 15:08:12 +00001975
1976
Douglas Gregore922c772009-08-04 22:27:00 +00001977template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00001978Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 if (!E)
1980 return SemaRef.Owned(E);
1981
1982 switch (E->getStmtClass()) {
1983 case Stmt::NoStmtClass: break;
1984#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Hunt656bb312010-05-05 15:24:00 +00001985#define ABSTRACT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00001986#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00001987 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00001988#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001989 }
1990
Douglas Gregora16548e2009-08-11 05:31:07 +00001991 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00001992}
1993
1994template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00001995NestedNameSpecifier *
1996TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001997 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001998 QualType ObjectType,
1999 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002000 if (!NNS)
2001 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002002
Douglas Gregorebe10102009-08-20 07:17:43 +00002003 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002004 NestedNameSpecifier *Prefix = NNS->getPrefix();
2005 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002006 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002007 ObjectType,
2008 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002009 if (!Prefix)
2010 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002011
2012 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002013 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002014 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002015 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002016 }
Mike Stump11289f42009-09-09 15:08:12 +00002017
Douglas Gregor1135c352009-08-06 05:28:30 +00002018 switch (NNS->getKind()) {
2019 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002020 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002021 "Identifier nested-name-specifier with no prefix or object type");
2022 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2023 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002024 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002025
2026 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002027 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002028 ObjectType,
2029 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002030
Douglas Gregor1135c352009-08-06 05:28:30 +00002031 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002032 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002034 getDerived().TransformDecl(Range.getBegin(),
2035 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002036 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002037 Prefix == NNS->getPrefix() &&
2038 NS == NNS->getAsNamespace())
2039 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregor1135c352009-08-06 05:28:30 +00002041 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2042 }
Mike Stump11289f42009-09-09 15:08:12 +00002043
Douglas Gregor1135c352009-08-06 05:28:30 +00002044 case NestedNameSpecifier::Global:
2045 // There is no meaningful transformation that one could perform on the
2046 // global scope.
2047 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregor1135c352009-08-06 05:28:30 +00002049 case NestedNameSpecifier::TypeSpecWithTemplate:
2050 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002051 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002052 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2053 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002054 if (T.isNull())
2055 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002056
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 if (!getDerived().AlwaysRebuild() &&
2058 Prefix == NNS->getPrefix() &&
2059 T == QualType(NNS->getAsType(), 0))
2060 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002061
2062 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2063 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002064 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 }
2066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002069 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002070}
2071
2072template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002073DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002074TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002075 SourceLocation Loc,
2076 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002077 if (!Name)
2078 return Name;
2079
2080 switch (Name.getNameKind()) {
2081 case DeclarationName::Identifier:
2082 case DeclarationName::ObjCZeroArgSelector:
2083 case DeclarationName::ObjCOneArgSelector:
2084 case DeclarationName::ObjCMultiArgSelector:
2085 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002086 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002087 case DeclarationName::CXXUsingDirective:
2088 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002089
Douglas Gregorf816bd72009-09-03 22:13:48 +00002090 case DeclarationName::CXXConstructorName:
2091 case DeclarationName::CXXDestructorName:
2092 case DeclarationName::CXXConversionFunctionName: {
2093 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002094 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002095 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002096 if (T.isNull())
2097 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002098
Douglas Gregorf816bd72009-09-03 22:13:48 +00002099 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002100 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002102 }
Mike Stump11289f42009-09-09 15:08:12 +00002103 }
2104
Douglas Gregorf816bd72009-09-03 22:13:48 +00002105 return DeclarationName();
2106}
2107
2108template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002109TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002110TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2111 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002112 SourceLocation Loc = getDerived().getBaseLocation();
2113
Douglas Gregor71dc5092009-08-06 06:41:21 +00002114 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002115 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002116 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002117 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2118 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002119 if (!NNS)
2120 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002121
Douglas Gregor71dc5092009-08-06 06:41:21 +00002122 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002123 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002124 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002125 if (!TransTemplate)
2126 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregor71dc5092009-08-06 06:41:21 +00002128 if (!getDerived().AlwaysRebuild() &&
2129 NNS == QTN->getQualifier() &&
2130 TransTemplate == Template)
2131 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002132
Douglas Gregor71dc5092009-08-06 06:41:21 +00002133 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2134 TransTemplate);
2135 }
Mike Stump11289f42009-09-09 15:08:12 +00002136
John McCalle66edc12009-11-24 19:00:30 +00002137 // These should be getting filtered out before they make it into the AST.
2138 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Douglas Gregor71dc5092009-08-06 06:41:21 +00002141 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002142 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002143 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002144 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2145 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002146 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002147 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002148
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002150 NNS == DTN->getQualifier() &&
2151 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002153
Douglas Gregor71395fa2009-11-04 00:56:37 +00002154 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002155 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002156 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157
2158 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002159 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 }
Mike Stump11289f42009-09-09 15:08:12 +00002161
Douglas Gregor71dc5092009-08-06 06:41:21 +00002162 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002163 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002164 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 if (!TransTemplate)
2166 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002167
Douglas Gregor71dc5092009-08-06 06:41:21 +00002168 if (!getDerived().AlwaysRebuild() &&
2169 TransTemplate == Template)
2170 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002171
Douglas Gregor71dc5092009-08-06 06:41:21 +00002172 return TemplateName(TransTemplate);
2173 }
Mike Stump11289f42009-09-09 15:08:12 +00002174
John McCalle66edc12009-11-24 19:00:30 +00002175 // These should be getting filtered out before they reach the AST.
2176 assert(false && "overloaded function decl survived to here");
2177 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002178}
2179
2180template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002181void TreeTransform<Derived>::InventTemplateArgumentLoc(
2182 const TemplateArgument &Arg,
2183 TemplateArgumentLoc &Output) {
2184 SourceLocation Loc = getDerived().getBaseLocation();
2185 switch (Arg.getKind()) {
2186 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002187 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002188 break;
2189
2190 case TemplateArgument::Type:
2191 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002192 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002193
John McCall0ad16662009-10-29 08:12:44 +00002194 break;
2195
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002196 case TemplateArgument::Template:
2197 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2198 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002199
John McCall0ad16662009-10-29 08:12:44 +00002200 case TemplateArgument::Expression:
2201 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2202 break;
2203
2204 case TemplateArgument::Declaration:
2205 case TemplateArgument::Integral:
2206 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002207 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002208 break;
2209 }
2210}
2211
2212template<typename Derived>
2213bool TreeTransform<Derived>::TransformTemplateArgument(
2214 const TemplateArgumentLoc &Input,
2215 TemplateArgumentLoc &Output) {
2216 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002217 switch (Arg.getKind()) {
2218 case TemplateArgument::Null:
2219 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002220 Output = Input;
2221 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002222
Douglas Gregore922c772009-08-04 22:27:00 +00002223 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002224 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002225 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002226 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002227
2228 DI = getDerived().TransformType(DI);
2229 if (!DI) return true;
2230
2231 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2232 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002233 }
Mike Stump11289f42009-09-09 15:08:12 +00002234
Douglas Gregore922c772009-08-04 22:27:00 +00002235 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002236 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002237 DeclarationName Name;
2238 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2239 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002240 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002241 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002242 if (!D) return true;
2243
John McCall0d07eb32009-10-29 18:45:58 +00002244 Expr *SourceExpr = Input.getSourceDeclExpression();
2245 if (SourceExpr) {
2246 EnterExpressionEvaluationContext Unevaluated(getSema(),
2247 Action::Unevaluated);
2248 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2249 if (E.isInvalid())
2250 SourceExpr = NULL;
2251 else {
2252 SourceExpr = E.takeAs<Expr>();
2253 SourceExpr->Retain();
2254 }
2255 }
2256
2257 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002258 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002259 }
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002261 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002262 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002263 TemplateName Template
2264 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2265 if (Template.isNull())
2266 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002267
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002268 Output = TemplateArgumentLoc(TemplateArgument(Template),
2269 Input.getTemplateQualifierRange(),
2270 Input.getTemplateNameLoc());
2271 return false;
2272 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002273
Douglas Gregore922c772009-08-04 22:27:00 +00002274 case TemplateArgument::Expression: {
2275 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002276 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002277 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002278
John McCall0ad16662009-10-29 08:12:44 +00002279 Expr *InputExpr = Input.getSourceExpression();
2280 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2281
2282 Sema::OwningExprResult E
2283 = getDerived().TransformExpr(InputExpr);
2284 if (E.isInvalid()) return true;
2285
2286 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002287 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002288 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2289 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002290 }
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregore922c772009-08-04 22:27:00 +00002292 case TemplateArgument::Pack: {
2293 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2294 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002295 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002296 AEnd = Arg.pack_end();
2297 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002298
John McCall0ad16662009-10-29 08:12:44 +00002299 // FIXME: preserve source information here when we start
2300 // caring about parameter packs.
2301
John McCall0d07eb32009-10-29 18:45:58 +00002302 TemplateArgumentLoc InputArg;
2303 TemplateArgumentLoc OutputArg;
2304 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2305 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002306 return true;
2307
John McCall0d07eb32009-10-29 18:45:58 +00002308 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002309 }
2310 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002311 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002312 true);
John McCall0d07eb32009-10-29 18:45:58 +00002313 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002314 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002315 }
2316 }
Mike Stump11289f42009-09-09 15:08:12 +00002317
Douglas Gregore922c772009-08-04 22:27:00 +00002318 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002319 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002320}
2321
Douglas Gregord6ff3322009-08-04 16:50:30 +00002322//===----------------------------------------------------------------------===//
2323// Type transformation
2324//===----------------------------------------------------------------------===//
2325
2326template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002327QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002328 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002329 if (getDerived().AlreadyTransformed(T))
2330 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002331
John McCall550e0c22009-10-21 00:40:46 +00002332 // Temporary workaround. All of these transformations should
2333 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002334 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002335 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002336
Douglas Gregorfe17d252010-02-16 19:09:40 +00002337 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002338
John McCall550e0c22009-10-21 00:40:46 +00002339 if (!NewDI)
2340 return QualType();
2341
2342 return NewDI->getType();
2343}
2344
2345template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002346TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2347 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002348 if (getDerived().AlreadyTransformed(DI->getType()))
2349 return DI;
2350
2351 TypeLocBuilder TLB;
2352
2353 TypeLoc TL = DI->getTypeLoc();
2354 TLB.reserve(TL.getFullDataSize());
2355
Douglas Gregorfe17d252010-02-16 19:09:40 +00002356 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002357 if (Result.isNull())
2358 return 0;
2359
John McCallbcd03502009-12-07 02:54:59 +00002360 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002361}
2362
2363template<typename Derived>
2364QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002365TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2366 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002367 switch (T.getTypeLocClass()) {
2368#define ABSTRACT_TYPELOC(CLASS, PARENT)
2369#define TYPELOC(CLASS, PARENT) \
2370 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002371 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2372 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002373#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002374 }
Mike Stump11289f42009-09-09 15:08:12 +00002375
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002376 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002377 return QualType();
2378}
2379
2380/// FIXME: By default, this routine adds type qualifiers only to types
2381/// that can have qualifiers, and silently suppresses those qualifiers
2382/// that are not permitted (e.g., qualifiers on reference or function
2383/// types). This is the right thing for template instantiation, but
2384/// probably not for other clients.
2385template<typename Derived>
2386QualType
2387TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002388 QualifiedTypeLoc T,
2389 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002390 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002391
Douglas Gregorfe17d252010-02-16 19:09:40 +00002392 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2393 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002394 if (Result.isNull())
2395 return QualType();
2396
2397 // Silently suppress qualifiers if the result type can't be qualified.
2398 // FIXME: this is the right thing for template instantiation, but
2399 // probably not for other clients.
2400 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002401 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002402
John McCall550e0c22009-10-21 00:40:46 +00002403 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2404
2405 TLB.push<QualifiedTypeLoc>(Result);
2406
2407 // No location information to preserve.
2408
2409 return Result;
2410}
2411
2412template <class TyLoc> static inline
2413QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2414 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2415 NewT.setNameLoc(T.getNameLoc());
2416 return T.getType();
2417}
2418
John McCall550e0c22009-10-21 00:40:46 +00002419template<typename Derived>
2420QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002421 BuiltinTypeLoc T,
2422 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002423 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2424 NewT.setBuiltinLoc(T.getBuiltinLoc());
2425 if (T.needsExtraLocalData())
2426 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2427 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002428}
Mike Stump11289f42009-09-09 15:08:12 +00002429
Douglas Gregord6ff3322009-08-04 16:50:30 +00002430template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002431QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002432 ComplexTypeLoc T,
2433 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002434 // FIXME: recurse?
2435 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002436}
Mike Stump11289f42009-09-09 15:08:12 +00002437
Douglas Gregord6ff3322009-08-04 16:50:30 +00002438template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002439QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002440 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002441 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002442 QualType PointeeType
2443 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002444 if (PointeeType.isNull())
2445 return QualType();
2446
2447 QualType Result = TL.getType();
John McCall01f21ad2010-05-13 08:39:13 +00002448 if (PointeeType->isObjCInterfaceType() ||
2449 PointeeType->isSpecificBuiltinType(BuiltinType::ObjCId)) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002450 // A dependent pointer type 'T *' has is being transformed such
2451 // that an Objective-C class type is being replaced for 'T'. The
2452 // resulting pointer type is an ObjCObjectPointerType, not a
2453 // PointerType.
John McCall01f21ad2010-05-13 08:39:13 +00002454 ObjCProtocolDecl **Protocols = 0;
2455 unsigned NumProtocols = 0;
2456
2457 if (const ObjCInterfaceType *IFace
2458 = PointeeType->getAs<ObjCInterfaceType>()) {
2459 Protocols = const_cast<ObjCProtocolDecl**>(IFace->qual_begin());
2460 NumProtocols = IFace->getNumProtocols();
2461 }
2462
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002463 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
John McCall01f21ad2010-05-13 08:39:13 +00002464 Protocols,
2465 NumProtocols);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002466
2467 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2468 NewT.setStarLoc(TL.getSigilLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002469 NewT.setHasProtocolsAsWritten(false);
2470 NewT.setLAngleLoc(SourceLocation());
2471 NewT.setRAngleLoc(SourceLocation());
2472 NewT.setHasBaseTypeAsWritten(true);
2473 return Result;
2474 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002475
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002476 if (getDerived().AlwaysRebuild() ||
2477 PointeeType != TL.getPointeeLoc().getType()) {
2478 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2479 if (Result.isNull())
2480 return QualType();
2481 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002482
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002483 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2484 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002485 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002486}
Mike Stump11289f42009-09-09 15:08:12 +00002487
2488template<typename Derived>
2489QualType
John McCall550e0c22009-10-21 00:40:46 +00002490TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002491 BlockPointerTypeLoc TL,
2492 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002493 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002494 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2495 if (PointeeType.isNull())
2496 return QualType();
2497
2498 QualType Result = TL.getType();
2499 if (getDerived().AlwaysRebuild() ||
2500 PointeeType != TL.getPointeeLoc().getType()) {
2501 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002502 TL.getSigilLoc());
2503 if (Result.isNull())
2504 return QualType();
2505 }
2506
Douglas Gregor049211a2010-04-22 16:50:51 +00002507 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002508 NewT.setSigilLoc(TL.getSigilLoc());
2509 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002510}
2511
John McCall70dd5f62009-10-30 00:06:24 +00002512/// Transforms a reference type. Note that somewhat paradoxically we
2513/// don't care whether the type itself is an l-value type or an r-value
2514/// type; we only care if the type was *written* as an l-value type
2515/// or an r-value type.
2516template<typename Derived>
2517QualType
2518TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002519 ReferenceTypeLoc TL,
2520 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002521 const ReferenceType *T = TL.getTypePtr();
2522
2523 // Note that this works with the pointee-as-written.
2524 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2525 if (PointeeType.isNull())
2526 return QualType();
2527
2528 QualType Result = TL.getType();
2529 if (getDerived().AlwaysRebuild() ||
2530 PointeeType != T->getPointeeTypeAsWritten()) {
2531 Result = getDerived().RebuildReferenceType(PointeeType,
2532 T->isSpelledAsLValue(),
2533 TL.getSigilLoc());
2534 if (Result.isNull())
2535 return QualType();
2536 }
2537
2538 // r-value references can be rebuilt as l-value references.
2539 ReferenceTypeLoc NewTL;
2540 if (isa<LValueReferenceType>(Result))
2541 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2542 else
2543 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2544 NewTL.setSigilLoc(TL.getSigilLoc());
2545
2546 return Result;
2547}
2548
Mike Stump11289f42009-09-09 15:08:12 +00002549template<typename Derived>
2550QualType
John McCall550e0c22009-10-21 00:40:46 +00002551TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002552 LValueReferenceTypeLoc TL,
2553 QualType ObjectType) {
2554 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002555}
2556
Mike Stump11289f42009-09-09 15:08:12 +00002557template<typename Derived>
2558QualType
John McCall550e0c22009-10-21 00:40:46 +00002559TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002560 RValueReferenceTypeLoc TL,
2561 QualType ObjectType) {
2562 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002563}
Mike Stump11289f42009-09-09 15:08:12 +00002564
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002566QualType
John McCall550e0c22009-10-21 00:40:46 +00002567TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002568 MemberPointerTypeLoc TL,
2569 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002570 MemberPointerType *T = TL.getTypePtr();
2571
2572 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573 if (PointeeType.isNull())
2574 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002575
John McCall550e0c22009-10-21 00:40:46 +00002576 // TODO: preserve source information for this.
2577 QualType ClassType
2578 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002579 if (ClassType.isNull())
2580 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002581
John McCall550e0c22009-10-21 00:40:46 +00002582 QualType Result = TL.getType();
2583 if (getDerived().AlwaysRebuild() ||
2584 PointeeType != T->getPointeeType() ||
2585 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002586 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2587 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002588 if (Result.isNull())
2589 return QualType();
2590 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002591
John McCall550e0c22009-10-21 00:40:46 +00002592 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2593 NewTL.setSigilLoc(TL.getSigilLoc());
2594
2595 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002596}
2597
Mike Stump11289f42009-09-09 15:08:12 +00002598template<typename Derived>
2599QualType
John McCall550e0c22009-10-21 00:40:46 +00002600TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002601 ConstantArrayTypeLoc TL,
2602 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002603 ConstantArrayType *T = TL.getTypePtr();
2604 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002605 if (ElementType.isNull())
2606 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002607
John McCall550e0c22009-10-21 00:40:46 +00002608 QualType Result = TL.getType();
2609 if (getDerived().AlwaysRebuild() ||
2610 ElementType != T->getElementType()) {
2611 Result = getDerived().RebuildConstantArrayType(ElementType,
2612 T->getSizeModifier(),
2613 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002614 T->getIndexTypeCVRQualifiers(),
2615 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002616 if (Result.isNull())
2617 return QualType();
2618 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002619
John McCall550e0c22009-10-21 00:40:46 +00002620 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2621 NewTL.setLBracketLoc(TL.getLBracketLoc());
2622 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002623
John McCall550e0c22009-10-21 00:40:46 +00002624 Expr *Size = TL.getSizeExpr();
2625 if (Size) {
2626 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2627 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2628 }
2629 NewTL.setSizeExpr(Size);
2630
2631 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002632}
Mike Stump11289f42009-09-09 15:08:12 +00002633
Douglas Gregord6ff3322009-08-04 16:50:30 +00002634template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002636 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002637 IncompleteArrayTypeLoc TL,
2638 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002639 IncompleteArrayType *T = TL.getTypePtr();
2640 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002641 if (ElementType.isNull())
2642 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002643
John McCall550e0c22009-10-21 00:40:46 +00002644 QualType Result = TL.getType();
2645 if (getDerived().AlwaysRebuild() ||
2646 ElementType != T->getElementType()) {
2647 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002648 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002649 T->getIndexTypeCVRQualifiers(),
2650 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002651 if (Result.isNull())
2652 return QualType();
2653 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002654
John McCall550e0c22009-10-21 00:40:46 +00002655 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2656 NewTL.setLBracketLoc(TL.getLBracketLoc());
2657 NewTL.setRBracketLoc(TL.getRBracketLoc());
2658 NewTL.setSizeExpr(0);
2659
2660 return Result;
2661}
2662
2663template<typename Derived>
2664QualType
2665TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002666 VariableArrayTypeLoc TL,
2667 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002668 VariableArrayType *T = TL.getTypePtr();
2669 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2670 if (ElementType.isNull())
2671 return QualType();
2672
2673 // Array bounds are not potentially evaluated contexts
2674 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2675
2676 Sema::OwningExprResult SizeResult
2677 = getDerived().TransformExpr(T->getSizeExpr());
2678 if (SizeResult.isInvalid())
2679 return QualType();
2680
2681 Expr *Size = static_cast<Expr*>(SizeResult.get());
2682
2683 QualType Result = TL.getType();
2684 if (getDerived().AlwaysRebuild() ||
2685 ElementType != T->getElementType() ||
2686 Size != T->getSizeExpr()) {
2687 Result = getDerived().RebuildVariableArrayType(ElementType,
2688 T->getSizeModifier(),
2689 move(SizeResult),
2690 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002691 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002692 if (Result.isNull())
2693 return QualType();
2694 }
2695 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002696
John McCall550e0c22009-10-21 00:40:46 +00002697 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2698 NewTL.setLBracketLoc(TL.getLBracketLoc());
2699 NewTL.setRBracketLoc(TL.getRBracketLoc());
2700 NewTL.setSizeExpr(Size);
2701
2702 return Result;
2703}
2704
2705template<typename Derived>
2706QualType
2707TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002708 DependentSizedArrayTypeLoc TL,
2709 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002710 DependentSizedArrayType *T = TL.getTypePtr();
2711 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2712 if (ElementType.isNull())
2713 return QualType();
2714
2715 // Array bounds are not potentially evaluated contexts
2716 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2717
2718 Sema::OwningExprResult SizeResult
2719 = getDerived().TransformExpr(T->getSizeExpr());
2720 if (SizeResult.isInvalid())
2721 return QualType();
2722
2723 Expr *Size = static_cast<Expr*>(SizeResult.get());
2724
2725 QualType Result = TL.getType();
2726 if (getDerived().AlwaysRebuild() ||
2727 ElementType != T->getElementType() ||
2728 Size != T->getSizeExpr()) {
2729 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2730 T->getSizeModifier(),
2731 move(SizeResult),
2732 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002733 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002734 if (Result.isNull())
2735 return QualType();
2736 }
2737 else SizeResult.take();
2738
2739 // We might have any sort of array type now, but fortunately they
2740 // all have the same location layout.
2741 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2742 NewTL.setLBracketLoc(TL.getLBracketLoc());
2743 NewTL.setRBracketLoc(TL.getRBracketLoc());
2744 NewTL.setSizeExpr(Size);
2745
2746 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002747}
Mike Stump11289f42009-09-09 15:08:12 +00002748
2749template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002750QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002751 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002752 DependentSizedExtVectorTypeLoc TL,
2753 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002754 DependentSizedExtVectorType *T = TL.getTypePtr();
2755
2756 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002757 QualType ElementType = getDerived().TransformType(T->getElementType());
2758 if (ElementType.isNull())
2759 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002760
Douglas Gregore922c772009-08-04 22:27:00 +00002761 // Vector sizes are not potentially evaluated contexts
2762 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2763
Douglas Gregord6ff3322009-08-04 16:50:30 +00002764 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2765 if (Size.isInvalid())
2766 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002767
John McCall550e0c22009-10-21 00:40:46 +00002768 QualType Result = TL.getType();
2769 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002770 ElementType != T->getElementType() ||
2771 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002772 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002773 move(Size),
2774 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002775 if (Result.isNull())
2776 return QualType();
2777 }
2778 else Size.take();
2779
2780 // Result might be dependent or not.
2781 if (isa<DependentSizedExtVectorType>(Result)) {
2782 DependentSizedExtVectorTypeLoc NewTL
2783 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2784 NewTL.setNameLoc(TL.getNameLoc());
2785 } else {
2786 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2787 NewTL.setNameLoc(TL.getNameLoc());
2788 }
2789
2790 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002791}
Mike Stump11289f42009-09-09 15:08:12 +00002792
2793template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002795 VectorTypeLoc TL,
2796 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002797 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002798 QualType ElementType = getDerived().TransformType(T->getElementType());
2799 if (ElementType.isNull())
2800 return QualType();
2801
John McCall550e0c22009-10-21 00:40:46 +00002802 QualType Result = TL.getType();
2803 if (getDerived().AlwaysRebuild() ||
2804 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002805 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2806 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002807 if (Result.isNull())
2808 return QualType();
2809 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002810
John McCall550e0c22009-10-21 00:40:46 +00002811 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2812 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002813
John McCall550e0c22009-10-21 00:40:46 +00002814 return Result;
2815}
2816
2817template<typename Derived>
2818QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002819 ExtVectorTypeLoc TL,
2820 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002821 VectorType *T = TL.getTypePtr();
2822 QualType ElementType = getDerived().TransformType(T->getElementType());
2823 if (ElementType.isNull())
2824 return QualType();
2825
2826 QualType Result = TL.getType();
2827 if (getDerived().AlwaysRebuild() ||
2828 ElementType != T->getElementType()) {
2829 Result = getDerived().RebuildExtVectorType(ElementType,
2830 T->getNumElements(),
2831 /*FIXME*/ SourceLocation());
2832 if (Result.isNull())
2833 return QualType();
2834 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002835
John McCall550e0c22009-10-21 00:40:46 +00002836 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2837 NewTL.setNameLoc(TL.getNameLoc());
2838
2839 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002840}
Mike Stump11289f42009-09-09 15:08:12 +00002841
2842template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002843ParmVarDecl *
2844TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2845 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2846 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2847 if (!NewDI)
2848 return 0;
2849
2850 if (NewDI == OldDI)
2851 return OldParm;
2852 else
2853 return ParmVarDecl::Create(SemaRef.Context,
2854 OldParm->getDeclContext(),
2855 OldParm->getLocation(),
2856 OldParm->getIdentifier(),
2857 NewDI->getType(),
2858 NewDI,
2859 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002860 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002861 /* DefArg */ NULL);
2862}
2863
2864template<typename Derived>
2865bool TreeTransform<Derived>::
2866 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2867 llvm::SmallVectorImpl<QualType> &PTypes,
2868 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2869 FunctionProtoType *T = TL.getTypePtr();
2870
2871 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2872 ParmVarDecl *OldParm = TL.getArg(i);
2873
2874 QualType NewType;
2875 ParmVarDecl *NewParm;
2876
2877 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002878 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2879 if (!NewParm)
2880 return true;
2881 NewType = NewParm->getType();
2882
2883 // Deal with the possibility that we don't have a parameter
2884 // declaration for this parameter.
2885 } else {
2886 NewParm = 0;
2887
2888 QualType OldType = T->getArgType(i);
2889 NewType = getDerived().TransformType(OldType);
2890 if (NewType.isNull())
2891 return true;
2892 }
2893
2894 PTypes.push_back(NewType);
2895 PVars.push_back(NewParm);
2896 }
2897
2898 return false;
2899}
2900
2901template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002902QualType
John McCall550e0c22009-10-21 00:40:46 +00002903TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002904 FunctionProtoTypeLoc TL,
2905 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002906 // Transform the parameters. We do this first for the benefit of template
2907 // instantiations, so that the ParmVarDecls get/ placed into the template
2908 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002909 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002910 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002911 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2912 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002913
Douglas Gregor14cf7522010-04-30 18:55:50 +00002914 FunctionProtoType *T = TL.getTypePtr();
2915 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2916 if (ResultType.isNull())
2917 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002918
John McCall550e0c22009-10-21 00:40:46 +00002919 QualType Result = TL.getType();
2920 if (getDerived().AlwaysRebuild() ||
2921 ResultType != T->getResultType() ||
2922 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2923 Result = getDerived().RebuildFunctionProtoType(ResultType,
2924 ParamTypes.data(),
2925 ParamTypes.size(),
2926 T->isVariadic(),
2927 T->getTypeQuals());
2928 if (Result.isNull())
2929 return QualType();
2930 }
Mike Stump11289f42009-09-09 15:08:12 +00002931
John McCall550e0c22009-10-21 00:40:46 +00002932 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2933 NewTL.setLParenLoc(TL.getLParenLoc());
2934 NewTL.setRParenLoc(TL.getRParenLoc());
2935 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2936 NewTL.setArg(i, ParamDecls[i]);
2937
2938 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002939}
Mike Stump11289f42009-09-09 15:08:12 +00002940
Douglas Gregord6ff3322009-08-04 16:50:30 +00002941template<typename Derived>
2942QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002943 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002944 FunctionNoProtoTypeLoc TL,
2945 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002946 FunctionNoProtoType *T = TL.getTypePtr();
2947 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2948 if (ResultType.isNull())
2949 return QualType();
2950
2951 QualType Result = TL.getType();
2952 if (getDerived().AlwaysRebuild() ||
2953 ResultType != T->getResultType())
2954 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2955
2956 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2957 NewTL.setLParenLoc(TL.getLParenLoc());
2958 NewTL.setRParenLoc(TL.getRParenLoc());
2959
2960 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002961}
Mike Stump11289f42009-09-09 15:08:12 +00002962
John McCallb96ec562009-12-04 22:46:56 +00002963template<typename Derived> QualType
2964TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002965 UnresolvedUsingTypeLoc TL,
2966 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002967 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002968 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002969 if (!D)
2970 return QualType();
2971
2972 QualType Result = TL.getType();
2973 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2974 Result = getDerived().RebuildUnresolvedUsingType(D);
2975 if (Result.isNull())
2976 return QualType();
2977 }
2978
2979 // We might get an arbitrary type spec type back. We should at
2980 // least always get a type spec type, though.
2981 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2982 NewTL.setNameLoc(TL.getNameLoc());
2983
2984 return Result;
2985}
2986
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002988QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002989 TypedefTypeLoc TL,
2990 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002991 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002992 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002993 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2994 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995 if (!Typedef)
2996 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002997
John McCall550e0c22009-10-21 00:40:46 +00002998 QualType Result = TL.getType();
2999 if (getDerived().AlwaysRebuild() ||
3000 Typedef != T->getDecl()) {
3001 Result = getDerived().RebuildTypedefType(Typedef);
3002 if (Result.isNull())
3003 return QualType();
3004 }
Mike Stump11289f42009-09-09 15:08:12 +00003005
John McCall550e0c22009-10-21 00:40:46 +00003006 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3007 NewTL.setNameLoc(TL.getNameLoc());
3008
3009 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003010}
Mike Stump11289f42009-09-09 15:08:12 +00003011
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003013QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003014 TypeOfExprTypeLoc TL,
3015 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003016 // typeof expressions are not potentially evaluated contexts
3017 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003018
John McCalle8595032010-01-13 20:03:27 +00003019 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020 if (E.isInvalid())
3021 return QualType();
3022
John McCall550e0c22009-10-21 00:40:46 +00003023 QualType Result = TL.getType();
3024 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003025 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003026 Result = getDerived().RebuildTypeOfExprType(move(E));
3027 if (Result.isNull())
3028 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003029 }
John McCall550e0c22009-10-21 00:40:46 +00003030 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003031
John McCall550e0c22009-10-21 00:40:46 +00003032 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003033 NewTL.setTypeofLoc(TL.getTypeofLoc());
3034 NewTL.setLParenLoc(TL.getLParenLoc());
3035 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003036
3037 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003038}
Mike Stump11289f42009-09-09 15:08:12 +00003039
3040template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003041QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003042 TypeOfTypeLoc TL,
3043 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003044 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3045 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3046 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003047 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003048
John McCall550e0c22009-10-21 00:40:46 +00003049 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003050 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3051 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003052 if (Result.isNull())
3053 return QualType();
3054 }
Mike Stump11289f42009-09-09 15:08:12 +00003055
John McCall550e0c22009-10-21 00:40:46 +00003056 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003057 NewTL.setTypeofLoc(TL.getTypeofLoc());
3058 NewTL.setLParenLoc(TL.getLParenLoc());
3059 NewTL.setRParenLoc(TL.getRParenLoc());
3060 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003061
3062 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003063}
Mike Stump11289f42009-09-09 15:08:12 +00003064
3065template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003066QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003067 DecltypeTypeLoc TL,
3068 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003069 DecltypeType *T = TL.getTypePtr();
3070
Douglas Gregore922c772009-08-04 22:27:00 +00003071 // decltype expressions are not potentially evaluated contexts
3072 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003073
Douglas Gregord6ff3322009-08-04 16:50:30 +00003074 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3075 if (E.isInvalid())
3076 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003077
John McCall550e0c22009-10-21 00:40:46 +00003078 QualType Result = TL.getType();
3079 if (getDerived().AlwaysRebuild() ||
3080 E.get() != T->getUnderlyingExpr()) {
3081 Result = getDerived().RebuildDecltypeType(move(E));
3082 if (Result.isNull())
3083 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003084 }
John McCall550e0c22009-10-21 00:40:46 +00003085 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003086
John McCall550e0c22009-10-21 00:40:46 +00003087 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3088 NewTL.setNameLoc(TL.getNameLoc());
3089
3090 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003091}
3092
3093template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003094QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003095 RecordTypeLoc TL,
3096 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003097 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003098 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003099 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3100 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003101 if (!Record)
3102 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 QualType Result = TL.getType();
3105 if (getDerived().AlwaysRebuild() ||
3106 Record != T->getDecl()) {
3107 Result = getDerived().RebuildRecordType(Record);
3108 if (Result.isNull())
3109 return QualType();
3110 }
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3113 NewTL.setNameLoc(TL.getNameLoc());
3114
3115 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003116}
Mike Stump11289f42009-09-09 15:08:12 +00003117
3118template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003119QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003120 EnumTypeLoc TL,
3121 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003122 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003123 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003124 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3125 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003126 if (!Enum)
3127 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003128
John McCall550e0c22009-10-21 00:40:46 +00003129 QualType Result = TL.getType();
3130 if (getDerived().AlwaysRebuild() ||
3131 Enum != T->getDecl()) {
3132 Result = getDerived().RebuildEnumType(Enum);
3133 if (Result.isNull())
3134 return QualType();
3135 }
Mike Stump11289f42009-09-09 15:08:12 +00003136
John McCall550e0c22009-10-21 00:40:46 +00003137 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3138 NewTL.setNameLoc(TL.getNameLoc());
3139
3140 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003141}
John McCallfcc33b02009-09-05 00:15:47 +00003142
John McCalle78aac42010-03-10 03:28:59 +00003143template<typename Derived>
3144QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3145 TypeLocBuilder &TLB,
3146 InjectedClassNameTypeLoc TL,
3147 QualType ObjectType) {
3148 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3149 TL.getTypePtr()->getDecl());
3150 if (!D) return QualType();
3151
3152 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3153 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3154 return T;
3155}
3156
Mike Stump11289f42009-09-09 15:08:12 +00003157
Douglas Gregord6ff3322009-08-04 16:50:30 +00003158template<typename Derived>
3159QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003160 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003161 TemplateTypeParmTypeLoc TL,
3162 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003163 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003164}
3165
Mike Stump11289f42009-09-09 15:08:12 +00003166template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003167QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003168 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003169 SubstTemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003171 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003172}
3173
3174template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003175QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3176 const TemplateSpecializationType *TST,
3177 QualType ObjectType) {
3178 // FIXME: this entire method is a temporary workaround; callers
3179 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003180
John McCall0ad16662009-10-29 08:12:44 +00003181 // Fake up a TemplateSpecializationTypeLoc.
3182 TypeLocBuilder TLB;
3183 TemplateSpecializationTypeLoc TL
3184 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3185
John McCall0d07eb32009-10-29 18:45:58 +00003186 SourceLocation BaseLoc = getDerived().getBaseLocation();
3187
3188 TL.setTemplateNameLoc(BaseLoc);
3189 TL.setLAngleLoc(BaseLoc);
3190 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003191 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3192 const TemplateArgument &TA = TST->getArg(i);
3193 TemplateArgumentLoc TAL;
3194 getDerived().InventTemplateArgumentLoc(TA, TAL);
3195 TL.setArgLocInfo(i, TAL.getLocInfo());
3196 }
3197
3198 TypeLocBuilder IgnoredTLB;
3199 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003200}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003201
Douglas Gregorc59e5612009-10-19 22:04:39 +00003202template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003204 TypeLocBuilder &TLB,
3205 TemplateSpecializationTypeLoc TL,
3206 QualType ObjectType) {
3207 const TemplateSpecializationType *T = TL.getTypePtr();
3208
Mike Stump11289f42009-09-09 15:08:12 +00003209 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003210 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003211 if (Template.isNull())
3212 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003213
John McCall6b51f282009-11-23 01:53:49 +00003214 TemplateArgumentListInfo NewTemplateArgs;
3215 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3216 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3217
3218 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3219 TemplateArgumentLoc Loc;
3220 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003221 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003222 NewTemplateArgs.addArgument(Loc);
3223 }
Mike Stump11289f42009-09-09 15:08:12 +00003224
John McCall0ad16662009-10-29 08:12:44 +00003225 // FIXME: maybe don't rebuild if all the template arguments are the same.
3226
3227 QualType Result =
3228 getDerived().RebuildTemplateSpecializationType(Template,
3229 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003230 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003231
3232 if (!Result.isNull()) {
3233 TemplateSpecializationTypeLoc NewTL
3234 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3235 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3236 NewTL.setLAngleLoc(TL.getLAngleLoc());
3237 NewTL.setRAngleLoc(TL.getRAngleLoc());
3238 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3239 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003240 }
Mike Stump11289f42009-09-09 15:08:12 +00003241
John McCall0ad16662009-10-29 08:12:44 +00003242 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003243}
Mike Stump11289f42009-09-09 15:08:12 +00003244
3245template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003246QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003247TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3248 ElaboratedTypeLoc TL,
3249 QualType ObjectType) {
3250 ElaboratedType *T = TL.getTypePtr();
3251
3252 NestedNameSpecifier *NNS = 0;
3253 // NOTE: the qualifier in an ElaboratedType is optional.
3254 if (T->getQualifier() != 0) {
3255 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3256 SourceRange(),
3257 ObjectType);
3258 if (!NNS)
3259 return QualType();
3260 }
Mike Stump11289f42009-09-09 15:08:12 +00003261
Douglas Gregord6ff3322009-08-04 16:50:30 +00003262 QualType Named = getDerived().TransformType(T->getNamedType());
3263 if (Named.isNull())
3264 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003265
John McCall550e0c22009-10-21 00:40:46 +00003266 QualType Result = TL.getType();
3267 if (getDerived().AlwaysRebuild() ||
3268 NNS != T->getQualifier() ||
3269 Named != T->getNamedType()) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003270 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, Named);
John McCall550e0c22009-10-21 00:40:46 +00003271 if (Result.isNull())
3272 return QualType();
3273 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003274
Abramo Bagnara6150c882010-05-11 21:36:43 +00003275 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003276 NewTL.setNameLoc(TL.getNameLoc());
3277
3278 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003279}
Mike Stump11289f42009-09-09 15:08:12 +00003280
3281template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003282QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3283 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003284 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003285 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003286
3287 /* FIXME: preserve source information better than this */
3288 SourceRange SR(TL.getNameLoc());
3289
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003291 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003292 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003293 if (!NNS)
3294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003295
John McCall550e0c22009-10-21 00:40:46 +00003296 QualType Result;
3297
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003299 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003300 = getDerived().TransformType(QualType(TemplateId, 0));
3301 if (NewTemplateId.isNull())
3302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003303
Douglas Gregord6ff3322009-08-04 16:50:30 +00003304 if (!getDerived().AlwaysRebuild() &&
3305 NNS == T->getQualifier() &&
3306 NewTemplateId == QualType(TemplateId, 0))
3307 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003308
Alexis Hunta8136cc2010-05-05 15:23:54 +00003309 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003310 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003311 } else {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003312 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003313 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314 }
John McCall550e0c22009-10-21 00:40:46 +00003315 if (Result.isNull())
3316 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003318 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003319 NewTL.setNameLoc(TL.getNameLoc());
3320
3321 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322}
Mike Stump11289f42009-09-09 15:08:12 +00003323
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003325QualType
3326TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003327 ObjCInterfaceTypeLoc TL,
3328 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003329 // ObjCInterfaceType is never dependent.
3330 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003331}
Mike Stump11289f42009-09-09 15:08:12 +00003332
3333template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003334QualType
3335TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003336 ObjCObjectPointerTypeLoc TL,
3337 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003338 // ObjCObjectPointerType is never dependent.
3339 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003340}
3341
Douglas Gregord6ff3322009-08-04 16:50:30 +00003342//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003343// Statement transformation
3344//===----------------------------------------------------------------------===//
3345template<typename Derived>
3346Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003347TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3348 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003349}
3350
3351template<typename Derived>
3352Sema::OwningStmtResult
3353TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3354 return getDerived().TransformCompoundStmt(S, false);
3355}
3356
3357template<typename Derived>
3358Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003359TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003360 bool IsStmtExpr) {
3361 bool SubStmtChanged = false;
3362 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3363 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3364 B != BEnd; ++B) {
3365 OwningStmtResult Result = getDerived().TransformStmt(*B);
3366 if (Result.isInvalid())
3367 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003368
Douglas Gregorebe10102009-08-20 07:17:43 +00003369 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3370 Statements.push_back(Result.takeAs<Stmt>());
3371 }
Mike Stump11289f42009-09-09 15:08:12 +00003372
Douglas Gregorebe10102009-08-20 07:17:43 +00003373 if (!getDerived().AlwaysRebuild() &&
3374 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003375 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003376
3377 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3378 move_arg(Statements),
3379 S->getRBracLoc(),
3380 IsStmtExpr);
3381}
Mike Stump11289f42009-09-09 15:08:12 +00003382
Douglas Gregorebe10102009-08-20 07:17:43 +00003383template<typename Derived>
3384Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003385TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003386 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3387 {
3388 // The case value expressions are not potentially evaluated.
3389 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003390
Eli Friedman06577382009-11-19 03:14:00 +00003391 // Transform the left-hand case value.
3392 LHS = getDerived().TransformExpr(S->getLHS());
3393 if (LHS.isInvalid())
3394 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003395
Eli Friedman06577382009-11-19 03:14:00 +00003396 // Transform the right-hand case value (for the GNU case-range extension).
3397 RHS = getDerived().TransformExpr(S->getRHS());
3398 if (RHS.isInvalid())
3399 return SemaRef.StmtError();
3400 }
Mike Stump11289f42009-09-09 15:08:12 +00003401
Douglas Gregorebe10102009-08-20 07:17:43 +00003402 // Build the case statement.
3403 // Case statements are always rebuilt so that they will attached to their
3404 // transformed switch statement.
3405 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3406 move(LHS),
3407 S->getEllipsisLoc(),
3408 move(RHS),
3409 S->getColonLoc());
3410 if (Case.isInvalid())
3411 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003412
Douglas Gregorebe10102009-08-20 07:17:43 +00003413 // Transform the statement following the case
3414 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3415 if (SubStmt.isInvalid())
3416 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003417
Douglas Gregorebe10102009-08-20 07:17:43 +00003418 // Attach the body to the case statement
3419 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3420}
3421
3422template<typename Derived>
3423Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003424TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003425 // Transform the statement following the default case
3426 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3427 if (SubStmt.isInvalid())
3428 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003429
Douglas Gregorebe10102009-08-20 07:17:43 +00003430 // Default statements are always rebuilt
3431 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3432 move(SubStmt));
3433}
Mike Stump11289f42009-09-09 15:08:12 +00003434
Douglas Gregorebe10102009-08-20 07:17:43 +00003435template<typename Derived>
3436Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003437TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003438 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3439 if (SubStmt.isInvalid())
3440 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003441
Douglas Gregorebe10102009-08-20 07:17:43 +00003442 // FIXME: Pass the real colon location in.
3443 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3444 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3445 move(SubStmt));
3446}
Mike Stump11289f42009-09-09 15:08:12 +00003447
Douglas Gregorebe10102009-08-20 07:17:43 +00003448template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003449Sema::OwningStmtResult
3450TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003451 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003452 OwningExprResult Cond(SemaRef);
3453 VarDecl *ConditionVar = 0;
3454 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003455 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003456 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003457 getDerived().TransformDefinition(
3458 S->getConditionVariable()->getLocation(),
3459 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003460 if (!ConditionVar)
3461 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003462 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003463 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003464
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003465 if (Cond.isInvalid())
3466 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003467
3468 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003469 if (S->getCond()) {
3470 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3471 S->getIfLoc(),
3472 move(Cond));
3473 if (CondE.isInvalid())
3474 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003475
Douglas Gregor6d319c62010-05-08 23:34:38 +00003476 Cond = move(CondE);
3477 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003478 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003479
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003480 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3481 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3482 return SemaRef.StmtError();
3483
Douglas Gregorebe10102009-08-20 07:17:43 +00003484 // Transform the "then" branch.
3485 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3486 if (Then.isInvalid())
3487 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003488
Douglas Gregorebe10102009-08-20 07:17:43 +00003489 // Transform the "else" branch.
3490 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3491 if (Else.isInvalid())
3492 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003493
Douglas Gregorebe10102009-08-20 07:17:43 +00003494 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003495 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003496 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003497 Then.get() == S->getThen() &&
3498 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003499 return SemaRef.Owned(S->Retain());
3500
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003501 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003502 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003503 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003504}
3505
3506template<typename Derived>
3507Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003508TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003509 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003510 OwningExprResult Cond(SemaRef);
3511 VarDecl *ConditionVar = 0;
3512 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003513 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003514 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003515 getDerived().TransformDefinition(
3516 S->getConditionVariable()->getLocation(),
3517 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003518 if (!ConditionVar)
3519 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003520 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003521 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003522
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003523 if (Cond.isInvalid())
3524 return SemaRef.StmtError();
3525 }
Mike Stump11289f42009-09-09 15:08:12 +00003526
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003528 OwningStmtResult Switch
3529 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3530 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 if (Switch.isInvalid())
3532 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003533
Douglas Gregorebe10102009-08-20 07:17:43 +00003534 // Transform the body of the switch statement.
3535 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3536 if (Body.isInvalid())
3537 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003538
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 // Complete the switch statement.
3540 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3541 move(Body));
3542}
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>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003547 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003548 OwningExprResult Cond(SemaRef);
3549 VarDecl *ConditionVar = 0;
3550 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003551 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003552 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003553 getDerived().TransformDefinition(
3554 S->getConditionVariable()->getLocation(),
3555 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003556 if (!ConditionVar)
3557 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003558 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003559 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003560
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003561 if (Cond.isInvalid())
3562 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003563
3564 if (S->getCond()) {
3565 // Convert the condition to a boolean value.
3566 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003567 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003568 move(Cond));
3569 if (CondE.isInvalid())
3570 return getSema().StmtError();
3571 Cond = move(CondE);
3572 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003573 }
Mike Stump11289f42009-09-09 15:08:12 +00003574
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003575 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3576 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3577 return SemaRef.StmtError();
3578
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 // Transform the body
3580 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3581 if (Body.isInvalid())
3582 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003583
Douglas Gregorebe10102009-08-20 07:17:43 +00003584 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003585 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003586 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003587 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003588 return SemaRef.Owned(S->Retain());
3589
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003590 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003591 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003592}
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregorebe10102009-08-20 07:17:43 +00003594template<typename Derived>
3595Sema::OwningStmtResult
3596TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003597 // Transform the body
3598 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3599 if (Body.isInvalid())
3600 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003601
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003602 // Transform the condition
3603 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3604 if (Cond.isInvalid())
3605 return SemaRef.StmtError();
3606
Douglas Gregorebe10102009-08-20 07:17:43 +00003607 if (!getDerived().AlwaysRebuild() &&
3608 Cond.get() == S->getCond() &&
3609 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003610 return SemaRef.Owned(S->Retain());
3611
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3613 /*FIXME:*/S->getWhileLoc(), move(Cond),
3614 S->getRParenLoc());
3615}
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617template<typename Derived>
3618Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003619TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 // Transform the initialization statement
3621 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3622 if (Init.isInvalid())
3623 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003624
Douglas Gregorebe10102009-08-20 07:17:43 +00003625 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003626 OwningExprResult Cond(SemaRef);
3627 VarDecl *ConditionVar = 0;
3628 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003629 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003630 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003631 getDerived().TransformDefinition(
3632 S->getConditionVariable()->getLocation(),
3633 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003634 if (!ConditionVar)
3635 return SemaRef.StmtError();
3636 } else {
3637 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003638
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003639 if (Cond.isInvalid())
3640 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003641
3642 if (S->getCond()) {
3643 // Convert the condition to a boolean value.
3644 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3645 S->getForLoc(),
3646 move(Cond));
3647 if (CondE.isInvalid())
3648 return getSema().StmtError();
3649
3650 Cond = move(CondE);
3651 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003652 }
Mike Stump11289f42009-09-09 15:08:12 +00003653
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003654 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3655 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3656 return SemaRef.StmtError();
3657
Douglas Gregorebe10102009-08-20 07:17:43 +00003658 // Transform the increment
3659 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3660 if (Inc.isInvalid())
3661 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003662
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003663 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3664 if (S->getInc() && !FullInc->get())
3665 return SemaRef.StmtError();
3666
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 // Transform the body
3668 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3669 if (Body.isInvalid())
3670 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003671
Douglas Gregorebe10102009-08-20 07:17:43 +00003672 if (!getDerived().AlwaysRebuild() &&
3673 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003674 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 Inc.get() == S->getInc() &&
3676 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003677 return SemaRef.Owned(S->Retain());
3678
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003680 move(Init), FullCond, ConditionVar,
3681 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003682}
3683
3684template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003685Sema::OwningStmtResult
3686TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003688 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003689 S->getLabel());
3690}
3691
3692template<typename Derived>
3693Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003694TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003695 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3696 if (Target.isInvalid())
3697 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003698
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 if (!getDerived().AlwaysRebuild() &&
3700 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003701 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003702
3703 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3704 move(Target));
3705}
3706
3707template<typename Derived>
3708Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003709TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3710 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003711}
Mike Stump11289f42009-09-09 15:08:12 +00003712
Douglas Gregorebe10102009-08-20 07:17:43 +00003713template<typename Derived>
3714Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003715TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3716 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003717}
Mike Stump11289f42009-09-09 15:08:12 +00003718
Douglas Gregorebe10102009-08-20 07:17:43 +00003719template<typename Derived>
3720Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003721TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003722 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3723 if (Result.isInvalid())
3724 return SemaRef.StmtError();
3725
Mike Stump11289f42009-09-09 15:08:12 +00003726 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003727 // to tell whether the return type of the function has changed.
3728 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3729}
Mike Stump11289f42009-09-09 15:08:12 +00003730
Douglas Gregorebe10102009-08-20 07:17:43 +00003731template<typename Derived>
3732Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003733TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003734 bool DeclChanged = false;
3735 llvm::SmallVector<Decl *, 4> Decls;
3736 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3737 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003738 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3739 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003740 if (!Transformed)
3741 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregorebe10102009-08-20 07:17:43 +00003743 if (Transformed != *D)
3744 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003745
Douglas Gregorebe10102009-08-20 07:17:43 +00003746 Decls.push_back(Transformed);
3747 }
Mike Stump11289f42009-09-09 15:08:12 +00003748
Douglas Gregorebe10102009-08-20 07:17:43 +00003749 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003750 return SemaRef.Owned(S->Retain());
3751
3752 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003753 S->getStartLoc(), S->getEndLoc());
3754}
Mike Stump11289f42009-09-09 15:08:12 +00003755
Douglas Gregorebe10102009-08-20 07:17:43 +00003756template<typename Derived>
3757Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003758TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003759 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003760 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003761}
3762
3763template<typename Derived>
3764Sema::OwningStmtResult
3765TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003766
Anders Carlssonaaeef072010-01-24 05:50:09 +00003767 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3768 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003769 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003770
Anders Carlssonaaeef072010-01-24 05:50:09 +00003771 OwningExprResult AsmString(SemaRef);
3772 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3773
3774 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003775
Anders Carlssonaaeef072010-01-24 05:50:09 +00003776 // Go through the outputs.
3777 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003778 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003779
Anders Carlssonaaeef072010-01-24 05:50:09 +00003780 // No need to transform the constraint literal.
3781 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003782
Anders Carlssonaaeef072010-01-24 05:50:09 +00003783 // Transform the output expr.
3784 Expr *OutputExpr = S->getOutputExpr(I);
3785 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3786 if (Result.isInvalid())
3787 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003788
Anders Carlssonaaeef072010-01-24 05:50:09 +00003789 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003790
Anders Carlssonaaeef072010-01-24 05:50:09 +00003791 Exprs.push_back(Result.takeAs<Expr>());
3792 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003793
Anders Carlssonaaeef072010-01-24 05:50:09 +00003794 // Go through the inputs.
3795 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003796 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003797
Anders Carlssonaaeef072010-01-24 05:50:09 +00003798 // No need to transform the constraint literal.
3799 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003800
Anders Carlssonaaeef072010-01-24 05:50:09 +00003801 // Transform the input expr.
3802 Expr *InputExpr = S->getInputExpr(I);
3803 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3804 if (Result.isInvalid())
3805 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003806
Anders Carlssonaaeef072010-01-24 05:50:09 +00003807 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003808
Anders Carlssonaaeef072010-01-24 05:50:09 +00003809 Exprs.push_back(Result.takeAs<Expr>());
3810 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003811
Anders Carlssonaaeef072010-01-24 05:50:09 +00003812 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3813 return SemaRef.Owned(S->Retain());
3814
3815 // Go through the clobbers.
3816 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3817 Clobbers.push_back(S->getClobber(I)->Retain());
3818
3819 // No need to transform the asm string literal.
3820 AsmString = SemaRef.Owned(S->getAsmString());
3821
3822 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3823 S->isSimple(),
3824 S->isVolatile(),
3825 S->getNumOutputs(),
3826 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003827 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003828 move_arg(Constraints),
3829 move_arg(Exprs),
3830 move(AsmString),
3831 move_arg(Clobbers),
3832 S->getRParenLoc(),
3833 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003834}
3835
3836
3837template<typename Derived>
3838Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003839TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003840 // Transform the body of the @try.
3841 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3842 if (TryBody.isInvalid())
3843 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003844
Douglas Gregor96c79492010-04-23 22:50:49 +00003845 // Transform the @catch statements (if present).
3846 bool AnyCatchChanged = false;
3847 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3848 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3849 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003850 if (Catch.isInvalid())
3851 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003852 if (Catch.get() != S->getCatchStmt(I))
3853 AnyCatchChanged = true;
3854 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003855 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003856
Douglas Gregor306de2f2010-04-22 23:59:56 +00003857 // Transform the @finally statement (if present).
3858 OwningStmtResult Finally(SemaRef);
3859 if (S->getFinallyStmt()) {
3860 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3861 if (Finally.isInvalid())
3862 return SemaRef.StmtError();
3863 }
3864
3865 // If nothing changed, just retain this statement.
3866 if (!getDerived().AlwaysRebuild() &&
3867 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003868 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003869 Finally.get() == S->getFinallyStmt())
3870 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003871
Douglas Gregor306de2f2010-04-22 23:59:56 +00003872 // Build a new statement.
3873 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003874 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003875}
Mike Stump11289f42009-09-09 15:08:12 +00003876
Douglas Gregorebe10102009-08-20 07:17:43 +00003877template<typename Derived>
3878Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003879TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003880 // Transform the @catch parameter, if there is one.
3881 VarDecl *Var = 0;
3882 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3883 TypeSourceInfo *TSInfo = 0;
3884 if (FromVar->getTypeSourceInfo()) {
3885 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3886 if (!TSInfo)
3887 return SemaRef.StmtError();
3888 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003890 QualType T;
3891 if (TSInfo)
3892 T = TSInfo->getType();
3893 else {
3894 T = getDerived().TransformType(FromVar->getType());
3895 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003896 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003897 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003898
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003899 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3900 if (!Var)
3901 return SemaRef.StmtError();
3902 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003903
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003904 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3905 if (Body.isInvalid())
3906 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003907
3908 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003909 S->getRParenLoc(),
3910 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003911}
Mike Stump11289f42009-09-09 15:08:12 +00003912
Douglas Gregorebe10102009-08-20 07:17:43 +00003913template<typename Derived>
3914Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003915TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003916 // Transform the body.
3917 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3918 if (Body.isInvalid())
3919 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003920
Douglas Gregor306de2f2010-04-22 23:59:56 +00003921 // If nothing changed, just retain this statement.
3922 if (!getDerived().AlwaysRebuild() &&
3923 Body.get() == S->getFinallyBody())
3924 return SemaRef.Owned(S->Retain());
3925
3926 // Build a new statement.
3927 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3928 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003929}
Mike Stump11289f42009-09-09 15:08:12 +00003930
Douglas Gregorebe10102009-08-20 07:17:43 +00003931template<typename Derived>
3932Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003933TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003934 OwningExprResult Operand(SemaRef);
3935 if (S->getThrowExpr()) {
3936 Operand = getDerived().TransformExpr(S->getThrowExpr());
3937 if (Operand.isInvalid())
3938 return getSema().StmtError();
3939 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003940
Douglas Gregor2900c162010-04-22 21:44:01 +00003941 if (!getDerived().AlwaysRebuild() &&
3942 Operand.get() == S->getThrowExpr())
3943 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003944
Douglas Gregor2900c162010-04-22 21:44:01 +00003945 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003946}
Mike Stump11289f42009-09-09 15:08:12 +00003947
Douglas Gregorebe10102009-08-20 07:17:43 +00003948template<typename Derived>
3949Sema::OwningStmtResult
3950TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003951 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003952 // Transform the object we are locking.
3953 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3954 if (Object.isInvalid())
3955 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003956
Douglas Gregor6148de72010-04-22 22:01:21 +00003957 // Transform the body.
3958 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3959 if (Body.isInvalid())
3960 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003961
Douglas Gregor6148de72010-04-22 22:01:21 +00003962 // If nothing change, just retain the current statement.
3963 if (!getDerived().AlwaysRebuild() &&
3964 Object.get() == S->getSynchExpr() &&
3965 Body.get() == S->getSynchBody())
3966 return SemaRef.Owned(S->Retain());
3967
3968 // Build a new statement.
3969 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3970 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003971}
3972
3973template<typename Derived>
3974Sema::OwningStmtResult
3975TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003976 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003977 // Transform the element statement.
3978 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3979 if (Element.isInvalid())
3980 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003981
Douglas Gregorf68a5082010-04-22 23:10:45 +00003982 // Transform the collection expression.
3983 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3984 if (Collection.isInvalid())
3985 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003986
Douglas Gregorf68a5082010-04-22 23:10:45 +00003987 // Transform the body.
3988 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3989 if (Body.isInvalid())
3990 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003991
Douglas Gregorf68a5082010-04-22 23:10:45 +00003992 // If nothing changed, just retain this statement.
3993 if (!getDerived().AlwaysRebuild() &&
3994 Element.get() == S->getElement() &&
3995 Collection.get() == S->getCollection() &&
3996 Body.get() == S->getBody())
3997 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003998
Douglas Gregorf68a5082010-04-22 23:10:45 +00003999 // Build a new statement.
4000 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4001 /*FIXME:*/S->getForLoc(),
4002 move(Element),
4003 move(Collection),
4004 S->getRParenLoc(),
4005 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004006}
4007
4008
4009template<typename Derived>
4010Sema::OwningStmtResult
4011TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4012 // Transform the exception declaration, if any.
4013 VarDecl *Var = 0;
4014 if (S->getExceptionDecl()) {
4015 VarDecl *ExceptionDecl = S->getExceptionDecl();
4016 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4017 ExceptionDecl->getDeclName());
4018
4019 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4020 if (T.isNull())
4021 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004022
Douglas Gregorebe10102009-08-20 07:17:43 +00004023 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4024 T,
John McCallbcd03502009-12-07 02:54:59 +00004025 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004026 ExceptionDecl->getIdentifier(),
4027 ExceptionDecl->getLocation(),
4028 /*FIXME: Inaccurate*/
4029 SourceRange(ExceptionDecl->getLocation()));
4030 if (!Var || Var->isInvalidDecl()) {
4031 if (Var)
4032 Var->Destroy(SemaRef.Context);
4033 return SemaRef.StmtError();
4034 }
4035 }
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037 // Transform the actual exception handler.
4038 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4039 if (Handler.isInvalid()) {
4040 if (Var)
4041 Var->Destroy(SemaRef.Context);
4042 return SemaRef.StmtError();
4043 }
Mike Stump11289f42009-09-09 15:08:12 +00004044
Douglas Gregorebe10102009-08-20 07:17:43 +00004045 if (!getDerived().AlwaysRebuild() &&
4046 !Var &&
4047 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004048 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004049
4050 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4051 Var,
4052 move(Handler));
4053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
Douglas Gregorebe10102009-08-20 07:17:43 +00004055template<typename Derived>
4056Sema::OwningStmtResult
4057TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4058 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004059 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004060 = getDerived().TransformCompoundStmt(S->getTryBlock());
4061 if (TryBlock.isInvalid())
4062 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregorebe10102009-08-20 07:17:43 +00004064 // Transform the handlers.
4065 bool HandlerChanged = false;
4066 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4067 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004068 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004069 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4070 if (Handler.isInvalid())
4071 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004072
Douglas Gregorebe10102009-08-20 07:17:43 +00004073 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4074 Handlers.push_back(Handler.takeAs<Stmt>());
4075 }
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregorebe10102009-08-20 07:17:43 +00004077 if (!getDerived().AlwaysRebuild() &&
4078 TryBlock.get() == S->getTryBlock() &&
4079 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004080 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004081
4082 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004083 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004084}
Mike Stump11289f42009-09-09 15:08:12 +00004085
Douglas Gregorebe10102009-08-20 07:17:43 +00004086//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004087// Expression transformation
4088//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004089template<typename Derived>
4090Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004091TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004092 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004093}
Mike Stump11289f42009-09-09 15:08:12 +00004094
4095template<typename Derived>
4096Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004097TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004098 NestedNameSpecifier *Qualifier = 0;
4099 if (E->getQualifier()) {
4100 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004101 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004102 if (!Qualifier)
4103 return SemaRef.ExprError();
4104 }
John McCallce546572009-12-08 09:08:17 +00004105
4106 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004107 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4108 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004109 if (!ND)
4110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004111
Alexis Hunta8136cc2010-05-05 15:23:54 +00004112 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004113 Qualifier == E->getQualifier() &&
4114 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004115 !E->hasExplicitTemplateArgumentList()) {
4116
4117 // Mark it referenced in the new context regardless.
4118 // FIXME: this is a bit instantiation-specific.
4119 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4120
Mike Stump11289f42009-09-09 15:08:12 +00004121 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004122 }
John McCallce546572009-12-08 09:08:17 +00004123
4124 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4125 if (E->hasExplicitTemplateArgumentList()) {
4126 TemplateArgs = &TransArgs;
4127 TransArgs.setLAngleLoc(E->getLAngleLoc());
4128 TransArgs.setRAngleLoc(E->getRAngleLoc());
4129 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4130 TemplateArgumentLoc Loc;
4131 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4132 return SemaRef.ExprError();
4133 TransArgs.addArgument(Loc);
4134 }
4135 }
4136
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004137 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004138 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004139}
Mike Stump11289f42009-09-09 15:08:12 +00004140
Douglas Gregora16548e2009-08-11 05:31:07 +00004141template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004142Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004143TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004144 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004145}
Mike Stump11289f42009-09-09 15:08:12 +00004146
Douglas Gregora16548e2009-08-11 05:31:07 +00004147template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004148Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004149TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004150 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004151}
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregora16548e2009-08-11 05:31:07 +00004153template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004154Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004155TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004156 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004157}
Mike Stump11289f42009-09-09 15:08:12 +00004158
Douglas Gregora16548e2009-08-11 05:31:07 +00004159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004160Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004161TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004162 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004163}
Mike Stump11289f42009-09-09 15:08:12 +00004164
Douglas Gregora16548e2009-08-11 05:31:07 +00004165template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004166Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004167TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004168 return SemaRef.Owned(E->Retain());
4169}
4170
4171template<typename Derived>
4172Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004173TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4175 if (SubExpr.isInvalid())
4176 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004177
Douglas Gregora16548e2009-08-11 05:31:07 +00004178 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004179 return SemaRef.Owned(E->Retain());
4180
4181 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004182 E->getRParen());
4183}
4184
Mike Stump11289f42009-09-09 15:08:12 +00004185template<typename Derived>
4186Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004187TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4188 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004189 if (SubExpr.isInvalid())
4190 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004193 return SemaRef.Owned(E->Retain());
4194
Douglas Gregora16548e2009-08-11 05:31:07 +00004195 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4196 E->getOpcode(),
4197 move(SubExpr));
4198}
Mike Stump11289f42009-09-09 15:08:12 +00004199
Douglas Gregora16548e2009-08-11 05:31:07 +00004200template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004201Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004202TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4203 // Transform the type.
4204 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4205 if (!Type)
4206 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004207
Douglas Gregor882211c2010-04-28 22:16:22 +00004208 // Transform all of the components into components similar to what the
4209 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004210 // FIXME: It would be slightly more efficient in the non-dependent case to
4211 // just map FieldDecls, rather than requiring the rebuilder to look for
4212 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004213 // template code that we don't care.
4214 bool ExprChanged = false;
4215 typedef Action::OffsetOfComponent Component;
4216 typedef OffsetOfExpr::OffsetOfNode Node;
4217 llvm::SmallVector<Component, 4> Components;
4218 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4219 const Node &ON = E->getComponent(I);
4220 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004221 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004222 Comp.LocStart = ON.getRange().getBegin();
4223 Comp.LocEnd = ON.getRange().getEnd();
4224 switch (ON.getKind()) {
4225 case Node::Array: {
4226 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4227 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4228 if (Index.isInvalid())
4229 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004230
Douglas Gregor882211c2010-04-28 22:16:22 +00004231 ExprChanged = ExprChanged || Index.get() != FromIndex;
4232 Comp.isBrackets = true;
4233 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4234 break;
4235 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004236
Douglas Gregor882211c2010-04-28 22:16:22 +00004237 case Node::Field:
4238 case Node::Identifier:
4239 Comp.isBrackets = false;
4240 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004241 if (!Comp.U.IdentInfo)
4242 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004243
Douglas Gregor882211c2010-04-28 22:16:22 +00004244 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004245
Douglas Gregord1702062010-04-29 00:18:15 +00004246 case Node::Base:
4247 // Will be recomputed during the rebuild.
4248 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004249 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004250
Douglas Gregor882211c2010-04-28 22:16:22 +00004251 Components.push_back(Comp);
4252 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004253
Douglas Gregor882211c2010-04-28 22:16:22 +00004254 // If nothing changed, retain the existing expression.
4255 if (!getDerived().AlwaysRebuild() &&
4256 Type == E->getTypeSourceInfo() &&
4257 !ExprChanged)
4258 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004259
Douglas Gregor882211c2010-04-28 22:16:22 +00004260 // Build a new offsetof expression.
4261 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4262 Components.data(), Components.size(),
4263 E->getRParenLoc());
4264}
4265
4266template<typename Derived>
4267Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004268TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004270 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004271
John McCallbcd03502009-12-07 02:54:59 +00004272 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004273 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004274 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004275
John McCall4c98fd82009-11-04 07:28:41 +00004276 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004277 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004278
John McCall4c98fd82009-11-04 07:28:41 +00004279 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004280 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 E->getSourceRange());
4282 }
Mike Stump11289f42009-09-09 15:08:12 +00004283
Douglas Gregora16548e2009-08-11 05:31:07 +00004284 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004285 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004286 // C++0x [expr.sizeof]p1:
4287 // The operand is either an expression, which is an unevaluated operand
4288 // [...]
4289 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4292 if (SubExpr.isInvalid())
4293 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4296 return SemaRef.Owned(E->Retain());
4297 }
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4300 E->isSizeOf(),
4301 E->getSourceRange());
4302}
Mike Stump11289f42009-09-09 15:08:12 +00004303
Douglas Gregora16548e2009-08-11 05:31:07 +00004304template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004305Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004306TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004307 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4308 if (LHS.isInvalid())
4309 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004310
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4312 if (RHS.isInvalid())
4313 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004314
4315
Douglas Gregora16548e2009-08-11 05:31:07 +00004316 if (!getDerived().AlwaysRebuild() &&
4317 LHS.get() == E->getLHS() &&
4318 RHS.get() == E->getRHS())
4319 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004320
Douglas Gregora16548e2009-08-11 05:31:07 +00004321 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4322 /*FIXME:*/E->getLHS()->getLocStart(),
4323 move(RHS),
4324 E->getRBracketLoc());
4325}
Mike Stump11289f42009-09-09 15:08:12 +00004326
4327template<typename Derived>
4328Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004329TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004330 // Transform the callee.
4331 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4332 if (Callee.isInvalid())
4333 return SemaRef.ExprError();
4334
4335 // Transform arguments.
4336 bool ArgChanged = false;
4337 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4338 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4339 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4340 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4341 if (Arg.isInvalid())
4342 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 // FIXME: Wrong source location information for the ','.
4345 FakeCommaLocs.push_back(
4346 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004347
4348 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 Args.push_back(Arg.takeAs<Expr>());
4350 }
Mike Stump11289f42009-09-09 15:08:12 +00004351
Douglas Gregora16548e2009-08-11 05:31:07 +00004352 if (!getDerived().AlwaysRebuild() &&
4353 Callee.get() == E->getCallee() &&
4354 !ArgChanged)
4355 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004356
Douglas Gregora16548e2009-08-11 05:31:07 +00004357 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004358 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004359 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4360 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4361 move_arg(Args),
4362 FakeCommaLocs.data(),
4363 E->getRParenLoc());
4364}
Mike Stump11289f42009-09-09 15:08:12 +00004365
4366template<typename Derived>
4367Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004368TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004369 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4370 if (Base.isInvalid())
4371 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004372
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004373 NestedNameSpecifier *Qualifier = 0;
4374 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004375 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004376 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004377 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004378 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004379 return SemaRef.ExprError();
4380 }
Mike Stump11289f42009-09-09 15:08:12 +00004381
Eli Friedman2cfcef62009-12-04 06:40:45 +00004382 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004383 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4384 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004385 if (!Member)
4386 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
John McCall16df1e52010-03-30 21:47:33 +00004388 NamedDecl *FoundDecl = E->getFoundDecl();
4389 if (FoundDecl == E->getMemberDecl()) {
4390 FoundDecl = Member;
4391 } else {
4392 FoundDecl = cast_or_null<NamedDecl>(
4393 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4394 if (!FoundDecl)
4395 return SemaRef.ExprError();
4396 }
4397
Douglas Gregora16548e2009-08-11 05:31:07 +00004398 if (!getDerived().AlwaysRebuild() &&
4399 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004400 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004401 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004402 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004403 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004404
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004405 // Mark it referenced in the new context regardless.
4406 // FIXME: this is a bit instantiation-specific.
4407 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004408 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004409 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004410
John McCall6b51f282009-11-23 01:53:49 +00004411 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004412 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004413 TransArgs.setLAngleLoc(E->getLAngleLoc());
4414 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004415 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004416 TemplateArgumentLoc Loc;
4417 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004418 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004419 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004420 }
4421 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004422
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 // FIXME: Bogus source location for the operator
4424 SourceLocation FakeOperatorLoc
4425 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4426
John McCall38836f02010-01-15 08:34:02 +00004427 // FIXME: to do this check properly, we will need to preserve the
4428 // first-qualifier-in-scope here, just in case we had a dependent
4429 // base (and therefore couldn't do the check) and a
4430 // nested-name-qualifier (and therefore could do the lookup).
4431 NamedDecl *FirstQualifierInScope = 0;
4432
Douglas Gregora16548e2009-08-11 05:31:07 +00004433 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4434 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004435 Qualifier,
4436 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004438 Member,
John McCall16df1e52010-03-30 21:47:33 +00004439 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004440 (E->hasExplicitTemplateArgumentList()
4441 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004442 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004443}
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004446Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004447TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4449 if (LHS.isInvalid())
4450 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004451
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4453 if (RHS.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 if (!getDerived().AlwaysRebuild() &&
4457 LHS.get() == E->getLHS() &&
4458 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004459 return SemaRef.Owned(E->Retain());
4460
Douglas Gregora16548e2009-08-11 05:31:07 +00004461 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4462 move(LHS), move(RHS));
4463}
4464
Mike Stump11289f42009-09-09 15:08:12 +00004465template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004466Sema::OwningExprResult
4467TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004468 CompoundAssignOperator *E) {
4469 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004470}
Mike Stump11289f42009-09-09 15:08:12 +00004471
Douglas Gregora16548e2009-08-11 05:31:07 +00004472template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004473Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004474TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4476 if (Cond.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4480 if (LHS.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4484 if (RHS.isInvalid())
4485 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 if (!getDerived().AlwaysRebuild() &&
4488 Cond.get() == E->getCond() &&
4489 LHS.get() == E->getLHS() &&
4490 RHS.get() == E->getRHS())
4491 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004492
4493 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004494 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004495 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004496 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004497 move(RHS));
4498}
Mike Stump11289f42009-09-09 15:08:12 +00004499
4500template<typename Derived>
4501Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004502TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004503 // Implicit casts are eliminated during transformation, since they
4504 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004505 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004506}
Mike Stump11289f42009-09-09 15:08:12 +00004507
Douglas Gregora16548e2009-08-11 05:31:07 +00004508template<typename Derived>
4509Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004510TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004511 TypeSourceInfo *OldT;
4512 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004513 {
4514 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004515 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4517 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004518
John McCall97513962010-01-15 18:39:57 +00004519 OldT = E->getTypeInfoAsWritten();
4520 NewT = getDerived().TransformType(OldT);
4521 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004522 return SemaRef.ExprError();
4523 }
Mike Stump11289f42009-09-09 15:08:12 +00004524
Douglas Gregor6131b442009-12-12 18:16:41 +00004525 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004526 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004527 if (SubExpr.isInvalid())
4528 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004529
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004531 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004532 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004533 return SemaRef.Owned(E->Retain());
4534
John McCall97513962010-01-15 18:39:57 +00004535 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4536 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004537 E->getRParenLoc(),
4538 move(SubExpr));
4539}
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004542Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004543TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004544 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4545 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4546 if (!NewT)
4547 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4550 if (Init.isInvalid())
4551 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004554 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004556 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004557
John McCall5d7aa7f2010-01-19 22:33:45 +00004558 // Note: the expression type doesn't necessarily match the
4559 // type-as-written, but that's okay, because it should always be
4560 // derivable from the initializer.
4561
John McCalle15bbff2010-01-18 19:35:47 +00004562 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004563 /*FIXME:*/E->getInitializer()->getLocEnd(),
4564 move(Init));
4565}
Mike Stump11289f42009-09-09 15:08:12 +00004566
Douglas Gregora16548e2009-08-11 05:31:07 +00004567template<typename Derived>
4568Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004569TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4571 if (Base.isInvalid())
4572 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004573
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 if (!getDerived().AlwaysRebuild() &&
4575 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004576 return SemaRef.Owned(E->Retain());
4577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004579 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4581 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4582 E->getAccessorLoc(),
4583 E->getAccessor());
4584}
Mike Stump11289f42009-09-09 15:08:12 +00004585
Douglas Gregora16548e2009-08-11 05:31:07 +00004586template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004587Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004588TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004589 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004590
Douglas Gregora16548e2009-08-11 05:31:07 +00004591 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4592 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4593 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4594 if (Init.isInvalid())
4595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004596
Douglas Gregora16548e2009-08-11 05:31:07 +00004597 InitChanged = InitChanged || Init.get() != E->getInit(I);
4598 Inits.push_back(Init.takeAs<Expr>());
4599 }
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004602 return SemaRef.Owned(E->Retain());
4603
Douglas Gregora16548e2009-08-11 05:31:07 +00004604 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004605 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004606}
Mike Stump11289f42009-09-09 15:08:12 +00004607
Douglas Gregora16548e2009-08-11 05:31:07 +00004608template<typename Derived>
4609Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004610TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004611 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004612
Douglas Gregorebe10102009-08-20 07:17:43 +00004613 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004614 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4615 if (Init.isInvalid())
4616 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregorebe10102009-08-20 07:17:43 +00004618 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004619 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4620 bool ExprChanged = false;
4621 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4622 DEnd = E->designators_end();
4623 D != DEnd; ++D) {
4624 if (D->isFieldDesignator()) {
4625 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4626 D->getDotLoc(),
4627 D->getFieldLoc()));
4628 continue;
4629 }
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 if (D->isArrayDesignator()) {
4632 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4633 if (Index.isInvalid())
4634 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004635
4636 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004637 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004638
Douglas Gregora16548e2009-08-11 05:31:07 +00004639 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4640 ArrayExprs.push_back(Index.release());
4641 continue;
4642 }
Mike Stump11289f42009-09-09 15:08:12 +00004643
Douglas Gregora16548e2009-08-11 05:31:07 +00004644 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004645 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4647 if (Start.isInvalid())
4648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4651 if (End.isInvalid())
4652 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004653
4654 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004655 End.get(),
4656 D->getLBracketLoc(),
4657 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004658
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4660 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004661
Douglas Gregora16548e2009-08-11 05:31:07 +00004662 ArrayExprs.push_back(Start.release());
4663 ArrayExprs.push_back(End.release());
4664 }
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 if (!getDerived().AlwaysRebuild() &&
4667 Init.get() == E->getInit() &&
4668 !ExprChanged)
4669 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4672 E->getEqualOrColonLoc(),
4673 E->usesGNUSyntax(), move(Init));
4674}
Mike Stump11289f42009-09-09 15:08:12 +00004675
Douglas Gregora16548e2009-08-11 05:31:07 +00004676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004677Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004678TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004679 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004680 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004681
Douglas Gregor3da3c062009-10-28 00:29:27 +00004682 // FIXME: Will we ever have proper type location here? Will we actually
4683 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 QualType T = getDerived().TransformType(E->getType());
4685 if (T.isNull())
4686 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004687
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 if (!getDerived().AlwaysRebuild() &&
4689 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004690 return SemaRef.Owned(E->Retain());
4691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 return getDerived().RebuildImplicitValueInitExpr(T);
4693}
Mike Stump11289f42009-09-09 15:08:12 +00004694
Douglas Gregora16548e2009-08-11 05:31:07 +00004695template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004696Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004697TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004698 // FIXME: Do we want the type as written?
4699 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 {
4702 // FIXME: Source location isn't quite accurate.
4703 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4704 T = getDerived().TransformType(E->getType());
4705 if (T.isNull())
4706 return SemaRef.ExprError();
4707 }
Mike Stump11289f42009-09-09 15:08:12 +00004708
Douglas Gregora16548e2009-08-11 05:31:07 +00004709 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4710 if (SubExpr.isInvalid())
4711 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 if (!getDerived().AlwaysRebuild() &&
4714 T == E->getType() &&
4715 SubExpr.get() == E->getSubExpr())
4716 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004717
Douglas Gregora16548e2009-08-11 05:31:07 +00004718 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4719 T, E->getRParenLoc());
4720}
4721
4722template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004723Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004724TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004725 bool ArgumentChanged = false;
4726 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4727 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4728 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4729 if (Init.isInvalid())
4730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4733 Inits.push_back(Init.takeAs<Expr>());
4734 }
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4737 move_arg(Inits),
4738 E->getRParenLoc());
4739}
Mike Stump11289f42009-09-09 15:08:12 +00004740
Douglas Gregora16548e2009-08-11 05:31:07 +00004741/// \brief Transform an address-of-label expression.
4742///
4743/// By default, the transformation of an address-of-label expression always
4744/// rebuilds the expression, so that the label identifier can be resolved to
4745/// the corresponding label statement by semantic analysis.
4746template<typename Derived>
4747Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004748TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004749 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4750 E->getLabel());
4751}
Mike Stump11289f42009-09-09 15:08:12 +00004752
4753template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004754Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004755TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004756 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004757 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4758 if (SubStmt.isInvalid())
4759 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004760
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 if (!getDerived().AlwaysRebuild() &&
4762 SubStmt.get() == E->getSubStmt())
4763 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004764
4765 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004766 move(SubStmt),
4767 E->getRParenLoc());
4768}
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770template<typename Derived>
4771Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004772TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004773 QualType T1, T2;
4774 {
4775 // FIXME: Source location isn't quite accurate.
4776 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregora16548e2009-08-11 05:31:07 +00004778 T1 = getDerived().TransformType(E->getArgType1());
4779 if (T1.isNull())
4780 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 T2 = getDerived().TransformType(E->getArgType2());
4783 if (T2.isNull())
4784 return SemaRef.ExprError();
4785 }
4786
4787 if (!getDerived().AlwaysRebuild() &&
4788 T1 == E->getArgType1() &&
4789 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004790 return SemaRef.Owned(E->Retain());
4791
Douglas Gregora16548e2009-08-11 05:31:07 +00004792 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4793 T1, T2, E->getRParenLoc());
4794}
Mike Stump11289f42009-09-09 15:08:12 +00004795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796template<typename Derived>
4797Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004798TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4800 if (Cond.isInvalid())
4801 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4804 if (LHS.isInvalid())
4805 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4808 if (RHS.isInvalid())
4809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 if (!getDerived().AlwaysRebuild() &&
4812 Cond.get() == E->getCond() &&
4813 LHS.get() == E->getLHS() &&
4814 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004815 return SemaRef.Owned(E->Retain());
4816
Douglas Gregora16548e2009-08-11 05:31:07 +00004817 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4818 move(Cond), move(LHS), move(RHS),
4819 E->getRParenLoc());
4820}
Mike Stump11289f42009-09-09 15:08:12 +00004821
Douglas Gregora16548e2009-08-11 05:31:07 +00004822template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004823Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004824TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004825 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004826}
4827
4828template<typename Derived>
4829Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004830TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004831 switch (E->getOperator()) {
4832 case OO_New:
4833 case OO_Delete:
4834 case OO_Array_New:
4835 case OO_Array_Delete:
4836 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4837 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004838
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004839 case OO_Call: {
4840 // This is a call to an object's operator().
4841 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4842
4843 // Transform the object itself.
4844 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4845 if (Object.isInvalid())
4846 return SemaRef.ExprError();
4847
4848 // FIXME: Poor location information
4849 SourceLocation FakeLParenLoc
4850 = SemaRef.PP.getLocForEndOfToken(
4851 static_cast<Expr *>(Object.get())->getLocEnd());
4852
4853 // Transform the call arguments.
4854 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4855 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4856 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004857 if (getDerived().DropCallArgument(E->getArg(I)))
4858 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004859
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004860 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4861 if (Arg.isInvalid())
4862 return SemaRef.ExprError();
4863
4864 // FIXME: Poor source location information.
4865 SourceLocation FakeCommaLoc
4866 = SemaRef.PP.getLocForEndOfToken(
4867 static_cast<Expr *>(Arg.get())->getLocEnd());
4868 FakeCommaLocs.push_back(FakeCommaLoc);
4869 Args.push_back(Arg.release());
4870 }
4871
4872 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4873 move_arg(Args),
4874 FakeCommaLocs.data(),
4875 E->getLocEnd());
4876 }
4877
4878#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4879 case OO_##Name:
4880#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4881#include "clang/Basic/OperatorKinds.def"
4882 case OO_Subscript:
4883 // Handled below.
4884 break;
4885
4886 case OO_Conditional:
4887 llvm_unreachable("conditional operator is not actually overloadable");
4888 return SemaRef.ExprError();
4889
4890 case OO_None:
4891 case NUM_OVERLOADED_OPERATORS:
4892 llvm_unreachable("not an overloaded operator?");
4893 return SemaRef.ExprError();
4894 }
4895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4897 if (Callee.isInvalid())
4898 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004899
John McCall47f29ea2009-12-08 09:21:05 +00004900 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004901 if (First.isInvalid())
4902 return SemaRef.ExprError();
4903
4904 OwningExprResult Second(SemaRef);
4905 if (E->getNumArgs() == 2) {
4906 Second = getDerived().TransformExpr(E->getArg(1));
4907 if (Second.isInvalid())
4908 return SemaRef.ExprError();
4909 }
Mike Stump11289f42009-09-09 15:08:12 +00004910
Douglas Gregora16548e2009-08-11 05:31:07 +00004911 if (!getDerived().AlwaysRebuild() &&
4912 Callee.get() == E->getCallee() &&
4913 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004914 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4915 return SemaRef.Owned(E->Retain());
4916
Douglas Gregora16548e2009-08-11 05:31:07 +00004917 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4918 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004919 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004920 move(First),
4921 move(Second));
4922}
Mike Stump11289f42009-09-09 15:08:12 +00004923
Douglas Gregora16548e2009-08-11 05:31:07 +00004924template<typename Derived>
4925Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004926TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4927 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004928}
Mike Stump11289f42009-09-09 15:08:12 +00004929
Douglas Gregora16548e2009-08-11 05:31:07 +00004930template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004931Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004932TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004933 TypeSourceInfo *OldT;
4934 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004935 {
4936 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004937 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004938 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4939 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004940
John McCall97513962010-01-15 18:39:57 +00004941 OldT = E->getTypeInfoAsWritten();
4942 NewT = getDerived().TransformType(OldT);
4943 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 return SemaRef.ExprError();
4945 }
Mike Stump11289f42009-09-09 15:08:12 +00004946
Douglas Gregor6131b442009-12-12 18:16:41 +00004947 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004948 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 if (SubExpr.isInvalid())
4950 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004951
Douglas Gregora16548e2009-08-11 05:31:07 +00004952 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004953 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004954 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004955 return SemaRef.Owned(E->Retain());
4956
Douglas Gregora16548e2009-08-11 05:31:07 +00004957 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004958 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004959 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4960 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4961 SourceLocation FakeRParenLoc
4962 = SemaRef.PP.getLocForEndOfToken(
4963 E->getSubExpr()->getSourceRange().getEnd());
4964 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004965 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004966 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004967 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004968 FakeRAngleLoc,
4969 FakeRAngleLoc,
4970 move(SubExpr),
4971 FakeRParenLoc);
4972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
Douglas Gregora16548e2009-08-11 05:31:07 +00004974template<typename Derived>
4975Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004976TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4977 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
4980template<typename Derived>
4981Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004982TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4983 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004984}
4985
Douglas Gregora16548e2009-08-11 05:31:07 +00004986template<typename Derived>
4987Sema::OwningExprResult
4988TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004989 CXXReinterpretCastExpr *E) {
4990 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004991}
Mike Stump11289f42009-09-09 15:08:12 +00004992
Douglas Gregora16548e2009-08-11 05:31:07 +00004993template<typename Derived>
4994Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004995TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4996 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
Douglas Gregora16548e2009-08-11 05:31:07 +00004999template<typename Derived>
5000Sema::OwningExprResult
5001TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005002 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005003 TypeSourceInfo *OldT;
5004 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005005 {
5006 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005007
John McCall97513962010-01-15 18:39:57 +00005008 OldT = E->getTypeInfoAsWritten();
5009 NewT = getDerived().TransformType(OldT);
5010 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 return SemaRef.ExprError();
5012 }
Mike Stump11289f42009-09-09 15:08:12 +00005013
Douglas Gregor6131b442009-12-12 18:16:41 +00005014 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005015 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005016 if (SubExpr.isInvalid())
5017 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005018
Douglas Gregora16548e2009-08-11 05:31:07 +00005019 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005020 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005021 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005022 return SemaRef.Owned(E->Retain());
5023
Douglas Gregora16548e2009-08-11 05:31:07 +00005024 // FIXME: The end of the type's source range is wrong
5025 return getDerived().RebuildCXXFunctionalCastExpr(
5026 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005027 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 /*FIXME:*/E->getSubExpr()->getLocStart(),
5029 move(SubExpr),
5030 E->getRParenLoc());
5031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregora16548e2009-08-11 05:31:07 +00005033template<typename Derived>
5034Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005035TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005037 TypeSourceInfo *TInfo
5038 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5039 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005041
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005043 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregor9da64192010-04-26 22:37:10 +00005046 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5047 E->getLocStart(),
5048 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005049 E->getLocEnd());
5050 }
Mike Stump11289f42009-09-09 15:08:12 +00005051
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 // We don't know whether the expression is potentially evaluated until
5053 // after we perform semantic analysis, so the expression is potentially
5054 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005055 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregora16548e2009-08-11 05:31:07 +00005058 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5059 if (SubExpr.isInvalid())
5060 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 if (!getDerived().AlwaysRebuild() &&
5063 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005064 return SemaRef.Owned(E->Retain());
5065
Douglas Gregor9da64192010-04-26 22:37:10 +00005066 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5067 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005068 move(SubExpr),
5069 E->getLocEnd());
5070}
5071
5072template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005073Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005074TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005075 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005076}
Mike Stump11289f42009-09-09 15:08:12 +00005077
Douglas Gregora16548e2009-08-11 05:31:07 +00005078template<typename Derived>
5079Sema::OwningExprResult
5080TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005081 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005082 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005083}
Mike Stump11289f42009-09-09 15:08:12 +00005084
Douglas Gregora16548e2009-08-11 05:31:07 +00005085template<typename Derived>
5086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005087TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005088 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregora16548e2009-08-11 05:31:07 +00005090 QualType T = getDerived().TransformType(E->getType());
5091 if (T.isNull())
5092 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 if (!getDerived().AlwaysRebuild() &&
5095 T == E->getType())
5096 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregorb15af892010-01-07 23:12:05 +00005098 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005099}
Mike Stump11289f42009-09-09 15:08:12 +00005100
Douglas Gregora16548e2009-08-11 05:31:07 +00005101template<typename Derived>
5102Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005103TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5105 if (SubExpr.isInvalid())
5106 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005107
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 if (!getDerived().AlwaysRebuild() &&
5109 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005110 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005111
5112 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5113}
Mike Stump11289f42009-09-09 15:08:12 +00005114
Douglas Gregora16548e2009-08-11 05:31:07 +00005115template<typename Derived>
5116Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005117TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005118 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005119 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5120 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 if (!Param)
5122 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005123
Chandler Carruth794da4c2010-02-08 06:42:49 +00005124 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 Param == E->getParam())
5126 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005127
Douglas Gregor033f6752009-12-23 23:03:06 +00005128 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005129}
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131template<typename Derived>
5132Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005133TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005134 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5135
5136 QualType T = getDerived().TransformType(E->getType());
5137 if (T.isNull())
5138 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005139
Douglas Gregora16548e2009-08-11 05:31:07 +00005140 if (!getDerived().AlwaysRebuild() &&
5141 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005142 return SemaRef.Owned(E->Retain());
5143
5144 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 /*FIXME:*/E->getTypeBeginLoc(),
5146 T,
5147 E->getRParenLoc());
5148}
Mike Stump11289f42009-09-09 15:08:12 +00005149
Douglas Gregora16548e2009-08-11 05:31:07 +00005150template<typename Derived>
5151Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005152TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005153 // Transform the type that we're allocating
5154 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5155 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5156 if (AllocType.isNull())
5157 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005158
Douglas Gregora16548e2009-08-11 05:31:07 +00005159 // Transform the size of the array we're allocating (if any).
5160 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5161 if (ArraySize.isInvalid())
5162 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 // Transform the placement arguments (if any).
5165 bool ArgumentChanged = false;
5166 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5167 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5168 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5169 if (Arg.isInvalid())
5170 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005171
Douglas Gregora16548e2009-08-11 05:31:07 +00005172 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5173 PlacementArgs.push_back(Arg.take());
5174 }
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregorebe10102009-08-20 07:17:43 +00005176 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005177 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5178 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5179 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5180 if (Arg.isInvalid())
5181 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5184 ConstructorArgs.push_back(Arg.take());
5185 }
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregord2d9da02010-02-26 00:38:10 +00005187 // Transform constructor, new operator, and delete operator.
5188 CXXConstructorDecl *Constructor = 0;
5189 if (E->getConstructor()) {
5190 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005191 getDerived().TransformDecl(E->getLocStart(),
5192 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005193 if (!Constructor)
5194 return SemaRef.ExprError();
5195 }
5196
5197 FunctionDecl *OperatorNew = 0;
5198 if (E->getOperatorNew()) {
5199 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005200 getDerived().TransformDecl(E->getLocStart(),
5201 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005202 if (!OperatorNew)
5203 return SemaRef.ExprError();
5204 }
5205
5206 FunctionDecl *OperatorDelete = 0;
5207 if (E->getOperatorDelete()) {
5208 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005209 getDerived().TransformDecl(E->getLocStart(),
5210 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005211 if (!OperatorDelete)
5212 return SemaRef.ExprError();
5213 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005214
Douglas Gregora16548e2009-08-11 05:31:07 +00005215 if (!getDerived().AlwaysRebuild() &&
5216 AllocType == E->getAllocatedType() &&
5217 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005218 Constructor == E->getConstructor() &&
5219 OperatorNew == E->getOperatorNew() &&
5220 OperatorDelete == E->getOperatorDelete() &&
5221 !ArgumentChanged) {
5222 // Mark any declarations we need as referenced.
5223 // FIXME: instantiation-specific.
5224 if (Constructor)
5225 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5226 if (OperatorNew)
5227 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5228 if (OperatorDelete)
5229 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005230 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005231 }
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005233 if (!ArraySize.get()) {
5234 // If no array size was specified, but the new expression was
5235 // instantiated with an array type (e.g., "new T" where T is
5236 // instantiated with "int[4]"), extract the outer bound from the
5237 // array type as our array size. We do this with constant and
5238 // dependently-sized array types.
5239 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5240 if (!ArrayT) {
5241 // Do nothing
5242 } else if (const ConstantArrayType *ConsArrayT
5243 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005244 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005245 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005246 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005247 SemaRef.Context.getSizeType(),
5248 /*FIXME:*/E->getLocStart()));
5249 AllocType = ConsArrayT->getElementType();
5250 } else if (const DependentSizedArrayType *DepArrayT
5251 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5252 if (DepArrayT->getSizeExpr()) {
5253 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5254 AllocType = DepArrayT->getElementType();
5255 }
5256 }
5257 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5259 E->isGlobalNew(),
5260 /*FIXME:*/E->getLocStart(),
5261 move_arg(PlacementArgs),
5262 /*FIXME:*/E->getLocStart(),
5263 E->isParenTypeId(),
5264 AllocType,
5265 /*FIXME:*/E->getLocStart(),
5266 /*FIXME:*/SourceRange(),
5267 move(ArraySize),
5268 /*FIXME:*/E->getLocStart(),
5269 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005270 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005271}
Mike Stump11289f42009-09-09 15:08:12 +00005272
Douglas Gregora16548e2009-08-11 05:31:07 +00005273template<typename Derived>
5274Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005275TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005276 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5277 if (Operand.isInvalid())
5278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregord2d9da02010-02-26 00:38:10 +00005280 // Transform the delete operator, if known.
5281 FunctionDecl *OperatorDelete = 0;
5282 if (E->getOperatorDelete()) {
5283 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005284 getDerived().TransformDecl(E->getLocStart(),
5285 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005286 if (!OperatorDelete)
5287 return SemaRef.ExprError();
5288 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005289
Douglas Gregora16548e2009-08-11 05:31:07 +00005290 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005291 Operand.get() == E->getArgument() &&
5292 OperatorDelete == E->getOperatorDelete()) {
5293 // Mark any declarations we need as referenced.
5294 // FIXME: instantiation-specific.
5295 if (OperatorDelete)
5296 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005297 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005298 }
Mike Stump11289f42009-09-09 15:08:12 +00005299
Douglas Gregora16548e2009-08-11 05:31:07 +00005300 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5301 E->isGlobalDelete(),
5302 E->isArrayForm(),
5303 move(Operand));
5304}
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregora16548e2009-08-11 05:31:07 +00005306template<typename Derived>
5307Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005308TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005309 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005310 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5311 if (Base.isInvalid())
5312 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005313
Douglas Gregor678f90d2010-02-25 01:56:36 +00005314 Sema::TypeTy *ObjectTypePtr = 0;
5315 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005316 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005317 E->getOperatorLoc(),
5318 E->isArrow()? tok::arrow : tok::period,
5319 ObjectTypePtr,
5320 MayBePseudoDestructor);
5321 if (Base.isInvalid())
5322 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005323
Douglas Gregor678f90d2010-02-25 01:56:36 +00005324 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005325 NestedNameSpecifier *Qualifier
5326 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005327 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005328 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005329 if (E->getQualifier() && !Qualifier)
5330 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005331
Douglas Gregor678f90d2010-02-25 01:56:36 +00005332 PseudoDestructorTypeStorage Destroyed;
5333 if (E->getDestroyedTypeInfo()) {
5334 TypeSourceInfo *DestroyedTypeInfo
5335 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5336 if (!DestroyedTypeInfo)
5337 return SemaRef.ExprError();
5338 Destroyed = DestroyedTypeInfo;
5339 } else if (ObjectType->isDependentType()) {
5340 // We aren't likely to be able to resolve the identifier down to a type
5341 // now anyway, so just retain the identifier.
5342 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5343 E->getDestroyedTypeLoc());
5344 } else {
5345 // Look for a destructor known with the given name.
5346 CXXScopeSpec SS;
5347 if (Qualifier) {
5348 SS.setScopeRep(Qualifier);
5349 SS.setRange(E->getQualifierRange());
5350 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005351
Douglas Gregor678f90d2010-02-25 01:56:36 +00005352 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5353 *E->getDestroyedTypeIdentifier(),
5354 E->getDestroyedTypeLoc(),
5355 /*Scope=*/0,
5356 SS, ObjectTypePtr,
5357 false);
5358 if (!T)
5359 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360
Douglas Gregor678f90d2010-02-25 01:56:36 +00005361 Destroyed
5362 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5363 E->getDestroyedTypeLoc());
5364 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005365
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005366 TypeSourceInfo *ScopeTypeInfo = 0;
5367 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005368 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005369 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005370 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005371 return SemaRef.ExprError();
5372 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005373
Douglas Gregorad8a3362009-09-04 17:36:40 +00005374 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5375 E->getOperatorLoc(),
5376 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005377 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005378 E->getQualifierRange(),
5379 ScopeTypeInfo,
5380 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005381 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005382 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005383}
Mike Stump11289f42009-09-09 15:08:12 +00005384
Douglas Gregorad8a3362009-09-04 17:36:40 +00005385template<typename Derived>
5386Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005387TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005388 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005389 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5390
5391 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5392 Sema::LookupOrdinaryName);
5393
5394 // Transform all the decls.
5395 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5396 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005397 NamedDecl *InstD = static_cast<NamedDecl*>(
5398 getDerived().TransformDecl(Old->getNameLoc(),
5399 *I));
John McCall84d87672009-12-10 09:41:52 +00005400 if (!InstD) {
5401 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5402 // This can happen because of dependent hiding.
5403 if (isa<UsingShadowDecl>(*I))
5404 continue;
5405 else
5406 return SemaRef.ExprError();
5407 }
John McCalle66edc12009-11-24 19:00:30 +00005408
5409 // Expand using declarations.
5410 if (isa<UsingDecl>(InstD)) {
5411 UsingDecl *UD = cast<UsingDecl>(InstD);
5412 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5413 E = UD->shadow_end(); I != E; ++I)
5414 R.addDecl(*I);
5415 continue;
5416 }
5417
5418 R.addDecl(InstD);
5419 }
5420
5421 // Resolve a kind, but don't do any further analysis. If it's
5422 // ambiguous, the callee needs to deal with it.
5423 R.resolveKind();
5424
5425 // Rebuild the nested-name qualifier, if present.
5426 CXXScopeSpec SS;
5427 NestedNameSpecifier *Qualifier = 0;
5428 if (Old->getQualifier()) {
5429 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005430 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005431 if (!Qualifier)
5432 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005433
John McCalle66edc12009-11-24 19:00:30 +00005434 SS.setScopeRep(Qualifier);
5435 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005436 }
5437
Douglas Gregor9262f472010-04-27 18:19:34 +00005438 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005439 CXXRecordDecl *NamingClass
5440 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5441 Old->getNameLoc(),
5442 Old->getNamingClass()));
5443 if (!NamingClass)
5444 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005445
Douglas Gregorda7be082010-04-27 16:10:10 +00005446 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005447 }
5448
5449 // If we have no template arguments, it's a normal declaration name.
5450 if (!Old->hasExplicitTemplateArgs())
5451 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5452
5453 // If we have template arguments, rebuild them, then rebuild the
5454 // templateid expression.
5455 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5456 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5457 TemplateArgumentLoc Loc;
5458 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5459 return SemaRef.ExprError();
5460 TransArgs.addArgument(Loc);
5461 }
5462
5463 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5464 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005465}
Mike Stump11289f42009-09-09 15:08:12 +00005466
Douglas Gregora16548e2009-08-11 05:31:07 +00005467template<typename Derived>
5468Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005469TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005470 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005471
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 QualType T = getDerived().TransformType(E->getQueriedType());
5473 if (T.isNull())
5474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 if (!getDerived().AlwaysRebuild() &&
5477 T == E->getQueriedType())
5478 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregora16548e2009-08-11 05:31:07 +00005480 // FIXME: Bad location information
5481 SourceLocation FakeLParenLoc
5482 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005483
5484 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005485 E->getLocStart(),
5486 /*FIXME:*/FakeLParenLoc,
5487 T,
5488 E->getLocEnd());
5489}
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491template<typename Derived>
5492Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005493TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005494 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005495 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005496 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005497 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005498 if (!NNS)
5499 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005500
5501 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005502 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5503 if (!Name)
5504 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005505
John McCalle66edc12009-11-24 19:00:30 +00005506 if (!E->hasExplicitTemplateArgs()) {
5507 if (!getDerived().AlwaysRebuild() &&
5508 NNS == E->getQualifier() &&
5509 Name == E->getDeclName())
5510 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005511
John McCalle66edc12009-11-24 19:00:30 +00005512 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5513 E->getQualifierRange(),
5514 Name, E->getLocation(),
5515 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005516 }
John McCall6b51f282009-11-23 01:53:49 +00005517
5518 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005519 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005520 TemplateArgumentLoc Loc;
5521 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005522 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005523 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005524 }
5525
John McCalle66edc12009-11-24 19:00:30 +00005526 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5527 E->getQualifierRange(),
5528 Name, E->getLocation(),
5529 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005530}
5531
5532template<typename Derived>
5533Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005534TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005535 // CXXConstructExprs are always implicit, so when we have a
5536 // 1-argument construction we just transform that argument.
5537 if (E->getNumArgs() == 1 ||
5538 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5539 return getDerived().TransformExpr(E->getArg(0));
5540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5542
5543 QualType T = getDerived().TransformType(E->getType());
5544 if (T.isNull())
5545 return SemaRef.ExprError();
5546
5547 CXXConstructorDecl *Constructor
5548 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005549 getDerived().TransformDecl(E->getLocStart(),
5550 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005551 if (!Constructor)
5552 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005553
Douglas Gregora16548e2009-08-11 05:31:07 +00005554 bool ArgumentChanged = false;
5555 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005556 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005557 ArgEnd = E->arg_end();
5558 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005559 if (getDerived().DropCallArgument(*Arg)) {
5560 ArgumentChanged = true;
5561 break;
5562 }
5563
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5565 if (TransArg.isInvalid())
5566 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5569 Args.push_back(TransArg.takeAs<Expr>());
5570 }
5571
5572 if (!getDerived().AlwaysRebuild() &&
5573 T == E->getType() &&
5574 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005575 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005576 // Mark the constructor as referenced.
5577 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005578 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005580 }
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregordb121ba2009-12-14 16:27:04 +00005582 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5583 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 move_arg(Args));
5585}
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587/// \brief Transform a C++ temporary-binding expression.
5588///
Douglas Gregor363b1512009-12-24 18:51:59 +00005589/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5590/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005591template<typename Derived>
5592Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005593TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005594 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005595}
Mike Stump11289f42009-09-09 15:08:12 +00005596
Anders Carlssonba6c4372010-01-29 02:39:32 +00005597/// \brief Transform a C++ reference-binding expression.
5598///
5599/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5600/// transform the subexpression and return that.
5601template<typename Derived>
5602Sema::OwningExprResult
5603TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5604 return getDerived().TransformExpr(E->getSubExpr());
5605}
5606
Mike Stump11289f42009-09-09 15:08:12 +00005607/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005608/// be destroyed after the expression is evaluated.
5609///
Douglas Gregor363b1512009-12-24 18:51:59 +00005610/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5611/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005612template<typename Derived>
5613Sema::OwningExprResult
5614TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005615 CXXExprWithTemporaries *E) {
5616 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005617}
Mike Stump11289f42009-09-09 15:08:12 +00005618
Douglas Gregora16548e2009-08-11 05:31:07 +00005619template<typename Derived>
5620Sema::OwningExprResult
5621TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005622 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005623 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5624 QualType T = getDerived().TransformType(E->getType());
5625 if (T.isNull())
5626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628 CXXConstructorDecl *Constructor
5629 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005630 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005631 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 if (!Constructor)
5633 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
Douglas Gregora16548e2009-08-11 05:31:07 +00005635 bool ArgumentChanged = false;
5636 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5637 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005638 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 ArgEnd = E->arg_end();
5640 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005641 if (getDerived().DropCallArgument(*Arg)) {
5642 ArgumentChanged = true;
5643 break;
5644 }
5645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5647 if (TransArg.isInvalid())
5648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5651 Args.push_back((Expr *)TransArg.release());
5652 }
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 if (!getDerived().AlwaysRebuild() &&
5655 T == E->getType() &&
5656 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005657 !ArgumentChanged) {
5658 // FIXME: Instantiation-specific
5659 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005660 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005661 }
Mike Stump11289f42009-09-09 15:08:12 +00005662
Douglas Gregora16548e2009-08-11 05:31:07 +00005663 // FIXME: Bogus location information
5664 SourceLocation CommaLoc;
5665 if (Args.size() > 1) {
5666 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005667 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005668 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5669 }
5670 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5671 T,
5672 /*FIXME:*/E->getTypeBeginLoc(),
5673 move_arg(Args),
5674 &CommaLoc,
5675 E->getLocEnd());
5676}
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregora16548e2009-08-11 05:31:07 +00005678template<typename Derived>
5679Sema::OwningExprResult
5680TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005681 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5683 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5684 if (T.isNull())
5685 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005686
Douglas Gregora16548e2009-08-11 05:31:07 +00005687 bool ArgumentChanged = false;
5688 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5689 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5690 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5691 ArgEnd = E->arg_end();
5692 Arg != ArgEnd; ++Arg) {
5693 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5694 if (TransArg.isInvalid())
5695 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5698 FakeCommaLocs.push_back(
5699 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5700 Args.push_back(TransArg.takeAs<Expr>());
5701 }
Mike Stump11289f42009-09-09 15:08:12 +00005702
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 if (!getDerived().AlwaysRebuild() &&
5704 T == E->getTypeAsWritten() &&
5705 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005706 return SemaRef.Owned(E->Retain());
5707
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 // FIXME: we're faking the locations of the commas
5709 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5710 T,
5711 E->getLParenLoc(),
5712 move_arg(Args),
5713 FakeCommaLocs.data(),
5714 E->getRParenLoc());
5715}
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregora16548e2009-08-11 05:31:07 +00005717template<typename Derived>
5718Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005719TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005720 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005721 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005722 OwningExprResult Base(SemaRef, (Expr*) 0);
5723 Expr *OldBase;
5724 QualType BaseType;
5725 QualType ObjectType;
5726 if (!E->isImplicitAccess()) {
5727 OldBase = E->getBase();
5728 Base = getDerived().TransformExpr(OldBase);
5729 if (Base.isInvalid())
5730 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005731
John McCall2d74de92009-12-01 22:10:20 +00005732 // Start the member reference and compute the object's type.
5733 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005734 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005735 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5736 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005737 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005738 ObjectTy,
5739 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005740 if (Base.isInvalid())
5741 return SemaRef.ExprError();
5742
5743 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5744 BaseType = ((Expr*) Base.get())->getType();
5745 } else {
5746 OldBase = 0;
5747 BaseType = getDerived().TransformType(E->getBaseType());
5748 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5749 }
Mike Stump11289f42009-09-09 15:08:12 +00005750
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005751 // Transform the first part of the nested-name-specifier that qualifies
5752 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005753 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005754 = getDerived().TransformFirstQualifierInScope(
5755 E->getFirstQualifierFoundInScope(),
5756 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005757
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005758 NestedNameSpecifier *Qualifier = 0;
5759 if (E->getQualifier()) {
5760 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5761 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005762 ObjectType,
5763 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005764 if (!Qualifier)
5765 return SemaRef.ExprError();
5766 }
Mike Stump11289f42009-09-09 15:08:12 +00005767
5768 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005769 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005770 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005771 if (!Name)
5772 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005773
John McCall2d74de92009-12-01 22:10:20 +00005774 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005775 // This is a reference to a member without an explicitly-specified
5776 // template argument list. Optimize for this common case.
5777 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005778 Base.get() == OldBase &&
5779 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005780 Qualifier == E->getQualifier() &&
5781 Name == E->getMember() &&
5782 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005783 return SemaRef.Owned(E->Retain());
5784
John McCall8cd78132009-11-19 22:55:06 +00005785 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005786 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005787 E->isArrow(),
5788 E->getOperatorLoc(),
5789 Qualifier,
5790 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005791 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005792 Name,
5793 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005794 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005795 }
5796
John McCall6b51f282009-11-23 01:53:49 +00005797 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005798 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005799 TemplateArgumentLoc Loc;
5800 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005801 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005802 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005803 }
Mike Stump11289f42009-09-09 15:08:12 +00005804
John McCall8cd78132009-11-19 22:55:06 +00005805 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005806 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005807 E->isArrow(),
5808 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005809 Qualifier,
5810 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005811 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005812 Name,
5813 E->getMemberLoc(),
5814 &TransArgs);
5815}
5816
5817template<typename Derived>
5818Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005819TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005820 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005821 OwningExprResult Base(SemaRef, (Expr*) 0);
5822 QualType BaseType;
5823 if (!Old->isImplicitAccess()) {
5824 Base = getDerived().TransformExpr(Old->getBase());
5825 if (Base.isInvalid())
5826 return SemaRef.ExprError();
5827 BaseType = ((Expr*) Base.get())->getType();
5828 } else {
5829 BaseType = getDerived().TransformType(Old->getBaseType());
5830 }
John McCall10eae182009-11-30 22:42:35 +00005831
5832 NestedNameSpecifier *Qualifier = 0;
5833 if (Old->getQualifier()) {
5834 Qualifier
5835 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005836 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005837 if (Qualifier == 0)
5838 return SemaRef.ExprError();
5839 }
5840
5841 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5842 Sema::LookupOrdinaryName);
5843
5844 // Transform all the decls.
5845 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5846 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005847 NamedDecl *InstD = static_cast<NamedDecl*>(
5848 getDerived().TransformDecl(Old->getMemberLoc(),
5849 *I));
John McCall84d87672009-12-10 09:41:52 +00005850 if (!InstD) {
5851 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5852 // This can happen because of dependent hiding.
5853 if (isa<UsingShadowDecl>(*I))
5854 continue;
5855 else
5856 return SemaRef.ExprError();
5857 }
John McCall10eae182009-11-30 22:42:35 +00005858
5859 // Expand using declarations.
5860 if (isa<UsingDecl>(InstD)) {
5861 UsingDecl *UD = cast<UsingDecl>(InstD);
5862 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5863 E = UD->shadow_end(); I != E; ++I)
5864 R.addDecl(*I);
5865 continue;
5866 }
5867
5868 R.addDecl(InstD);
5869 }
5870
5871 R.resolveKind();
5872
Douglas Gregor9262f472010-04-27 18:19:34 +00005873 // Determine the naming class.
5874 if (!Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005875 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005876 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005877 Old->getMemberLoc(),
5878 Old->getNamingClass()));
5879 if (!NamingClass)
5880 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005881
Douglas Gregorda7be082010-04-27 16:10:10 +00005882 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005883 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005884
John McCall10eae182009-11-30 22:42:35 +00005885 TemplateArgumentListInfo TransArgs;
5886 if (Old->hasExplicitTemplateArgs()) {
5887 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5888 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5889 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5890 TemplateArgumentLoc Loc;
5891 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5892 Loc))
5893 return SemaRef.ExprError();
5894 TransArgs.addArgument(Loc);
5895 }
5896 }
John McCall38836f02010-01-15 08:34:02 +00005897
5898 // FIXME: to do this check properly, we will need to preserve the
5899 // first-qualifier-in-scope here, just in case we had a dependent
5900 // base (and therefore couldn't do the check) and a
5901 // nested-name-qualifier (and therefore could do the lookup).
5902 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005903
John McCall10eae182009-11-30 22:42:35 +00005904 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005905 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005906 Old->getOperatorLoc(),
5907 Old->isArrow(),
5908 Qualifier,
5909 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005910 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005911 R,
5912 (Old->hasExplicitTemplateArgs()
5913 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005914}
5915
5916template<typename Derived>
5917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005918TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005919 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005920}
5921
Mike Stump11289f42009-09-09 15:08:12 +00005922template<typename Derived>
5923Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005924TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005925 TypeSourceInfo *EncodedTypeInfo
5926 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5927 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005931 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005932 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005933
5934 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005935 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 E->getRParenLoc());
5937}
Mike Stump11289f42009-09-09 15:08:12 +00005938
Douglas Gregora16548e2009-08-11 05:31:07 +00005939template<typename Derived>
5940Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005941TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005942 // Transform arguments.
5943 bool ArgChanged = false;
5944 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5945 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5946 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5947 if (Arg.isInvalid())
5948 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005949
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005950 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5951 Args.push_back(Arg.takeAs<Expr>());
5952 }
5953
5954 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5955 // Class message: transform the receiver type.
5956 TypeSourceInfo *ReceiverTypeInfo
5957 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5958 if (!ReceiverTypeInfo)
5959 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005960
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005961 // If nothing changed, just retain the existing message send.
5962 if (!getDerived().AlwaysRebuild() &&
5963 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5964 return SemaRef.Owned(E->Retain());
5965
5966 // Build a new class message send.
5967 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5968 E->getSelector(),
5969 E->getMethodDecl(),
5970 E->getLeftLoc(),
5971 move_arg(Args),
5972 E->getRightLoc());
5973 }
5974
5975 // Instance message: transform the receiver
5976 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5977 "Only class and instance messages may be instantiated");
5978 OwningExprResult Receiver
5979 = getDerived().TransformExpr(E->getInstanceReceiver());
5980 if (Receiver.isInvalid())
5981 return SemaRef.ExprError();
5982
5983 // If nothing changed, just retain the existing message send.
5984 if (!getDerived().AlwaysRebuild() &&
5985 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5986 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005987
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005988 // Build a new instance message send.
5989 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5990 E->getSelector(),
5991 E->getMethodDecl(),
5992 E->getLeftLoc(),
5993 move_arg(Args),
5994 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995}
5996
Mike Stump11289f42009-09-09 15:08:12 +00005997template<typename Derived>
5998Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006000 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006001}
6002
Mike Stump11289f42009-09-09 15:08:12 +00006003template<typename Derived>
6004Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006006 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006007}
6008
Mike Stump11289f42009-09-09 15:08:12 +00006009template<typename Derived>
6010Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006011TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006012 // Transform the base expression.
6013 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6014 if (Base.isInvalid())
6015 return SemaRef.ExprError();
6016
6017 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006018
Douglas Gregord51d90d2010-04-26 20:11:03 +00006019 // If nothing changed, just retain the existing expression.
6020 if (!getDerived().AlwaysRebuild() &&
6021 Base.get() == E->getBase())
6022 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006023
Douglas Gregord51d90d2010-04-26 20:11:03 +00006024 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6025 E->getLocation(),
6026 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006027}
6028
Mike Stump11289f42009-09-09 15:08:12 +00006029template<typename Derived>
6030Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006031TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006032 // Transform the base expression.
6033 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6034 if (Base.isInvalid())
6035 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006036
Douglas Gregor9faee212010-04-26 20:47:02 +00006037 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006038
Douglas Gregor9faee212010-04-26 20:47:02 +00006039 // If nothing changed, just retain the existing expression.
6040 if (!getDerived().AlwaysRebuild() &&
6041 Base.get() == E->getBase())
6042 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006043
Douglas Gregor9faee212010-04-26 20:47:02 +00006044 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6045 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006046}
6047
Mike Stump11289f42009-09-09 15:08:12 +00006048template<typename Derived>
6049Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006050TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006051 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006052 // If this implicit setter/getter refers to class methods, it cannot have any
6053 // dependent parts. Just retain the existing declaration.
6054 if (E->getInterfaceDecl())
6055 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006056
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006057 // Transform the base expression.
6058 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6059 if (Base.isInvalid())
6060 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006061
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006062 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006063
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006064 // If nothing changed, just retain the existing expression.
6065 if (!getDerived().AlwaysRebuild() &&
6066 Base.get() == E->getBase())
6067 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006068
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006069 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6070 E->getGetterMethod(),
6071 E->getType(),
6072 E->getSetterMethod(),
6073 E->getLocation(),
6074 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006075
Douglas Gregora16548e2009-08-11 05:31:07 +00006076}
6077
Mike Stump11289f42009-09-09 15:08:12 +00006078template<typename Derived>
6079Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006080TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006081 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006082 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006083}
6084
Mike Stump11289f42009-09-09 15:08:12 +00006085template<typename Derived>
6086Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006087TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006088 // Transform the base expression.
6089 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6090 if (Base.isInvalid())
6091 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006092
Douglas Gregord51d90d2010-04-26 20:11:03 +00006093 // If nothing changed, just retain the existing expression.
6094 if (!getDerived().AlwaysRebuild() &&
6095 Base.get() == E->getBase())
6096 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006097
Douglas Gregord51d90d2010-04-26 20:11:03 +00006098 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6099 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006100}
6101
Mike Stump11289f42009-09-09 15:08:12 +00006102template<typename Derived>
6103Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006104TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006105 bool ArgumentChanged = false;
6106 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6107 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6108 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6109 if (SubExpr.isInvalid())
6110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006111
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6113 SubExprs.push_back(SubExpr.takeAs<Expr>());
6114 }
Mike Stump11289f42009-09-09 15:08:12 +00006115
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 if (!getDerived().AlwaysRebuild() &&
6117 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006118 return SemaRef.Owned(E->Retain());
6119
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6121 move_arg(SubExprs),
6122 E->getRParenLoc());
6123}
6124
Mike Stump11289f42009-09-09 15:08:12 +00006125template<typename Derived>
6126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 // FIXME: Implement this!
6129 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006130 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006131}
6132
Mike Stump11289f42009-09-09 15:08:12 +00006133template<typename Derived>
6134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006136 // FIXME: Implement this!
6137 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006138 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006139}
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregora16548e2009-08-11 05:31:07 +00006141//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006142// Type reconstruction
6143//===----------------------------------------------------------------------===//
6144
Mike Stump11289f42009-09-09 15:08:12 +00006145template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006146QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6147 SourceLocation Star) {
6148 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006149 getDerived().getBaseEntity());
6150}
6151
Mike Stump11289f42009-09-09 15:08:12 +00006152template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006153QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6154 SourceLocation Star) {
6155 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006156 getDerived().getBaseEntity());
6157}
6158
Mike Stump11289f42009-09-09 15:08:12 +00006159template<typename Derived>
6160QualType
John McCall70dd5f62009-10-30 00:06:24 +00006161TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6162 bool WrittenAsLValue,
6163 SourceLocation Sigil) {
6164 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6165 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006166}
6167
6168template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006169QualType
John McCall70dd5f62009-10-30 00:06:24 +00006170TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6171 QualType ClassType,
6172 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006173 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006174 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006175}
6176
6177template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006178QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006179TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6180 ArrayType::ArraySizeModifier SizeMod,
6181 const llvm::APInt *Size,
6182 Expr *SizeExpr,
6183 unsigned IndexTypeQuals,
6184 SourceRange BracketsRange) {
6185 if (SizeExpr || !Size)
6186 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6187 IndexTypeQuals, BracketsRange,
6188 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006189
6190 QualType Types[] = {
6191 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6192 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6193 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006194 };
6195 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6196 QualType SizeType;
6197 for (unsigned I = 0; I != NumTypes; ++I)
6198 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6199 SizeType = Types[I];
6200 break;
6201 }
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregord6ff3322009-08-04 16:50:30 +00006203 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006204 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006205 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006206 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006207}
Mike Stump11289f42009-09-09 15:08:12 +00006208
Douglas Gregord6ff3322009-08-04 16:50:30 +00006209template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006210QualType
6211TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006212 ArrayType::ArraySizeModifier SizeMod,
6213 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006214 unsigned IndexTypeQuals,
6215 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006216 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006217 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006218}
6219
6220template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006221QualType
Mike Stump11289f42009-09-09 15:08:12 +00006222TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006223 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006224 unsigned IndexTypeQuals,
6225 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006226 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006227 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006228}
Mike Stump11289f42009-09-09 15:08:12 +00006229
Douglas Gregord6ff3322009-08-04 16:50:30 +00006230template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006231QualType
6232TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006233 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006235 unsigned IndexTypeQuals,
6236 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006237 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006238 SizeExpr.takeAs<Expr>(),
6239 IndexTypeQuals, BracketsRange);
6240}
6241
6242template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006243QualType
6244TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006245 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006246 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006247 unsigned IndexTypeQuals,
6248 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006249 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006250 SizeExpr.takeAs<Expr>(),
6251 IndexTypeQuals, BracketsRange);
6252}
6253
6254template<typename Derived>
6255QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006256 unsigned NumElements,
6257 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006258 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006259 return SemaRef.Context.getVectorType(ElementType, NumElements,
6260 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006261}
Mike Stump11289f42009-09-09 15:08:12 +00006262
Douglas Gregord6ff3322009-08-04 16:50:30 +00006263template<typename Derived>
6264QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6265 unsigned NumElements,
6266 SourceLocation AttributeLoc) {
6267 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6268 NumElements, true);
6269 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006270 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006271 AttributeLoc);
6272 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6273 AttributeLoc);
6274}
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregord6ff3322009-08-04 16:50:30 +00006276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006277QualType
6278TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006280 SourceLocation AttributeLoc) {
6281 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregord6ff3322009-08-04 16:50:30 +00006284template<typename Derived>
6285QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006286 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006287 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006288 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006289 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006290 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006291 Quals,
6292 getDerived().getBaseLocation(),
6293 getDerived().getBaseEntity());
6294}
Mike Stump11289f42009-09-09 15:08:12 +00006295
Douglas Gregord6ff3322009-08-04 16:50:30 +00006296template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006297QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6298 return SemaRef.Context.getFunctionNoProtoType(T);
6299}
6300
6301template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006302QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6303 assert(D && "no decl found");
6304 if (D->isInvalidDecl()) return QualType();
6305
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006306 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006307 TypeDecl *Ty;
6308 if (isa<UsingDecl>(D)) {
6309 UsingDecl *Using = cast<UsingDecl>(D);
6310 assert(Using->isTypeName() &&
6311 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6312
6313 // A valid resolved using typename decl points to exactly one type decl.
6314 assert(++Using->shadow_begin() == Using->shadow_end());
6315 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006316
John McCallb96ec562009-12-04 22:46:56 +00006317 } else {
6318 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6319 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6320 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6321 }
6322
6323 return SemaRef.Context.getTypeDeclType(Ty);
6324}
6325
6326template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006327QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006328 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6329}
6330
6331template<typename Derived>
6332QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6333 return SemaRef.Context.getTypeOfType(Underlying);
6334}
6335
6336template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006337QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006338 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6339}
6340
6341template<typename Derived>
6342QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006343 TemplateName Template,
6344 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006345 const TemplateArgumentListInfo &TemplateArgs) {
6346 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006347}
Mike Stump11289f42009-09-09 15:08:12 +00006348
Douglas Gregor1135c352009-08-06 05:28:30 +00006349template<typename Derived>
6350NestedNameSpecifier *
6351TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6352 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006353 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006354 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006355 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006356 CXXScopeSpec SS;
6357 // FIXME: The source location information is all wrong.
6358 SS.setRange(Range);
6359 SS.setScopeRep(Prefix);
6360 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006361 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006362 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006363 ObjectType,
6364 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006365 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006366}
6367
6368template<typename Derived>
6369NestedNameSpecifier *
6370TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6371 SourceRange Range,
6372 NamespaceDecl *NS) {
6373 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6374}
6375
6376template<typename Derived>
6377NestedNameSpecifier *
6378TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6379 SourceRange Range,
6380 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006381 QualType T) {
6382 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006383 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006384 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006385 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6386 T.getTypePtr());
6387 }
Mike Stump11289f42009-09-09 15:08:12 +00006388
Douglas Gregor1135c352009-08-06 05:28:30 +00006389 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6390 return 0;
6391}
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregor71dc5092009-08-06 06:41:21 +00006393template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006394TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006395TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6396 bool TemplateKW,
6397 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006398 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006399 Template);
6400}
6401
6402template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006403TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006404TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006405 const IdentifierInfo &II,
6406 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006407 CXXScopeSpec SS;
6408 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006409 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006410 UnqualifiedId Name;
6411 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006412 return getSema().ActOnDependentTemplateName(
6413 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006414 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006415 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006416 ObjectType.getAsOpaquePtr(),
6417 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006418 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006419}
Mike Stump11289f42009-09-09 15:08:12 +00006420
Douglas Gregora16548e2009-08-11 05:31:07 +00006421template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006422TemplateName
6423TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6424 OverloadedOperatorKind Operator,
6425 QualType ObjectType) {
6426 CXXScopeSpec SS;
6427 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6428 SS.setScopeRep(Qualifier);
6429 UnqualifiedId Name;
6430 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6431 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6432 Operator, SymbolLocations);
6433 return getSema().ActOnDependentTemplateName(
6434 /*FIXME:*/getDerived().getBaseLocation(),
6435 SS,
6436 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006437 ObjectType.getAsOpaquePtr(),
6438 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006439 .template getAsVal<TemplateName>();
6440}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006441
Douglas Gregor71395fa2009-11-04 00:56:37 +00006442template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006443Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006444TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6445 SourceLocation OpLoc,
6446 ExprArg Callee,
6447 ExprArg First,
6448 ExprArg Second) {
6449 Expr *FirstExpr = (Expr *)First.get();
6450 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006451 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006452 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006453
Douglas Gregora16548e2009-08-11 05:31:07 +00006454 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006455 if (Op == OO_Subscript) {
6456 if (!FirstExpr->getType()->isOverloadableType() &&
6457 !SecondExpr->getType()->isOverloadableType())
6458 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006459 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006460 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006461 } else if (Op == OO_Arrow) {
6462 // -> is never a builtin operation.
6463 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006464 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006465 if (!FirstExpr->getType()->isOverloadableType()) {
6466 // The argument is not of overloadable type, so try to create a
6467 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006468 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006469 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006470
Douglas Gregora16548e2009-08-11 05:31:07 +00006471 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6472 }
6473 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006474 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006475 !SecondExpr->getType()->isOverloadableType()) {
6476 // Neither of the arguments is an overloadable type, so try to
6477 // create a built-in binary operation.
6478 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006479 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006480 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6481 if (Result.isInvalid())
6482 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006483
Douglas Gregora16548e2009-08-11 05:31:07 +00006484 First.release();
6485 Second.release();
6486 return move(Result);
6487 }
6488 }
Mike Stump11289f42009-09-09 15:08:12 +00006489
6490 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006491 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006492 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006493
John McCalld14a8642009-11-21 08:51:07 +00006494 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6495 assert(ULE->requiresADL());
6496
6497 // FIXME: Do we have to check
6498 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006499 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006500 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006501 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006502 }
Mike Stump11289f42009-09-09 15:08:12 +00006503
Douglas Gregora16548e2009-08-11 05:31:07 +00006504 // Add any functions found via argument-dependent lookup.
6505 Expr *Args[2] = { FirstExpr, SecondExpr };
6506 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 // Create the overloaded operator invocation for unary operators.
6509 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006510 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006511 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6512 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6513 }
Mike Stump11289f42009-09-09 15:08:12 +00006514
Sebastian Redladba46e2009-10-29 20:17:01 +00006515 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006516 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6517 OpLoc,
6518 move(First),
6519 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006520
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006522 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006524 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6526 if (Result.isInvalid())
6527 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006528
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 First.release();
6530 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006531 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006532}
Mike Stump11289f42009-09-09 15:08:12 +00006533
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006534template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006535Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006536TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6537 SourceLocation OperatorLoc,
6538 bool isArrow,
6539 NestedNameSpecifier *Qualifier,
6540 SourceRange QualifierRange,
6541 TypeSourceInfo *ScopeType,
6542 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006543 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006544 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006545 CXXScopeSpec SS;
6546 if (Qualifier) {
6547 SS.setRange(QualifierRange);
6548 SS.setScopeRep(Qualifier);
6549 }
6550
6551 Expr *BaseE = (Expr *)Base.get();
6552 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006553 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006554 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006555 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006556 !BaseType->getAs<PointerType>()->getPointeeType()
6557 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006558 // This pseudo-destructor expression is still a pseudo-destructor.
6559 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6560 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006561 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006562 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006563 /*FIXME?*/true);
6564 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006565
Douglas Gregor678f90d2010-02-25 01:56:36 +00006566 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006567 DeclarationName Name
6568 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6569 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006570
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006571 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006572
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006573 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6574 OperatorLoc, isArrow,
6575 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006576 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006577 /*TemplateArgs*/ 0);
6578}
6579
Douglas Gregord6ff3322009-08-04 16:50:30 +00006580} // end namespace clang
6581
6582#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H