blob: 4923480737ee5aa6f80201b1cf7881383cc9b93a [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();
2448 if (PointeeType->isObjCInterfaceType()) {
2449 // A dependent pointer type 'T *' has is being transformed such
2450 // that an Objective-C class type is being replaced for 'T'. The
2451 // resulting pointer type is an ObjCObjectPointerType, not a
2452 // PointerType.
2453 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2454 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2455 const_cast<ObjCProtocolDecl **>(
2456 IFace->qual_begin()),
2457 IFace->getNumProtocols());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002458
2459 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2460 NewT.setStarLoc(TL.getSigilLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002461 NewT.setHasProtocolsAsWritten(false);
2462 NewT.setLAngleLoc(SourceLocation());
2463 NewT.setRAngleLoc(SourceLocation());
2464 NewT.setHasBaseTypeAsWritten(true);
2465 return Result;
2466 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002467
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 if (getDerived().AlwaysRebuild() ||
2469 PointeeType != TL.getPointeeLoc().getType()) {
2470 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2471 if (Result.isNull())
2472 return QualType();
2473 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002474
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002475 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2476 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002477 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002478}
Mike Stump11289f42009-09-09 15:08:12 +00002479
2480template<typename Derived>
2481QualType
John McCall550e0c22009-10-21 00:40:46 +00002482TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002483 BlockPointerTypeLoc TL,
2484 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002485 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002486 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2487 if (PointeeType.isNull())
2488 return QualType();
2489
2490 QualType Result = TL.getType();
2491 if (getDerived().AlwaysRebuild() ||
2492 PointeeType != TL.getPointeeLoc().getType()) {
2493 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002494 TL.getSigilLoc());
2495 if (Result.isNull())
2496 return QualType();
2497 }
2498
Douglas Gregor049211a2010-04-22 16:50:51 +00002499 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002500 NewT.setSigilLoc(TL.getSigilLoc());
2501 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002502}
2503
John McCall70dd5f62009-10-30 00:06:24 +00002504/// Transforms a reference type. Note that somewhat paradoxically we
2505/// don't care whether the type itself is an l-value type or an r-value
2506/// type; we only care if the type was *written* as an l-value type
2507/// or an r-value type.
2508template<typename Derived>
2509QualType
2510TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002511 ReferenceTypeLoc TL,
2512 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002513 const ReferenceType *T = TL.getTypePtr();
2514
2515 // Note that this works with the pointee-as-written.
2516 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2517 if (PointeeType.isNull())
2518 return QualType();
2519
2520 QualType Result = TL.getType();
2521 if (getDerived().AlwaysRebuild() ||
2522 PointeeType != T->getPointeeTypeAsWritten()) {
2523 Result = getDerived().RebuildReferenceType(PointeeType,
2524 T->isSpelledAsLValue(),
2525 TL.getSigilLoc());
2526 if (Result.isNull())
2527 return QualType();
2528 }
2529
2530 // r-value references can be rebuilt as l-value references.
2531 ReferenceTypeLoc NewTL;
2532 if (isa<LValueReferenceType>(Result))
2533 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2534 else
2535 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2536 NewTL.setSigilLoc(TL.getSigilLoc());
2537
2538 return Result;
2539}
2540
Mike Stump11289f42009-09-09 15:08:12 +00002541template<typename Derived>
2542QualType
John McCall550e0c22009-10-21 00:40:46 +00002543TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002544 LValueReferenceTypeLoc TL,
2545 QualType ObjectType) {
2546 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002547}
2548
Mike Stump11289f42009-09-09 15:08:12 +00002549template<typename Derived>
2550QualType
John McCall550e0c22009-10-21 00:40:46 +00002551TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002552 RValueReferenceTypeLoc TL,
2553 QualType ObjectType) {
2554 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002555}
Mike Stump11289f42009-09-09 15:08:12 +00002556
Douglas Gregord6ff3322009-08-04 16:50:30 +00002557template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002558QualType
John McCall550e0c22009-10-21 00:40:46 +00002559TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002560 MemberPointerTypeLoc TL,
2561 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002562 MemberPointerType *T = TL.getTypePtr();
2563
2564 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002565 if (PointeeType.isNull())
2566 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002567
John McCall550e0c22009-10-21 00:40:46 +00002568 // TODO: preserve source information for this.
2569 QualType ClassType
2570 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002571 if (ClassType.isNull())
2572 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002573
John McCall550e0c22009-10-21 00:40:46 +00002574 QualType Result = TL.getType();
2575 if (getDerived().AlwaysRebuild() ||
2576 PointeeType != T->getPointeeType() ||
2577 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002578 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2579 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002580 if (Result.isNull())
2581 return QualType();
2582 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002583
John McCall550e0c22009-10-21 00:40:46 +00002584 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2585 NewTL.setSigilLoc(TL.getSigilLoc());
2586
2587 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002588}
2589
Mike Stump11289f42009-09-09 15:08:12 +00002590template<typename Derived>
2591QualType
John McCall550e0c22009-10-21 00:40:46 +00002592TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002593 ConstantArrayTypeLoc TL,
2594 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002595 ConstantArrayType *T = TL.getTypePtr();
2596 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002597 if (ElementType.isNull())
2598 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002599
John McCall550e0c22009-10-21 00:40:46 +00002600 QualType Result = TL.getType();
2601 if (getDerived().AlwaysRebuild() ||
2602 ElementType != T->getElementType()) {
2603 Result = getDerived().RebuildConstantArrayType(ElementType,
2604 T->getSizeModifier(),
2605 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002606 T->getIndexTypeCVRQualifiers(),
2607 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002608 if (Result.isNull())
2609 return QualType();
2610 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2613 NewTL.setLBracketLoc(TL.getLBracketLoc());
2614 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002615
John McCall550e0c22009-10-21 00:40:46 +00002616 Expr *Size = TL.getSizeExpr();
2617 if (Size) {
2618 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2619 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2620 }
2621 NewTL.setSizeExpr(Size);
2622
2623 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002624}
Mike Stump11289f42009-09-09 15:08:12 +00002625
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002627QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002628 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002629 IncompleteArrayTypeLoc TL,
2630 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002631 IncompleteArrayType *T = TL.getTypePtr();
2632 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002633 if (ElementType.isNull())
2634 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002635
John McCall550e0c22009-10-21 00:40:46 +00002636 QualType Result = TL.getType();
2637 if (getDerived().AlwaysRebuild() ||
2638 ElementType != T->getElementType()) {
2639 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002640 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002641 T->getIndexTypeCVRQualifiers(),
2642 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002643 if (Result.isNull())
2644 return QualType();
2645 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002646
John McCall550e0c22009-10-21 00:40:46 +00002647 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2648 NewTL.setLBracketLoc(TL.getLBracketLoc());
2649 NewTL.setRBracketLoc(TL.getRBracketLoc());
2650 NewTL.setSizeExpr(0);
2651
2652 return Result;
2653}
2654
2655template<typename Derived>
2656QualType
2657TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002658 VariableArrayTypeLoc TL,
2659 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002660 VariableArrayType *T = TL.getTypePtr();
2661 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2662 if (ElementType.isNull())
2663 return QualType();
2664
2665 // Array bounds are not potentially evaluated contexts
2666 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2667
2668 Sema::OwningExprResult SizeResult
2669 = getDerived().TransformExpr(T->getSizeExpr());
2670 if (SizeResult.isInvalid())
2671 return QualType();
2672
2673 Expr *Size = static_cast<Expr*>(SizeResult.get());
2674
2675 QualType Result = TL.getType();
2676 if (getDerived().AlwaysRebuild() ||
2677 ElementType != T->getElementType() ||
2678 Size != T->getSizeExpr()) {
2679 Result = getDerived().RebuildVariableArrayType(ElementType,
2680 T->getSizeModifier(),
2681 move(SizeResult),
2682 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002683 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002684 if (Result.isNull())
2685 return QualType();
2686 }
2687 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002688
John McCall550e0c22009-10-21 00:40:46 +00002689 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2690 NewTL.setLBracketLoc(TL.getLBracketLoc());
2691 NewTL.setRBracketLoc(TL.getRBracketLoc());
2692 NewTL.setSizeExpr(Size);
2693
2694 return Result;
2695}
2696
2697template<typename Derived>
2698QualType
2699TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002700 DependentSizedArrayTypeLoc TL,
2701 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002702 DependentSizedArrayType *T = TL.getTypePtr();
2703 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2704 if (ElementType.isNull())
2705 return QualType();
2706
2707 // Array bounds are not potentially evaluated contexts
2708 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2709
2710 Sema::OwningExprResult SizeResult
2711 = getDerived().TransformExpr(T->getSizeExpr());
2712 if (SizeResult.isInvalid())
2713 return QualType();
2714
2715 Expr *Size = static_cast<Expr*>(SizeResult.get());
2716
2717 QualType Result = TL.getType();
2718 if (getDerived().AlwaysRebuild() ||
2719 ElementType != T->getElementType() ||
2720 Size != T->getSizeExpr()) {
2721 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2722 T->getSizeModifier(),
2723 move(SizeResult),
2724 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002725 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002726 if (Result.isNull())
2727 return QualType();
2728 }
2729 else SizeResult.take();
2730
2731 // We might have any sort of array type now, but fortunately they
2732 // all have the same location layout.
2733 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2734 NewTL.setLBracketLoc(TL.getLBracketLoc());
2735 NewTL.setRBracketLoc(TL.getRBracketLoc());
2736 NewTL.setSizeExpr(Size);
2737
2738 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002739}
Mike Stump11289f42009-09-09 15:08:12 +00002740
2741template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002742QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002743 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002744 DependentSizedExtVectorTypeLoc TL,
2745 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002746 DependentSizedExtVectorType *T = TL.getTypePtr();
2747
2748 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002749 QualType ElementType = getDerived().TransformType(T->getElementType());
2750 if (ElementType.isNull())
2751 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002752
Douglas Gregore922c772009-08-04 22:27:00 +00002753 // Vector sizes are not potentially evaluated contexts
2754 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2755
Douglas Gregord6ff3322009-08-04 16:50:30 +00002756 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2757 if (Size.isInvalid())
2758 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002759
John McCall550e0c22009-10-21 00:40:46 +00002760 QualType Result = TL.getType();
2761 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002762 ElementType != T->getElementType() ||
2763 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002764 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002765 move(Size),
2766 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002767 if (Result.isNull())
2768 return QualType();
2769 }
2770 else Size.take();
2771
2772 // Result might be dependent or not.
2773 if (isa<DependentSizedExtVectorType>(Result)) {
2774 DependentSizedExtVectorTypeLoc NewTL
2775 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2776 NewTL.setNameLoc(TL.getNameLoc());
2777 } else {
2778 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2779 NewTL.setNameLoc(TL.getNameLoc());
2780 }
2781
2782 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002783}
Mike Stump11289f42009-09-09 15:08:12 +00002784
2785template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002786QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002787 VectorTypeLoc TL,
2788 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002789 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002790 QualType ElementType = getDerived().TransformType(T->getElementType());
2791 if (ElementType.isNull())
2792 return QualType();
2793
John McCall550e0c22009-10-21 00:40:46 +00002794 QualType Result = TL.getType();
2795 if (getDerived().AlwaysRebuild() ||
2796 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002797 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2798 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002799 if (Result.isNull())
2800 return QualType();
2801 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002802
John McCall550e0c22009-10-21 00:40:46 +00002803 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2804 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002805
John McCall550e0c22009-10-21 00:40:46 +00002806 return Result;
2807}
2808
2809template<typename Derived>
2810QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002811 ExtVectorTypeLoc TL,
2812 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002813 VectorType *T = TL.getTypePtr();
2814 QualType ElementType = getDerived().TransformType(T->getElementType());
2815 if (ElementType.isNull())
2816 return QualType();
2817
2818 QualType Result = TL.getType();
2819 if (getDerived().AlwaysRebuild() ||
2820 ElementType != T->getElementType()) {
2821 Result = getDerived().RebuildExtVectorType(ElementType,
2822 T->getNumElements(),
2823 /*FIXME*/ SourceLocation());
2824 if (Result.isNull())
2825 return QualType();
2826 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002827
John McCall550e0c22009-10-21 00:40:46 +00002828 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2829 NewTL.setNameLoc(TL.getNameLoc());
2830
2831 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002832}
Mike Stump11289f42009-09-09 15:08:12 +00002833
2834template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002835ParmVarDecl *
2836TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2837 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2838 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2839 if (!NewDI)
2840 return 0;
2841
2842 if (NewDI == OldDI)
2843 return OldParm;
2844 else
2845 return ParmVarDecl::Create(SemaRef.Context,
2846 OldParm->getDeclContext(),
2847 OldParm->getLocation(),
2848 OldParm->getIdentifier(),
2849 NewDI->getType(),
2850 NewDI,
2851 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002852 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002853 /* DefArg */ NULL);
2854}
2855
2856template<typename Derived>
2857bool TreeTransform<Derived>::
2858 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2859 llvm::SmallVectorImpl<QualType> &PTypes,
2860 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2861 FunctionProtoType *T = TL.getTypePtr();
2862
2863 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2864 ParmVarDecl *OldParm = TL.getArg(i);
2865
2866 QualType NewType;
2867 ParmVarDecl *NewParm;
2868
2869 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002870 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2871 if (!NewParm)
2872 return true;
2873 NewType = NewParm->getType();
2874
2875 // Deal with the possibility that we don't have a parameter
2876 // declaration for this parameter.
2877 } else {
2878 NewParm = 0;
2879
2880 QualType OldType = T->getArgType(i);
2881 NewType = getDerived().TransformType(OldType);
2882 if (NewType.isNull())
2883 return true;
2884 }
2885
2886 PTypes.push_back(NewType);
2887 PVars.push_back(NewParm);
2888 }
2889
2890 return false;
2891}
2892
2893template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002894QualType
John McCall550e0c22009-10-21 00:40:46 +00002895TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002896 FunctionProtoTypeLoc TL,
2897 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002898 // Transform the parameters. We do this first for the benefit of template
2899 // instantiations, so that the ParmVarDecls get/ placed into the template
2900 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002901 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002902 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002903 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2904 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002905
Douglas Gregor14cf7522010-04-30 18:55:50 +00002906 FunctionProtoType *T = TL.getTypePtr();
2907 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2908 if (ResultType.isNull())
2909 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002910
John McCall550e0c22009-10-21 00:40:46 +00002911 QualType Result = TL.getType();
2912 if (getDerived().AlwaysRebuild() ||
2913 ResultType != T->getResultType() ||
2914 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2915 Result = getDerived().RebuildFunctionProtoType(ResultType,
2916 ParamTypes.data(),
2917 ParamTypes.size(),
2918 T->isVariadic(),
2919 T->getTypeQuals());
2920 if (Result.isNull())
2921 return QualType();
2922 }
Mike Stump11289f42009-09-09 15:08:12 +00002923
John McCall550e0c22009-10-21 00:40:46 +00002924 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2925 NewTL.setLParenLoc(TL.getLParenLoc());
2926 NewTL.setRParenLoc(TL.getRParenLoc());
2927 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2928 NewTL.setArg(i, ParamDecls[i]);
2929
2930 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002931}
Mike Stump11289f42009-09-09 15:08:12 +00002932
Douglas Gregord6ff3322009-08-04 16:50:30 +00002933template<typename Derived>
2934QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002935 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002936 FunctionNoProtoTypeLoc TL,
2937 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002938 FunctionNoProtoType *T = TL.getTypePtr();
2939 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2940 if (ResultType.isNull())
2941 return QualType();
2942
2943 QualType Result = TL.getType();
2944 if (getDerived().AlwaysRebuild() ||
2945 ResultType != T->getResultType())
2946 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2947
2948 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2949 NewTL.setLParenLoc(TL.getLParenLoc());
2950 NewTL.setRParenLoc(TL.getRParenLoc());
2951
2952 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002953}
Mike Stump11289f42009-09-09 15:08:12 +00002954
John McCallb96ec562009-12-04 22:46:56 +00002955template<typename Derived> QualType
2956TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002957 UnresolvedUsingTypeLoc TL,
2958 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002959 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002960 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002961 if (!D)
2962 return QualType();
2963
2964 QualType Result = TL.getType();
2965 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2966 Result = getDerived().RebuildUnresolvedUsingType(D);
2967 if (Result.isNull())
2968 return QualType();
2969 }
2970
2971 // We might get an arbitrary type spec type back. We should at
2972 // least always get a type spec type, though.
2973 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2974 NewTL.setNameLoc(TL.getNameLoc());
2975
2976 return Result;
2977}
2978
Douglas Gregord6ff3322009-08-04 16:50:30 +00002979template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002980QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002981 TypedefTypeLoc TL,
2982 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002983 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002984 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002985 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
2986 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002987 if (!Typedef)
2988 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002989
John McCall550e0c22009-10-21 00:40:46 +00002990 QualType Result = TL.getType();
2991 if (getDerived().AlwaysRebuild() ||
2992 Typedef != T->getDecl()) {
2993 Result = getDerived().RebuildTypedefType(Typedef);
2994 if (Result.isNull())
2995 return QualType();
2996 }
Mike Stump11289f42009-09-09 15:08:12 +00002997
John McCall550e0c22009-10-21 00:40:46 +00002998 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
2999 NewTL.setNameLoc(TL.getNameLoc());
3000
3001 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003002}
Mike Stump11289f42009-09-09 15:08:12 +00003003
Douglas Gregord6ff3322009-08-04 16:50:30 +00003004template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003005QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003006 TypeOfExprTypeLoc TL,
3007 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003008 // typeof expressions are not potentially evaluated contexts
3009 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003010
John McCalle8595032010-01-13 20:03:27 +00003011 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003012 if (E.isInvalid())
3013 return QualType();
3014
John McCall550e0c22009-10-21 00:40:46 +00003015 QualType Result = TL.getType();
3016 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003017 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003018 Result = getDerived().RebuildTypeOfExprType(move(E));
3019 if (Result.isNull())
3020 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003021 }
John McCall550e0c22009-10-21 00:40:46 +00003022 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003023
John McCall550e0c22009-10-21 00:40:46 +00003024 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003025 NewTL.setTypeofLoc(TL.getTypeofLoc());
3026 NewTL.setLParenLoc(TL.getLParenLoc());
3027 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003028
3029 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003030}
Mike Stump11289f42009-09-09 15:08:12 +00003031
3032template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003033QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003034 TypeOfTypeLoc TL,
3035 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003036 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3037 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3038 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003039 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003040
John McCall550e0c22009-10-21 00:40:46 +00003041 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003042 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3043 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003044 if (Result.isNull())
3045 return QualType();
3046 }
Mike Stump11289f42009-09-09 15:08:12 +00003047
John McCall550e0c22009-10-21 00:40:46 +00003048 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003049 NewTL.setTypeofLoc(TL.getTypeofLoc());
3050 NewTL.setLParenLoc(TL.getLParenLoc());
3051 NewTL.setRParenLoc(TL.getRParenLoc());
3052 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003053
3054 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055}
Mike Stump11289f42009-09-09 15:08:12 +00003056
3057template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003058QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003059 DecltypeTypeLoc TL,
3060 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003061 DecltypeType *T = TL.getTypePtr();
3062
Douglas Gregore922c772009-08-04 22:27:00 +00003063 // decltype expressions are not potentially evaluated contexts
3064 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003065
Douglas Gregord6ff3322009-08-04 16:50:30 +00003066 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3067 if (E.isInvalid())
3068 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003069
John McCall550e0c22009-10-21 00:40:46 +00003070 QualType Result = TL.getType();
3071 if (getDerived().AlwaysRebuild() ||
3072 E.get() != T->getUnderlyingExpr()) {
3073 Result = getDerived().RebuildDecltypeType(move(E));
3074 if (Result.isNull())
3075 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076 }
John McCall550e0c22009-10-21 00:40:46 +00003077 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3080 NewTL.setNameLoc(TL.getNameLoc());
3081
3082 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003083}
3084
3085template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003086QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003087 RecordTypeLoc TL,
3088 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003089 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003090 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003091 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3092 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093 if (!Record)
3094 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003095
John McCall550e0c22009-10-21 00:40:46 +00003096 QualType Result = TL.getType();
3097 if (getDerived().AlwaysRebuild() ||
3098 Record != T->getDecl()) {
3099 Result = getDerived().RebuildRecordType(Record);
3100 if (Result.isNull())
3101 return QualType();
3102 }
Mike Stump11289f42009-09-09 15:08:12 +00003103
John McCall550e0c22009-10-21 00:40:46 +00003104 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3105 NewTL.setNameLoc(TL.getNameLoc());
3106
3107 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003108}
Mike Stump11289f42009-09-09 15:08:12 +00003109
3110template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003111QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003112 EnumTypeLoc TL,
3113 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003114 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003116 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3117 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003118 if (!Enum)
3119 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003120
John McCall550e0c22009-10-21 00:40:46 +00003121 QualType Result = TL.getType();
3122 if (getDerived().AlwaysRebuild() ||
3123 Enum != T->getDecl()) {
3124 Result = getDerived().RebuildEnumType(Enum);
3125 if (Result.isNull())
3126 return QualType();
3127 }
Mike Stump11289f42009-09-09 15:08:12 +00003128
John McCall550e0c22009-10-21 00:40:46 +00003129 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3130 NewTL.setNameLoc(TL.getNameLoc());
3131
3132 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003133}
John McCallfcc33b02009-09-05 00:15:47 +00003134
John McCalle78aac42010-03-10 03:28:59 +00003135template<typename Derived>
3136QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3137 TypeLocBuilder &TLB,
3138 InjectedClassNameTypeLoc TL,
3139 QualType ObjectType) {
3140 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3141 TL.getTypePtr()->getDecl());
3142 if (!D) return QualType();
3143
3144 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3145 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3146 return T;
3147}
3148
Mike Stump11289f42009-09-09 15:08:12 +00003149
Douglas Gregord6ff3322009-08-04 16:50:30 +00003150template<typename Derived>
3151QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003152 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003153 TemplateTypeParmTypeLoc TL,
3154 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003155 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156}
3157
Mike Stump11289f42009-09-09 15:08:12 +00003158template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003159QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003160 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003161 SubstTemplateTypeParmTypeLoc TL,
3162 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003163 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003164}
3165
3166template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003167QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3168 const TemplateSpecializationType *TST,
3169 QualType ObjectType) {
3170 // FIXME: this entire method is a temporary workaround; callers
3171 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003172
John McCall0ad16662009-10-29 08:12:44 +00003173 // Fake up a TemplateSpecializationTypeLoc.
3174 TypeLocBuilder TLB;
3175 TemplateSpecializationTypeLoc TL
3176 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3177
John McCall0d07eb32009-10-29 18:45:58 +00003178 SourceLocation BaseLoc = getDerived().getBaseLocation();
3179
3180 TL.setTemplateNameLoc(BaseLoc);
3181 TL.setLAngleLoc(BaseLoc);
3182 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003183 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3184 const TemplateArgument &TA = TST->getArg(i);
3185 TemplateArgumentLoc TAL;
3186 getDerived().InventTemplateArgumentLoc(TA, TAL);
3187 TL.setArgLocInfo(i, TAL.getLocInfo());
3188 }
3189
3190 TypeLocBuilder IgnoredTLB;
3191 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003192}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003193
Douglas Gregorc59e5612009-10-19 22:04:39 +00003194template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003195QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003196 TypeLocBuilder &TLB,
3197 TemplateSpecializationTypeLoc TL,
3198 QualType ObjectType) {
3199 const TemplateSpecializationType *T = TL.getTypePtr();
3200
Mike Stump11289f42009-09-09 15:08:12 +00003201 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003202 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003203 if (Template.isNull())
3204 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003205
John McCall6b51f282009-11-23 01:53:49 +00003206 TemplateArgumentListInfo NewTemplateArgs;
3207 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3208 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3209
3210 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3211 TemplateArgumentLoc Loc;
3212 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003213 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003214 NewTemplateArgs.addArgument(Loc);
3215 }
Mike Stump11289f42009-09-09 15:08:12 +00003216
John McCall0ad16662009-10-29 08:12:44 +00003217 // FIXME: maybe don't rebuild if all the template arguments are the same.
3218
3219 QualType Result =
3220 getDerived().RebuildTemplateSpecializationType(Template,
3221 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003222 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003223
3224 if (!Result.isNull()) {
3225 TemplateSpecializationTypeLoc NewTL
3226 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3227 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3228 NewTL.setLAngleLoc(TL.getLAngleLoc());
3229 NewTL.setRAngleLoc(TL.getRAngleLoc());
3230 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3231 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003232 }
Mike Stump11289f42009-09-09 15:08:12 +00003233
John McCall0ad16662009-10-29 08:12:44 +00003234 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003235}
Mike Stump11289f42009-09-09 15:08:12 +00003236
3237template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003238QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003239TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3240 ElaboratedTypeLoc TL,
3241 QualType ObjectType) {
3242 ElaboratedType *T = TL.getTypePtr();
3243
3244 NestedNameSpecifier *NNS = 0;
3245 // NOTE: the qualifier in an ElaboratedType is optional.
3246 if (T->getQualifier() != 0) {
3247 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3248 SourceRange(),
3249 ObjectType);
3250 if (!NNS)
3251 return QualType();
3252 }
Mike Stump11289f42009-09-09 15:08:12 +00003253
Douglas Gregord6ff3322009-08-04 16:50:30 +00003254 QualType Named = getDerived().TransformType(T->getNamedType());
3255 if (Named.isNull())
3256 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003257
John McCall550e0c22009-10-21 00:40:46 +00003258 QualType Result = TL.getType();
3259 if (getDerived().AlwaysRebuild() ||
3260 NNS != T->getQualifier() ||
3261 Named != T->getNamedType()) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00003262 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, Named);
John McCall550e0c22009-10-21 00:40:46 +00003263 if (Result.isNull())
3264 return QualType();
3265 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266
Abramo Bagnara6150c882010-05-11 21:36:43 +00003267 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003268 NewTL.setNameLoc(TL.getNameLoc());
3269
3270 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003271}
Mike Stump11289f42009-09-09 15:08:12 +00003272
3273template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003274QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3275 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003276 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003277 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003278
3279 /* FIXME: preserve source information better than this */
3280 SourceRange SR(TL.getNameLoc());
3281
Douglas Gregord6ff3322009-08-04 16:50:30 +00003282 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003283 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003284 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003285 if (!NNS)
3286 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003287
John McCall550e0c22009-10-21 00:40:46 +00003288 QualType Result;
3289
Douglas Gregord6ff3322009-08-04 16:50:30 +00003290 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003291 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003292 = getDerived().TransformType(QualType(TemplateId, 0));
3293 if (NewTemplateId.isNull())
3294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003295
Douglas Gregord6ff3322009-08-04 16:50:30 +00003296 if (!getDerived().AlwaysRebuild() &&
3297 NNS == T->getQualifier() &&
3298 NewTemplateId == QualType(TemplateId, 0))
3299 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003300
Alexis Hunta8136cc2010-05-05 15:23:54 +00003301 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003302 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003303 } else {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003304 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003305 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 }
John McCall550e0c22009-10-21 00:40:46 +00003307 if (Result.isNull())
3308 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003309
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003310 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003311 NewTL.setNameLoc(TL.getNameLoc());
3312
3313 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003314}
Mike Stump11289f42009-09-09 15:08:12 +00003315
Douglas Gregord6ff3322009-08-04 16:50:30 +00003316template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003317QualType
3318TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003319 ObjCInterfaceTypeLoc TL,
3320 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003321 // ObjCInterfaceType is never dependent.
3322 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003323}
Mike Stump11289f42009-09-09 15:08:12 +00003324
3325template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003326QualType
3327TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003328 ObjCObjectPointerTypeLoc TL,
3329 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003330 // ObjCObjectPointerType is never dependent.
3331 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003332}
3333
Douglas Gregord6ff3322009-08-04 16:50:30 +00003334//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003335// Statement transformation
3336//===----------------------------------------------------------------------===//
3337template<typename Derived>
3338Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003339TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3340 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003341}
3342
3343template<typename Derived>
3344Sema::OwningStmtResult
3345TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3346 return getDerived().TransformCompoundStmt(S, false);
3347}
3348
3349template<typename Derived>
3350Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003351TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003352 bool IsStmtExpr) {
3353 bool SubStmtChanged = false;
3354 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3355 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3356 B != BEnd; ++B) {
3357 OwningStmtResult Result = getDerived().TransformStmt(*B);
3358 if (Result.isInvalid())
3359 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003360
Douglas Gregorebe10102009-08-20 07:17:43 +00003361 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3362 Statements.push_back(Result.takeAs<Stmt>());
3363 }
Mike Stump11289f42009-09-09 15:08:12 +00003364
Douglas Gregorebe10102009-08-20 07:17:43 +00003365 if (!getDerived().AlwaysRebuild() &&
3366 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003367 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003368
3369 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3370 move_arg(Statements),
3371 S->getRBracLoc(),
3372 IsStmtExpr);
3373}
Mike Stump11289f42009-09-09 15:08:12 +00003374
Douglas Gregorebe10102009-08-20 07:17:43 +00003375template<typename Derived>
3376Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003377TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003378 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3379 {
3380 // The case value expressions are not potentially evaluated.
3381 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003382
Eli Friedman06577382009-11-19 03:14:00 +00003383 // Transform the left-hand case value.
3384 LHS = getDerived().TransformExpr(S->getLHS());
3385 if (LHS.isInvalid())
3386 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003387
Eli Friedman06577382009-11-19 03:14:00 +00003388 // Transform the right-hand case value (for the GNU case-range extension).
3389 RHS = getDerived().TransformExpr(S->getRHS());
3390 if (RHS.isInvalid())
3391 return SemaRef.StmtError();
3392 }
Mike Stump11289f42009-09-09 15:08:12 +00003393
Douglas Gregorebe10102009-08-20 07:17:43 +00003394 // Build the case statement.
3395 // Case statements are always rebuilt so that they will attached to their
3396 // transformed switch statement.
3397 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3398 move(LHS),
3399 S->getEllipsisLoc(),
3400 move(RHS),
3401 S->getColonLoc());
3402 if (Case.isInvalid())
3403 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003404
Douglas Gregorebe10102009-08-20 07:17:43 +00003405 // Transform the statement following the case
3406 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3407 if (SubStmt.isInvalid())
3408 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003409
Douglas Gregorebe10102009-08-20 07:17:43 +00003410 // Attach the body to the case statement
3411 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3412}
3413
3414template<typename Derived>
3415Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003416TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003417 // Transform the statement following the default case
3418 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3419 if (SubStmt.isInvalid())
3420 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003421
Douglas Gregorebe10102009-08-20 07:17:43 +00003422 // Default statements are always rebuilt
3423 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3424 move(SubStmt));
3425}
Mike Stump11289f42009-09-09 15:08:12 +00003426
Douglas Gregorebe10102009-08-20 07:17:43 +00003427template<typename Derived>
3428Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003429TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003430 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3431 if (SubStmt.isInvalid())
3432 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003433
Douglas Gregorebe10102009-08-20 07:17:43 +00003434 // FIXME: Pass the real colon location in.
3435 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3436 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3437 move(SubStmt));
3438}
Mike Stump11289f42009-09-09 15:08:12 +00003439
Douglas Gregorebe10102009-08-20 07:17:43 +00003440template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003441Sema::OwningStmtResult
3442TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003443 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003444 OwningExprResult Cond(SemaRef);
3445 VarDecl *ConditionVar = 0;
3446 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003447 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003448 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003449 getDerived().TransformDefinition(
3450 S->getConditionVariable()->getLocation(),
3451 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003452 if (!ConditionVar)
3453 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003454 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003455 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003456
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003457 if (Cond.isInvalid())
3458 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003459
3460 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003461 if (S->getCond()) {
3462 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3463 S->getIfLoc(),
3464 move(Cond));
3465 if (CondE.isInvalid())
3466 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003467
Douglas Gregor6d319c62010-05-08 23:34:38 +00003468 Cond = move(CondE);
3469 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003470 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003471
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003472 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3473 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3474 return SemaRef.StmtError();
3475
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 // Transform the "then" branch.
3477 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3478 if (Then.isInvalid())
3479 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregorebe10102009-08-20 07:17:43 +00003481 // Transform the "else" branch.
3482 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3483 if (Else.isInvalid())
3484 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003487 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003488 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003489 Then.get() == S->getThen() &&
3490 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003491 return SemaRef.Owned(S->Retain());
3492
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003493 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003494 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003495 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003496}
3497
3498template<typename Derived>
3499Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003500TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003501 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003502 OwningExprResult Cond(SemaRef);
3503 VarDecl *ConditionVar = 0;
3504 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003505 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003506 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003507 getDerived().TransformDefinition(
3508 S->getConditionVariable()->getLocation(),
3509 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003510 if (!ConditionVar)
3511 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003512 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003513 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003514
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003515 if (Cond.isInvalid())
3516 return SemaRef.StmtError();
3517 }
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003520 OwningStmtResult Switch
3521 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3522 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003523 if (Switch.isInvalid())
3524 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003525
Douglas Gregorebe10102009-08-20 07:17:43 +00003526 // Transform the body of the switch statement.
3527 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3528 if (Body.isInvalid())
3529 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 // Complete the switch statement.
3532 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3533 move(Body));
3534}
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregorebe10102009-08-20 07:17:43 +00003536template<typename Derived>
3537Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003538TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003539 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003540 OwningExprResult Cond(SemaRef);
3541 VarDecl *ConditionVar = 0;
3542 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003543 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003544 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003545 getDerived().TransformDefinition(
3546 S->getConditionVariable()->getLocation(),
3547 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003548 if (!ConditionVar)
3549 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003550 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003551 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003552
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003553 if (Cond.isInvalid())
3554 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003555
3556 if (S->getCond()) {
3557 // Convert the condition to a boolean value.
3558 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003559 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003560 move(Cond));
3561 if (CondE.isInvalid())
3562 return getSema().StmtError();
3563 Cond = move(CondE);
3564 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003565 }
Mike Stump11289f42009-09-09 15:08:12 +00003566
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003567 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3568 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3569 return SemaRef.StmtError();
3570
Douglas Gregorebe10102009-08-20 07:17:43 +00003571 // Transform the body
3572 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3573 if (Body.isInvalid())
3574 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregorebe10102009-08-20 07:17:43 +00003576 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003577 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003578 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003579 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003580 return SemaRef.Owned(S->Retain());
3581
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003582 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003583 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003584}
Mike Stump11289f42009-09-09 15:08:12 +00003585
Douglas Gregorebe10102009-08-20 07:17:43 +00003586template<typename Derived>
3587Sema::OwningStmtResult
3588TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003589 // Transform the body
3590 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3591 if (Body.isInvalid())
3592 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003593
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003594 // Transform the condition
3595 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3596 if (Cond.isInvalid())
3597 return SemaRef.StmtError();
3598
Douglas Gregorebe10102009-08-20 07:17:43 +00003599 if (!getDerived().AlwaysRebuild() &&
3600 Cond.get() == S->getCond() &&
3601 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003602 return SemaRef.Owned(S->Retain());
3603
Douglas Gregorebe10102009-08-20 07:17:43 +00003604 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3605 /*FIXME:*/S->getWhileLoc(), move(Cond),
3606 S->getRParenLoc());
3607}
Mike Stump11289f42009-09-09 15:08:12 +00003608
Douglas Gregorebe10102009-08-20 07:17:43 +00003609template<typename Derived>
3610Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003611TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003612 // Transform the initialization statement
3613 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3614 if (Init.isInvalid())
3615 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003616
Douglas Gregorebe10102009-08-20 07:17:43 +00003617 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003618 OwningExprResult Cond(SemaRef);
3619 VarDecl *ConditionVar = 0;
3620 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003621 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003622 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003623 getDerived().TransformDefinition(
3624 S->getConditionVariable()->getLocation(),
3625 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003626 if (!ConditionVar)
3627 return SemaRef.StmtError();
3628 } else {
3629 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003630
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003631 if (Cond.isInvalid())
3632 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003633
3634 if (S->getCond()) {
3635 // Convert the condition to a boolean value.
3636 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3637 S->getForLoc(),
3638 move(Cond));
3639 if (CondE.isInvalid())
3640 return getSema().StmtError();
3641
3642 Cond = move(CondE);
3643 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003644 }
Mike Stump11289f42009-09-09 15:08:12 +00003645
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003646 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3647 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3648 return SemaRef.StmtError();
3649
Douglas Gregorebe10102009-08-20 07:17:43 +00003650 // Transform the increment
3651 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3652 if (Inc.isInvalid())
3653 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003654
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003655 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3656 if (S->getInc() && !FullInc->get())
3657 return SemaRef.StmtError();
3658
Douglas Gregorebe10102009-08-20 07:17:43 +00003659 // Transform the body
3660 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3661 if (Body.isInvalid())
3662 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003663
Douglas Gregorebe10102009-08-20 07:17:43 +00003664 if (!getDerived().AlwaysRebuild() &&
3665 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003666 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003667 Inc.get() == S->getInc() &&
3668 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003669 return SemaRef.Owned(S->Retain());
3670
Douglas Gregorebe10102009-08-20 07:17:43 +00003671 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003672 move(Init), FullCond, ConditionVar,
3673 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003674}
3675
3676template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003677Sema::OwningStmtResult
3678TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003679 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003680 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003681 S->getLabel());
3682}
3683
3684template<typename Derived>
3685Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003686TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003687 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3688 if (Target.isInvalid())
3689 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 if (!getDerived().AlwaysRebuild() &&
3692 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003693 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003694
3695 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3696 move(Target));
3697}
3698
3699template<typename Derived>
3700Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003701TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3702 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003703}
Mike Stump11289f42009-09-09 15:08:12 +00003704
Douglas Gregorebe10102009-08-20 07:17:43 +00003705template<typename Derived>
3706Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003707TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3708 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003709}
Mike Stump11289f42009-09-09 15:08:12 +00003710
Douglas Gregorebe10102009-08-20 07:17:43 +00003711template<typename Derived>
3712Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3715 if (Result.isInvalid())
3716 return SemaRef.StmtError();
3717
Mike Stump11289f42009-09-09 15:08:12 +00003718 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003719 // to tell whether the return type of the function has changed.
3720 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3721}
Mike Stump11289f42009-09-09 15:08:12 +00003722
Douglas Gregorebe10102009-08-20 07:17:43 +00003723template<typename Derived>
3724Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003725TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003726 bool DeclChanged = false;
3727 llvm::SmallVector<Decl *, 4> Decls;
3728 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3729 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003730 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3731 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003732 if (!Transformed)
3733 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregorebe10102009-08-20 07:17:43 +00003735 if (Transformed != *D)
3736 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003737
Douglas Gregorebe10102009-08-20 07:17:43 +00003738 Decls.push_back(Transformed);
3739 }
Mike Stump11289f42009-09-09 15:08:12 +00003740
Douglas Gregorebe10102009-08-20 07:17:43 +00003741 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003742 return SemaRef.Owned(S->Retain());
3743
3744 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003745 S->getStartLoc(), S->getEndLoc());
3746}
Mike Stump11289f42009-09-09 15:08:12 +00003747
Douglas Gregorebe10102009-08-20 07:17:43 +00003748template<typename Derived>
3749Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003750TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003751 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003752 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003753}
3754
3755template<typename Derived>
3756Sema::OwningStmtResult
3757TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003758
Anders Carlssonaaeef072010-01-24 05:50:09 +00003759 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3760 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003761 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003762
Anders Carlssonaaeef072010-01-24 05:50:09 +00003763 OwningExprResult AsmString(SemaRef);
3764 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3765
3766 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003767
Anders Carlssonaaeef072010-01-24 05:50:09 +00003768 // Go through the outputs.
3769 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003770 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003771
Anders Carlssonaaeef072010-01-24 05:50:09 +00003772 // No need to transform the constraint literal.
3773 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003774
Anders Carlssonaaeef072010-01-24 05:50:09 +00003775 // Transform the output expr.
3776 Expr *OutputExpr = S->getOutputExpr(I);
3777 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3778 if (Result.isInvalid())
3779 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003780
Anders Carlssonaaeef072010-01-24 05:50:09 +00003781 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003782
Anders Carlssonaaeef072010-01-24 05:50:09 +00003783 Exprs.push_back(Result.takeAs<Expr>());
3784 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003785
Anders Carlssonaaeef072010-01-24 05:50:09 +00003786 // Go through the inputs.
3787 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003788 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003789
Anders Carlssonaaeef072010-01-24 05:50:09 +00003790 // No need to transform the constraint literal.
3791 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003792
Anders Carlssonaaeef072010-01-24 05:50:09 +00003793 // Transform the input expr.
3794 Expr *InputExpr = S->getInputExpr(I);
3795 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3796 if (Result.isInvalid())
3797 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003798
Anders Carlssonaaeef072010-01-24 05:50:09 +00003799 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003800
Anders Carlssonaaeef072010-01-24 05:50:09 +00003801 Exprs.push_back(Result.takeAs<Expr>());
3802 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003803
Anders Carlssonaaeef072010-01-24 05:50:09 +00003804 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3805 return SemaRef.Owned(S->Retain());
3806
3807 // Go through the clobbers.
3808 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3809 Clobbers.push_back(S->getClobber(I)->Retain());
3810
3811 // No need to transform the asm string literal.
3812 AsmString = SemaRef.Owned(S->getAsmString());
3813
3814 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3815 S->isSimple(),
3816 S->isVolatile(),
3817 S->getNumOutputs(),
3818 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003819 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003820 move_arg(Constraints),
3821 move_arg(Exprs),
3822 move(AsmString),
3823 move_arg(Clobbers),
3824 S->getRParenLoc(),
3825 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003826}
3827
3828
3829template<typename Derived>
3830Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003831TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003832 // Transform the body of the @try.
3833 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3834 if (TryBody.isInvalid())
3835 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003836
Douglas Gregor96c79492010-04-23 22:50:49 +00003837 // Transform the @catch statements (if present).
3838 bool AnyCatchChanged = false;
3839 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3840 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3841 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003842 if (Catch.isInvalid())
3843 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003844 if (Catch.get() != S->getCatchStmt(I))
3845 AnyCatchChanged = true;
3846 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003847 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003848
Douglas Gregor306de2f2010-04-22 23:59:56 +00003849 // Transform the @finally statement (if present).
3850 OwningStmtResult Finally(SemaRef);
3851 if (S->getFinallyStmt()) {
3852 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3853 if (Finally.isInvalid())
3854 return SemaRef.StmtError();
3855 }
3856
3857 // If nothing changed, just retain this statement.
3858 if (!getDerived().AlwaysRebuild() &&
3859 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003860 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003861 Finally.get() == S->getFinallyStmt())
3862 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003863
Douglas Gregor306de2f2010-04-22 23:59:56 +00003864 // Build a new statement.
3865 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003866 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003867}
Mike Stump11289f42009-09-09 15:08:12 +00003868
Douglas Gregorebe10102009-08-20 07:17:43 +00003869template<typename Derived>
3870Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003871TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003872 // Transform the @catch parameter, if there is one.
3873 VarDecl *Var = 0;
3874 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3875 TypeSourceInfo *TSInfo = 0;
3876 if (FromVar->getTypeSourceInfo()) {
3877 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3878 if (!TSInfo)
3879 return SemaRef.StmtError();
3880 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003881
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003882 QualType T;
3883 if (TSInfo)
3884 T = TSInfo->getType();
3885 else {
3886 T = getDerived().TransformType(FromVar->getType());
3887 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003888 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003889 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003890
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003891 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3892 if (!Var)
3893 return SemaRef.StmtError();
3894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003895
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003896 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3897 if (Body.isInvalid())
3898 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003899
3900 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003901 S->getRParenLoc(),
3902 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003903}
Mike Stump11289f42009-09-09 15:08:12 +00003904
Douglas Gregorebe10102009-08-20 07:17:43 +00003905template<typename Derived>
3906Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003907TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003908 // Transform the body.
3909 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3910 if (Body.isInvalid())
3911 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003912
Douglas Gregor306de2f2010-04-22 23:59:56 +00003913 // If nothing changed, just retain this statement.
3914 if (!getDerived().AlwaysRebuild() &&
3915 Body.get() == S->getFinallyBody())
3916 return SemaRef.Owned(S->Retain());
3917
3918 // Build a new statement.
3919 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3920 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003921}
Mike Stump11289f42009-09-09 15:08:12 +00003922
Douglas Gregorebe10102009-08-20 07:17:43 +00003923template<typename Derived>
3924Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003925TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003926 OwningExprResult Operand(SemaRef);
3927 if (S->getThrowExpr()) {
3928 Operand = getDerived().TransformExpr(S->getThrowExpr());
3929 if (Operand.isInvalid())
3930 return getSema().StmtError();
3931 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003932
Douglas Gregor2900c162010-04-22 21:44:01 +00003933 if (!getDerived().AlwaysRebuild() &&
3934 Operand.get() == S->getThrowExpr())
3935 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003936
Douglas Gregor2900c162010-04-22 21:44:01 +00003937 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003938}
Mike Stump11289f42009-09-09 15:08:12 +00003939
Douglas Gregorebe10102009-08-20 07:17:43 +00003940template<typename Derived>
3941Sema::OwningStmtResult
3942TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003943 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003944 // Transform the object we are locking.
3945 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3946 if (Object.isInvalid())
3947 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003948
Douglas Gregor6148de72010-04-22 22:01:21 +00003949 // Transform the body.
3950 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3951 if (Body.isInvalid())
3952 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003953
Douglas Gregor6148de72010-04-22 22:01:21 +00003954 // If nothing change, just retain the current statement.
3955 if (!getDerived().AlwaysRebuild() &&
3956 Object.get() == S->getSynchExpr() &&
3957 Body.get() == S->getSynchBody())
3958 return SemaRef.Owned(S->Retain());
3959
3960 // Build a new statement.
3961 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3962 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003963}
3964
3965template<typename Derived>
3966Sema::OwningStmtResult
3967TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003968 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003969 // Transform the element statement.
3970 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3971 if (Element.isInvalid())
3972 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003973
Douglas Gregorf68a5082010-04-22 23:10:45 +00003974 // Transform the collection expression.
3975 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3976 if (Collection.isInvalid())
3977 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978
Douglas Gregorf68a5082010-04-22 23:10:45 +00003979 // Transform the body.
3980 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3981 if (Body.isInvalid())
3982 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003983
Douglas Gregorf68a5082010-04-22 23:10:45 +00003984 // If nothing changed, just retain this statement.
3985 if (!getDerived().AlwaysRebuild() &&
3986 Element.get() == S->getElement() &&
3987 Collection.get() == S->getCollection() &&
3988 Body.get() == S->getBody())
3989 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
Douglas Gregorf68a5082010-04-22 23:10:45 +00003991 // Build a new statement.
3992 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
3993 /*FIXME:*/S->getForLoc(),
3994 move(Element),
3995 move(Collection),
3996 S->getRParenLoc(),
3997 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003998}
3999
4000
4001template<typename Derived>
4002Sema::OwningStmtResult
4003TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4004 // Transform the exception declaration, if any.
4005 VarDecl *Var = 0;
4006 if (S->getExceptionDecl()) {
4007 VarDecl *ExceptionDecl = S->getExceptionDecl();
4008 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4009 ExceptionDecl->getDeclName());
4010
4011 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4012 if (T.isNull())
4013 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004014
Douglas Gregorebe10102009-08-20 07:17:43 +00004015 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4016 T,
John McCallbcd03502009-12-07 02:54:59 +00004017 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004018 ExceptionDecl->getIdentifier(),
4019 ExceptionDecl->getLocation(),
4020 /*FIXME: Inaccurate*/
4021 SourceRange(ExceptionDecl->getLocation()));
4022 if (!Var || Var->isInvalidDecl()) {
4023 if (Var)
4024 Var->Destroy(SemaRef.Context);
4025 return SemaRef.StmtError();
4026 }
4027 }
Mike Stump11289f42009-09-09 15:08:12 +00004028
Douglas Gregorebe10102009-08-20 07:17:43 +00004029 // Transform the actual exception handler.
4030 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4031 if (Handler.isInvalid()) {
4032 if (Var)
4033 Var->Destroy(SemaRef.Context);
4034 return SemaRef.StmtError();
4035 }
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037 if (!getDerived().AlwaysRebuild() &&
4038 !Var &&
4039 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004040 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004041
4042 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4043 Var,
4044 move(Handler));
4045}
Mike Stump11289f42009-09-09 15:08:12 +00004046
Douglas Gregorebe10102009-08-20 07:17:43 +00004047template<typename Derived>
4048Sema::OwningStmtResult
4049TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4050 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004051 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004052 = getDerived().TransformCompoundStmt(S->getTryBlock());
4053 if (TryBlock.isInvalid())
4054 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004055
Douglas Gregorebe10102009-08-20 07:17:43 +00004056 // Transform the handlers.
4057 bool HandlerChanged = false;
4058 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4059 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004060 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004061 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4062 if (Handler.isInvalid())
4063 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004064
Douglas Gregorebe10102009-08-20 07:17:43 +00004065 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4066 Handlers.push_back(Handler.takeAs<Stmt>());
4067 }
Mike Stump11289f42009-09-09 15:08:12 +00004068
Douglas Gregorebe10102009-08-20 07:17:43 +00004069 if (!getDerived().AlwaysRebuild() &&
4070 TryBlock.get() == S->getTryBlock() &&
4071 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004072 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004073
4074 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004075 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004076}
Mike Stump11289f42009-09-09 15:08:12 +00004077
Douglas Gregorebe10102009-08-20 07:17:43 +00004078//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004079// Expression transformation
4080//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004081template<typename Derived>
4082Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004083TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004084 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004085}
Mike Stump11289f42009-09-09 15:08:12 +00004086
4087template<typename Derived>
4088Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004089TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004090 NestedNameSpecifier *Qualifier = 0;
4091 if (E->getQualifier()) {
4092 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004093 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004094 if (!Qualifier)
4095 return SemaRef.ExprError();
4096 }
John McCallce546572009-12-08 09:08:17 +00004097
4098 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004099 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4100 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004101 if (!ND)
4102 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004103
Alexis Hunta8136cc2010-05-05 15:23:54 +00004104 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004105 Qualifier == E->getQualifier() &&
4106 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004107 !E->hasExplicitTemplateArgumentList()) {
4108
4109 // Mark it referenced in the new context regardless.
4110 // FIXME: this is a bit instantiation-specific.
4111 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4112
Mike Stump11289f42009-09-09 15:08:12 +00004113 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004114 }
John McCallce546572009-12-08 09:08:17 +00004115
4116 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4117 if (E->hasExplicitTemplateArgumentList()) {
4118 TemplateArgs = &TransArgs;
4119 TransArgs.setLAngleLoc(E->getLAngleLoc());
4120 TransArgs.setRAngleLoc(E->getRAngleLoc());
4121 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4122 TemplateArgumentLoc Loc;
4123 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4124 return SemaRef.ExprError();
4125 TransArgs.addArgument(Loc);
4126 }
4127 }
4128
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004129 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004130 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004131}
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregora16548e2009-08-11 05:31:07 +00004133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004134Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004135TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004136 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004137}
Mike Stump11289f42009-09-09 15:08:12 +00004138
Douglas Gregora16548e2009-08-11 05:31:07 +00004139template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004140Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004141TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004142 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004143}
Mike Stump11289f42009-09-09 15:08:12 +00004144
Douglas Gregora16548e2009-08-11 05:31:07 +00004145template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004146Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004147TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004148 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004149}
Mike Stump11289f42009-09-09 15:08:12 +00004150
Douglas Gregora16548e2009-08-11 05:31:07 +00004151template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004152Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004153TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004154 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004155}
Mike Stump11289f42009-09-09 15:08:12 +00004156
Douglas Gregora16548e2009-08-11 05:31:07 +00004157template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004158Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004159TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004160 return SemaRef.Owned(E->Retain());
4161}
4162
4163template<typename Derived>
4164Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004165TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004166 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4167 if (SubExpr.isInvalid())
4168 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004169
Douglas Gregora16548e2009-08-11 05:31:07 +00004170 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004171 return SemaRef.Owned(E->Retain());
4172
4173 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004174 E->getRParen());
4175}
4176
Mike Stump11289f42009-09-09 15:08:12 +00004177template<typename Derived>
4178Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004179TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4180 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004181 if (SubExpr.isInvalid())
4182 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004183
Douglas Gregora16548e2009-08-11 05:31:07 +00004184 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004185 return SemaRef.Owned(E->Retain());
4186
Douglas Gregora16548e2009-08-11 05:31:07 +00004187 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4188 E->getOpcode(),
4189 move(SubExpr));
4190}
Mike Stump11289f42009-09-09 15:08:12 +00004191
Douglas Gregora16548e2009-08-11 05:31:07 +00004192template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004193Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004194TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4195 // Transform the type.
4196 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4197 if (!Type)
4198 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004199
Douglas Gregor882211c2010-04-28 22:16:22 +00004200 // Transform all of the components into components similar to what the
4201 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004202 // FIXME: It would be slightly more efficient in the non-dependent case to
4203 // just map FieldDecls, rather than requiring the rebuilder to look for
4204 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004205 // template code that we don't care.
4206 bool ExprChanged = false;
4207 typedef Action::OffsetOfComponent Component;
4208 typedef OffsetOfExpr::OffsetOfNode Node;
4209 llvm::SmallVector<Component, 4> Components;
4210 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4211 const Node &ON = E->getComponent(I);
4212 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004213 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004214 Comp.LocStart = ON.getRange().getBegin();
4215 Comp.LocEnd = ON.getRange().getEnd();
4216 switch (ON.getKind()) {
4217 case Node::Array: {
4218 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4219 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4220 if (Index.isInvalid())
4221 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004222
Douglas Gregor882211c2010-04-28 22:16:22 +00004223 ExprChanged = ExprChanged || Index.get() != FromIndex;
4224 Comp.isBrackets = true;
4225 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4226 break;
4227 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004228
Douglas Gregor882211c2010-04-28 22:16:22 +00004229 case Node::Field:
4230 case Node::Identifier:
4231 Comp.isBrackets = false;
4232 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004233 if (!Comp.U.IdentInfo)
4234 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004235
Douglas Gregor882211c2010-04-28 22:16:22 +00004236 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004237
Douglas Gregord1702062010-04-29 00:18:15 +00004238 case Node::Base:
4239 // Will be recomputed during the rebuild.
4240 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004241 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004242
Douglas Gregor882211c2010-04-28 22:16:22 +00004243 Components.push_back(Comp);
4244 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004245
Douglas Gregor882211c2010-04-28 22:16:22 +00004246 // If nothing changed, retain the existing expression.
4247 if (!getDerived().AlwaysRebuild() &&
4248 Type == E->getTypeSourceInfo() &&
4249 !ExprChanged)
4250 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004251
Douglas Gregor882211c2010-04-28 22:16:22 +00004252 // Build a new offsetof expression.
4253 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4254 Components.data(), Components.size(),
4255 E->getRParenLoc());
4256}
4257
4258template<typename Derived>
4259Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004261 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004262 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004263
John McCallbcd03502009-12-07 02:54:59 +00004264 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004265 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004266 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004267
John McCall4c98fd82009-11-04 07:28:41 +00004268 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004269 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004270
John McCall4c98fd82009-11-04 07:28:41 +00004271 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004272 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 E->getSourceRange());
4274 }
Mike Stump11289f42009-09-09 15:08:12 +00004275
Douglas Gregora16548e2009-08-11 05:31:07 +00004276 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004277 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 // C++0x [expr.sizeof]p1:
4279 // The operand is either an expression, which is an unevaluated operand
4280 // [...]
4281 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004282
Douglas Gregora16548e2009-08-11 05:31:07 +00004283 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4284 if (SubExpr.isInvalid())
4285 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004286
Douglas Gregora16548e2009-08-11 05:31:07 +00004287 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4288 return SemaRef.Owned(E->Retain());
4289 }
Mike Stump11289f42009-09-09 15:08:12 +00004290
Douglas Gregora16548e2009-08-11 05:31:07 +00004291 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4292 E->isSizeOf(),
4293 E->getSourceRange());
4294}
Mike Stump11289f42009-09-09 15:08:12 +00004295
Douglas Gregora16548e2009-08-11 05:31:07 +00004296template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004297Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004298TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4300 if (LHS.isInvalid())
4301 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004302
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4304 if (RHS.isInvalid())
4305 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004306
4307
Douglas Gregora16548e2009-08-11 05:31:07 +00004308 if (!getDerived().AlwaysRebuild() &&
4309 LHS.get() == E->getLHS() &&
4310 RHS.get() == E->getRHS())
4311 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004312
Douglas Gregora16548e2009-08-11 05:31:07 +00004313 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4314 /*FIXME:*/E->getLHS()->getLocStart(),
4315 move(RHS),
4316 E->getRBracketLoc());
4317}
Mike Stump11289f42009-09-09 15:08:12 +00004318
4319template<typename Derived>
4320Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004321TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004322 // Transform the callee.
4323 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4324 if (Callee.isInvalid())
4325 return SemaRef.ExprError();
4326
4327 // Transform arguments.
4328 bool ArgChanged = false;
4329 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4330 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4331 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4332 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4333 if (Arg.isInvalid())
4334 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004335
Douglas Gregora16548e2009-08-11 05:31:07 +00004336 // FIXME: Wrong source location information for the ','.
4337 FakeCommaLocs.push_back(
4338 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004339
4340 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004341 Args.push_back(Arg.takeAs<Expr>());
4342 }
Mike Stump11289f42009-09-09 15:08:12 +00004343
Douglas Gregora16548e2009-08-11 05:31:07 +00004344 if (!getDerived().AlwaysRebuild() &&
4345 Callee.get() == E->getCallee() &&
4346 !ArgChanged)
4347 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004348
Douglas Gregora16548e2009-08-11 05:31:07 +00004349 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004350 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004351 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4352 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4353 move_arg(Args),
4354 FakeCommaLocs.data(),
4355 E->getRParenLoc());
4356}
Mike Stump11289f42009-09-09 15:08:12 +00004357
4358template<typename Derived>
4359Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004360TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4362 if (Base.isInvalid())
4363 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004364
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004365 NestedNameSpecifier *Qualifier = 0;
4366 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004367 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004368 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004369 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004370 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004371 return SemaRef.ExprError();
4372 }
Mike Stump11289f42009-09-09 15:08:12 +00004373
Eli Friedman2cfcef62009-12-04 06:40:45 +00004374 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004375 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4376 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 if (!Member)
4378 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004379
John McCall16df1e52010-03-30 21:47:33 +00004380 NamedDecl *FoundDecl = E->getFoundDecl();
4381 if (FoundDecl == E->getMemberDecl()) {
4382 FoundDecl = Member;
4383 } else {
4384 FoundDecl = cast_or_null<NamedDecl>(
4385 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4386 if (!FoundDecl)
4387 return SemaRef.ExprError();
4388 }
4389
Douglas Gregora16548e2009-08-11 05:31:07 +00004390 if (!getDerived().AlwaysRebuild() &&
4391 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004392 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004393 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004394 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004395 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004396
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004397 // Mark it referenced in the new context regardless.
4398 // FIXME: this is a bit instantiation-specific.
4399 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004400 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004401 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004402
John McCall6b51f282009-11-23 01:53:49 +00004403 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004404 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004405 TransArgs.setLAngleLoc(E->getLAngleLoc());
4406 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004407 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004408 TemplateArgumentLoc Loc;
4409 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004410 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004411 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004412 }
4413 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004414
Douglas Gregora16548e2009-08-11 05:31:07 +00004415 // FIXME: Bogus source location for the operator
4416 SourceLocation FakeOperatorLoc
4417 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4418
John McCall38836f02010-01-15 08:34:02 +00004419 // FIXME: to do this check properly, we will need to preserve the
4420 // first-qualifier-in-scope here, just in case we had a dependent
4421 // base (and therefore couldn't do the check) and a
4422 // nested-name-qualifier (and therefore could do the lookup).
4423 NamedDecl *FirstQualifierInScope = 0;
4424
Douglas Gregora16548e2009-08-11 05:31:07 +00004425 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4426 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004427 Qualifier,
4428 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004429 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004430 Member,
John McCall16df1e52010-03-30 21:47:33 +00004431 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004432 (E->hasExplicitTemplateArgumentList()
4433 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004434 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004435}
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004438Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004439TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004440 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4441 if (LHS.isInvalid())
4442 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004443
Douglas Gregora16548e2009-08-11 05:31:07 +00004444 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4445 if (RHS.isInvalid())
4446 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004447
Douglas Gregora16548e2009-08-11 05:31:07 +00004448 if (!getDerived().AlwaysRebuild() &&
4449 LHS.get() == E->getLHS() &&
4450 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004451 return SemaRef.Owned(E->Retain());
4452
Douglas Gregora16548e2009-08-11 05:31:07 +00004453 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4454 move(LHS), move(RHS));
4455}
4456
Mike Stump11289f42009-09-09 15:08:12 +00004457template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004458Sema::OwningExprResult
4459TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004460 CompoundAssignOperator *E) {
4461 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004462}
Mike Stump11289f42009-09-09 15:08:12 +00004463
Douglas Gregora16548e2009-08-11 05:31:07 +00004464template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004465Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004466TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004467 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4468 if (Cond.isInvalid())
4469 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004470
Douglas Gregora16548e2009-08-11 05:31:07 +00004471 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4472 if (LHS.isInvalid())
4473 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004474
Douglas Gregora16548e2009-08-11 05:31:07 +00004475 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4476 if (RHS.isInvalid())
4477 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004478
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 if (!getDerived().AlwaysRebuild() &&
4480 Cond.get() == E->getCond() &&
4481 LHS.get() == E->getLHS() &&
4482 RHS.get() == E->getRHS())
4483 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004484
4485 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004486 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004487 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004488 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004489 move(RHS));
4490}
Mike Stump11289f42009-09-09 15:08:12 +00004491
4492template<typename Derived>
4493Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004494TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004495 // Implicit casts are eliminated during transformation, since they
4496 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004497 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004498}
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregora16548e2009-08-11 05:31:07 +00004500template<typename Derived>
4501Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004502TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004503 TypeSourceInfo *OldT;
4504 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004505 {
4506 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004507 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004508 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4509 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004510
John McCall97513962010-01-15 18:39:57 +00004511 OldT = E->getTypeInfoAsWritten();
4512 NewT = getDerived().TransformType(OldT);
4513 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004514 return SemaRef.ExprError();
4515 }
Mike Stump11289f42009-09-09 15:08:12 +00004516
Douglas Gregor6131b442009-12-12 18:16:41 +00004517 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004518 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004519 if (SubExpr.isInvalid())
4520 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004521
Douglas Gregora16548e2009-08-11 05:31:07 +00004522 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004523 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004524 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004525 return SemaRef.Owned(E->Retain());
4526
John McCall97513962010-01-15 18:39:57 +00004527 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4528 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004529 E->getRParenLoc(),
4530 move(SubExpr));
4531}
Mike Stump11289f42009-09-09 15:08:12 +00004532
Douglas Gregora16548e2009-08-11 05:31:07 +00004533template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004534Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004535TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004536 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4537 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4538 if (!NewT)
4539 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004540
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4542 if (Init.isInvalid())
4543 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004546 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004547 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004548 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004549
John McCall5d7aa7f2010-01-19 22:33:45 +00004550 // Note: the expression type doesn't necessarily match the
4551 // type-as-written, but that's okay, because it should always be
4552 // derivable from the initializer.
4553
John McCalle15bbff2010-01-18 19:35:47 +00004554 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004555 /*FIXME:*/E->getInitializer()->getLocEnd(),
4556 move(Init));
4557}
Mike Stump11289f42009-09-09 15:08:12 +00004558
Douglas Gregora16548e2009-08-11 05:31:07 +00004559template<typename Derived>
4560Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004561TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004562 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4563 if (Base.isInvalid())
4564 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004565
Douglas Gregora16548e2009-08-11 05:31:07 +00004566 if (!getDerived().AlwaysRebuild() &&
4567 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004568 return SemaRef.Owned(E->Retain());
4569
Douglas Gregora16548e2009-08-11 05:31:07 +00004570 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004571 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4573 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4574 E->getAccessorLoc(),
4575 E->getAccessor());
4576}
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004579Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004580TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004581 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004582
Douglas Gregora16548e2009-08-11 05:31:07 +00004583 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4584 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4585 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4586 if (Init.isInvalid())
4587 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004588
Douglas Gregora16548e2009-08-11 05:31:07 +00004589 InitChanged = InitChanged || Init.get() != E->getInit(I);
4590 Inits.push_back(Init.takeAs<Expr>());
4591 }
Mike Stump11289f42009-09-09 15:08:12 +00004592
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004594 return SemaRef.Owned(E->Retain());
4595
Douglas Gregora16548e2009-08-11 05:31:07 +00004596 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004597 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004598}
Mike Stump11289f42009-09-09 15:08:12 +00004599
Douglas Gregora16548e2009-08-11 05:31:07 +00004600template<typename Derived>
4601Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004602TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004603 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004604
Douglas Gregorebe10102009-08-20 07:17:43 +00004605 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4607 if (Init.isInvalid())
4608 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004609
Douglas Gregorebe10102009-08-20 07:17:43 +00004610 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004611 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4612 bool ExprChanged = false;
4613 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4614 DEnd = E->designators_end();
4615 D != DEnd; ++D) {
4616 if (D->isFieldDesignator()) {
4617 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4618 D->getDotLoc(),
4619 D->getFieldLoc()));
4620 continue;
4621 }
Mike Stump11289f42009-09-09 15:08:12 +00004622
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 if (D->isArrayDesignator()) {
4624 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4625 if (Index.isInvalid())
4626 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004627
4628 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004629 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregora16548e2009-08-11 05:31:07 +00004631 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4632 ArrayExprs.push_back(Index.release());
4633 continue;
4634 }
Mike Stump11289f42009-09-09 15:08:12 +00004635
Douglas Gregora16548e2009-08-11 05:31:07 +00004636 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004637 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004638 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4639 if (Start.isInvalid())
4640 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4643 if (End.isInvalid())
4644 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004645
4646 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004647 End.get(),
4648 D->getLBracketLoc(),
4649 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004650
Douglas Gregora16548e2009-08-11 05:31:07 +00004651 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4652 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 ArrayExprs.push_back(Start.release());
4655 ArrayExprs.push_back(End.release());
4656 }
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregora16548e2009-08-11 05:31:07 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 Init.get() == E->getInit() &&
4660 !ExprChanged)
4661 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4664 E->getEqualOrColonLoc(),
4665 E->usesGNUSyntax(), move(Init));
4666}
Mike Stump11289f42009-09-09 15:08:12 +00004667
Douglas Gregora16548e2009-08-11 05:31:07 +00004668template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004669Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004670TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004671 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004672 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004673
Douglas Gregor3da3c062009-10-28 00:29:27 +00004674 // FIXME: Will we ever have proper type location here? Will we actually
4675 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004676 QualType T = getDerived().TransformType(E->getType());
4677 if (T.isNull())
4678 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680 if (!getDerived().AlwaysRebuild() &&
4681 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004682 return SemaRef.Owned(E->Retain());
4683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 return getDerived().RebuildImplicitValueInitExpr(T);
4685}
Mike Stump11289f42009-09-09 15:08:12 +00004686
Douglas Gregora16548e2009-08-11 05:31:07 +00004687template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004688Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004689TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 // FIXME: Do we want the type as written?
4691 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004692
Douglas Gregora16548e2009-08-11 05:31:07 +00004693 {
4694 // FIXME: Source location isn't quite accurate.
4695 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4696 T = getDerived().TransformType(E->getType());
4697 if (T.isNull())
4698 return SemaRef.ExprError();
4699 }
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4702 if (SubExpr.isInvalid())
4703 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 if (!getDerived().AlwaysRebuild() &&
4706 T == E->getType() &&
4707 SubExpr.get() == E->getSubExpr())
4708 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004709
Douglas Gregora16548e2009-08-11 05:31:07 +00004710 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4711 T, E->getRParenLoc());
4712}
4713
4714template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004715Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004716TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 bool ArgumentChanged = false;
4718 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4719 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4720 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4721 if (Init.isInvalid())
4722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004723
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4725 Inits.push_back(Init.takeAs<Expr>());
4726 }
Mike Stump11289f42009-09-09 15:08:12 +00004727
Douglas Gregora16548e2009-08-11 05:31:07 +00004728 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4729 move_arg(Inits),
4730 E->getRParenLoc());
4731}
Mike Stump11289f42009-09-09 15:08:12 +00004732
Douglas Gregora16548e2009-08-11 05:31:07 +00004733/// \brief Transform an address-of-label expression.
4734///
4735/// By default, the transformation of an address-of-label expression always
4736/// rebuilds the expression, so that the label identifier can be resolved to
4737/// the corresponding label statement by semantic analysis.
4738template<typename Derived>
4739Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004740TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004741 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4742 E->getLabel());
4743}
Mike Stump11289f42009-09-09 15:08:12 +00004744
4745template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004746Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004747TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004748 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004749 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4750 if (SubStmt.isInvalid())
4751 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004752
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 if (!getDerived().AlwaysRebuild() &&
4754 SubStmt.get() == E->getSubStmt())
4755 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004756
4757 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004758 move(SubStmt),
4759 E->getRParenLoc());
4760}
Mike Stump11289f42009-09-09 15:08:12 +00004761
Douglas Gregora16548e2009-08-11 05:31:07 +00004762template<typename Derived>
4763Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004764TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 QualType T1, T2;
4766 {
4767 // FIXME: Source location isn't quite accurate.
4768 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004769
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 T1 = getDerived().TransformType(E->getArgType1());
4771 if (T1.isNull())
4772 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774 T2 = getDerived().TransformType(E->getArgType2());
4775 if (T2.isNull())
4776 return SemaRef.ExprError();
4777 }
4778
4779 if (!getDerived().AlwaysRebuild() &&
4780 T1 == E->getArgType1() &&
4781 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004782 return SemaRef.Owned(E->Retain());
4783
Douglas Gregora16548e2009-08-11 05:31:07 +00004784 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4785 T1, T2, E->getRParenLoc());
4786}
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788template<typename Derived>
4789Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004790TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4792 if (Cond.isInvalid())
4793 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004794
Douglas Gregora16548e2009-08-11 05:31:07 +00004795 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4796 if (LHS.isInvalid())
4797 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004798
Douglas Gregora16548e2009-08-11 05:31:07 +00004799 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4800 if (RHS.isInvalid())
4801 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004802
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 if (!getDerived().AlwaysRebuild() &&
4804 Cond.get() == E->getCond() &&
4805 LHS.get() == E->getLHS() &&
4806 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004807 return SemaRef.Owned(E->Retain());
4808
Douglas Gregora16548e2009-08-11 05:31:07 +00004809 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4810 move(Cond), move(LHS), move(RHS),
4811 E->getRParenLoc());
4812}
Mike Stump11289f42009-09-09 15:08:12 +00004813
Douglas Gregora16548e2009-08-11 05:31:07 +00004814template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004815Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004816TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004817 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004818}
4819
4820template<typename Derived>
4821Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004822TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004823 switch (E->getOperator()) {
4824 case OO_New:
4825 case OO_Delete:
4826 case OO_Array_New:
4827 case OO_Array_Delete:
4828 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4829 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004830
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004831 case OO_Call: {
4832 // This is a call to an object's operator().
4833 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4834
4835 // Transform the object itself.
4836 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4837 if (Object.isInvalid())
4838 return SemaRef.ExprError();
4839
4840 // FIXME: Poor location information
4841 SourceLocation FakeLParenLoc
4842 = SemaRef.PP.getLocForEndOfToken(
4843 static_cast<Expr *>(Object.get())->getLocEnd());
4844
4845 // Transform the call arguments.
4846 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4847 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4848 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004849 if (getDerived().DropCallArgument(E->getArg(I)))
4850 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004851
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004852 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4853 if (Arg.isInvalid())
4854 return SemaRef.ExprError();
4855
4856 // FIXME: Poor source location information.
4857 SourceLocation FakeCommaLoc
4858 = SemaRef.PP.getLocForEndOfToken(
4859 static_cast<Expr *>(Arg.get())->getLocEnd());
4860 FakeCommaLocs.push_back(FakeCommaLoc);
4861 Args.push_back(Arg.release());
4862 }
4863
4864 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4865 move_arg(Args),
4866 FakeCommaLocs.data(),
4867 E->getLocEnd());
4868 }
4869
4870#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4871 case OO_##Name:
4872#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4873#include "clang/Basic/OperatorKinds.def"
4874 case OO_Subscript:
4875 // Handled below.
4876 break;
4877
4878 case OO_Conditional:
4879 llvm_unreachable("conditional operator is not actually overloadable");
4880 return SemaRef.ExprError();
4881
4882 case OO_None:
4883 case NUM_OVERLOADED_OPERATORS:
4884 llvm_unreachable("not an overloaded operator?");
4885 return SemaRef.ExprError();
4886 }
4887
Douglas Gregora16548e2009-08-11 05:31:07 +00004888 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4889 if (Callee.isInvalid())
4890 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004891
John McCall47f29ea2009-12-08 09:21:05 +00004892 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004893 if (First.isInvalid())
4894 return SemaRef.ExprError();
4895
4896 OwningExprResult Second(SemaRef);
4897 if (E->getNumArgs() == 2) {
4898 Second = getDerived().TransformExpr(E->getArg(1));
4899 if (Second.isInvalid())
4900 return SemaRef.ExprError();
4901 }
Mike Stump11289f42009-09-09 15:08:12 +00004902
Douglas Gregora16548e2009-08-11 05:31:07 +00004903 if (!getDerived().AlwaysRebuild() &&
4904 Callee.get() == E->getCallee() &&
4905 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004906 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4907 return SemaRef.Owned(E->Retain());
4908
Douglas Gregora16548e2009-08-11 05:31:07 +00004909 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4910 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004911 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004912 move(First),
4913 move(Second));
4914}
Mike Stump11289f42009-09-09 15:08:12 +00004915
Douglas Gregora16548e2009-08-11 05:31:07 +00004916template<typename Derived>
4917Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004918TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4919 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004920}
Mike Stump11289f42009-09-09 15:08:12 +00004921
Douglas Gregora16548e2009-08-11 05:31:07 +00004922template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004923Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004924TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004925 TypeSourceInfo *OldT;
4926 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004927 {
4928 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004929 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004930 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4931 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004932
John McCall97513962010-01-15 18:39:57 +00004933 OldT = E->getTypeInfoAsWritten();
4934 NewT = getDerived().TransformType(OldT);
4935 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004936 return SemaRef.ExprError();
4937 }
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregor6131b442009-12-12 18:16:41 +00004939 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004940 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004941 if (SubExpr.isInvalid())
4942 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregora16548e2009-08-11 05:31:07 +00004944 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004945 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004946 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004947 return SemaRef.Owned(E->Retain());
4948
Douglas Gregora16548e2009-08-11 05:31:07 +00004949 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004950 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004951 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4952 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4953 SourceLocation FakeRParenLoc
4954 = SemaRef.PP.getLocForEndOfToken(
4955 E->getSubExpr()->getSourceRange().getEnd());
4956 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004957 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004959 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004960 FakeRAngleLoc,
4961 FakeRAngleLoc,
4962 move(SubExpr),
4963 FakeRParenLoc);
4964}
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregora16548e2009-08-11 05:31:07 +00004966template<typename Derived>
4967Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004968TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4969 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004970}
Mike Stump11289f42009-09-09 15:08:12 +00004971
4972template<typename Derived>
4973Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004974TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4975 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004976}
4977
Douglas Gregora16548e2009-08-11 05:31:07 +00004978template<typename Derived>
4979Sema::OwningExprResult
4980TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004981 CXXReinterpretCastExpr *E) {
4982 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004983}
Mike Stump11289f42009-09-09 15:08:12 +00004984
Douglas Gregora16548e2009-08-11 05:31:07 +00004985template<typename Derived>
4986Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004987TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
4988 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004989}
Mike Stump11289f42009-09-09 15:08:12 +00004990
Douglas Gregora16548e2009-08-11 05:31:07 +00004991template<typename Derived>
4992Sema::OwningExprResult
4993TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004994 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004995 TypeSourceInfo *OldT;
4996 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004997 {
4998 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCall97513962010-01-15 18:39:57 +00005000 OldT = E->getTypeInfoAsWritten();
5001 NewT = getDerived().TransformType(OldT);
5002 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005003 return SemaRef.ExprError();
5004 }
Mike Stump11289f42009-09-09 15:08:12 +00005005
Douglas Gregor6131b442009-12-12 18:16:41 +00005006 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005007 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005008 if (SubExpr.isInvalid())
5009 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregora16548e2009-08-11 05:31:07 +00005011 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005012 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005014 return SemaRef.Owned(E->Retain());
5015
Douglas Gregora16548e2009-08-11 05:31:07 +00005016 // FIXME: The end of the type's source range is wrong
5017 return getDerived().RebuildCXXFunctionalCastExpr(
5018 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005019 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 /*FIXME:*/E->getSubExpr()->getLocStart(),
5021 move(SubExpr),
5022 E->getRParenLoc());
5023}
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregora16548e2009-08-11 05:31:07 +00005025template<typename Derived>
5026Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005027TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005029 TypeSourceInfo *TInfo
5030 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5031 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005033
Douglas Gregora16548e2009-08-11 05:31:07 +00005034 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005035 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005036 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregor9da64192010-04-26 22:37:10 +00005038 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5039 E->getLocStart(),
5040 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005041 E->getLocEnd());
5042 }
Mike Stump11289f42009-09-09 15:08:12 +00005043
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 // We don't know whether the expression is potentially evaluated until
5045 // after we perform semantic analysis, so the expression is potentially
5046 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005047 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5051 if (SubExpr.isInvalid())
5052 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005053
Douglas Gregora16548e2009-08-11 05:31:07 +00005054 if (!getDerived().AlwaysRebuild() &&
5055 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005056 return SemaRef.Owned(E->Retain());
5057
Douglas Gregor9da64192010-04-26 22:37:10 +00005058 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5059 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 move(SubExpr),
5061 E->getLocEnd());
5062}
5063
5064template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005065Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005066TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005067 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005068}
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregora16548e2009-08-11 05:31:07 +00005070template<typename Derived>
5071Sema::OwningExprResult
5072TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005073 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005074 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005075}
Mike Stump11289f42009-09-09 15:08:12 +00005076
Douglas Gregora16548e2009-08-11 05:31:07 +00005077template<typename Derived>
5078Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005079TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005080 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082 QualType T = getDerived().TransformType(E->getType());
5083 if (T.isNull())
5084 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086 if (!getDerived().AlwaysRebuild() &&
5087 T == E->getType())
5088 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005089
Douglas Gregorb15af892010-01-07 23:12:05 +00005090 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005091}
Mike Stump11289f42009-09-09 15:08:12 +00005092
Douglas Gregora16548e2009-08-11 05:31:07 +00005093template<typename Derived>
5094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005095TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005096 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5097 if (SubExpr.isInvalid())
5098 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100 if (!getDerived().AlwaysRebuild() &&
5101 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005102 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103
5104 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5105}
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregora16548e2009-08-11 05:31:07 +00005107template<typename Derived>
5108Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005109TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005110 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005111 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5112 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005113 if (!Param)
5114 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005115
Chandler Carruth794da4c2010-02-08 06:42:49 +00005116 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 Param == E->getParam())
5118 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregor033f6752009-12-23 23:03:06 +00005120 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005121}
Mike Stump11289f42009-09-09 15:08:12 +00005122
Douglas Gregora16548e2009-08-11 05:31:07 +00005123template<typename Derived>
5124Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005125TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005126 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5127
5128 QualType T = getDerived().TransformType(E->getType());
5129 if (T.isNull())
5130 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregora16548e2009-08-11 05:31:07 +00005132 if (!getDerived().AlwaysRebuild() &&
5133 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005134 return SemaRef.Owned(E->Retain());
5135
5136 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 /*FIXME:*/E->getTypeBeginLoc(),
5138 T,
5139 E->getRParenLoc());
5140}
Mike Stump11289f42009-09-09 15:08:12 +00005141
Douglas Gregora16548e2009-08-11 05:31:07 +00005142template<typename Derived>
5143Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005144TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 // Transform the type that we're allocating
5146 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5147 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5148 if (AllocType.isNull())
5149 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 // Transform the size of the array we're allocating (if any).
5152 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5153 if (ArraySize.isInvalid())
5154 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005155
Douglas Gregora16548e2009-08-11 05:31:07 +00005156 // Transform the placement arguments (if any).
5157 bool ArgumentChanged = false;
5158 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5159 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5160 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5161 if (Arg.isInvalid())
5162 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005163
Douglas Gregora16548e2009-08-11 05:31:07 +00005164 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5165 PlacementArgs.push_back(Arg.take());
5166 }
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregorebe10102009-08-20 07:17:43 +00005168 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005169 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5170 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5171 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5172 if (Arg.isInvalid())
5173 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005174
Douglas Gregora16548e2009-08-11 05:31:07 +00005175 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5176 ConstructorArgs.push_back(Arg.take());
5177 }
Mike Stump11289f42009-09-09 15:08:12 +00005178
Douglas Gregord2d9da02010-02-26 00:38:10 +00005179 // Transform constructor, new operator, and delete operator.
5180 CXXConstructorDecl *Constructor = 0;
5181 if (E->getConstructor()) {
5182 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005183 getDerived().TransformDecl(E->getLocStart(),
5184 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005185 if (!Constructor)
5186 return SemaRef.ExprError();
5187 }
5188
5189 FunctionDecl *OperatorNew = 0;
5190 if (E->getOperatorNew()) {
5191 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005192 getDerived().TransformDecl(E->getLocStart(),
5193 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005194 if (!OperatorNew)
5195 return SemaRef.ExprError();
5196 }
5197
5198 FunctionDecl *OperatorDelete = 0;
5199 if (E->getOperatorDelete()) {
5200 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005201 getDerived().TransformDecl(E->getLocStart(),
5202 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005203 if (!OperatorDelete)
5204 return SemaRef.ExprError();
5205 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005206
Douglas Gregora16548e2009-08-11 05:31:07 +00005207 if (!getDerived().AlwaysRebuild() &&
5208 AllocType == E->getAllocatedType() &&
5209 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005210 Constructor == E->getConstructor() &&
5211 OperatorNew == E->getOperatorNew() &&
5212 OperatorDelete == E->getOperatorDelete() &&
5213 !ArgumentChanged) {
5214 // Mark any declarations we need as referenced.
5215 // FIXME: instantiation-specific.
5216 if (Constructor)
5217 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5218 if (OperatorNew)
5219 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5220 if (OperatorDelete)
5221 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005222 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005223 }
Mike Stump11289f42009-09-09 15:08:12 +00005224
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005225 if (!ArraySize.get()) {
5226 // If no array size was specified, but the new expression was
5227 // instantiated with an array type (e.g., "new T" where T is
5228 // instantiated with "int[4]"), extract the outer bound from the
5229 // array type as our array size. We do this with constant and
5230 // dependently-sized array types.
5231 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5232 if (!ArrayT) {
5233 // Do nothing
5234 } else if (const ConstantArrayType *ConsArrayT
5235 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005236 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005237 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005238 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005239 SemaRef.Context.getSizeType(),
5240 /*FIXME:*/E->getLocStart()));
5241 AllocType = ConsArrayT->getElementType();
5242 } else if (const DependentSizedArrayType *DepArrayT
5243 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5244 if (DepArrayT->getSizeExpr()) {
5245 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5246 AllocType = DepArrayT->getElementType();
5247 }
5248 }
5249 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005250 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5251 E->isGlobalNew(),
5252 /*FIXME:*/E->getLocStart(),
5253 move_arg(PlacementArgs),
5254 /*FIXME:*/E->getLocStart(),
5255 E->isParenTypeId(),
5256 AllocType,
5257 /*FIXME:*/E->getLocStart(),
5258 /*FIXME:*/SourceRange(),
5259 move(ArraySize),
5260 /*FIXME:*/E->getLocStart(),
5261 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005262 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265template<typename Derived>
5266Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005267TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005268 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5269 if (Operand.isInvalid())
5270 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005271
Douglas Gregord2d9da02010-02-26 00:38:10 +00005272 // Transform the delete operator, if known.
5273 FunctionDecl *OperatorDelete = 0;
5274 if (E->getOperatorDelete()) {
5275 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005276 getDerived().TransformDecl(E->getLocStart(),
5277 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005278 if (!OperatorDelete)
5279 return SemaRef.ExprError();
5280 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005281
Douglas Gregora16548e2009-08-11 05:31:07 +00005282 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005283 Operand.get() == E->getArgument() &&
5284 OperatorDelete == E->getOperatorDelete()) {
5285 // Mark any declarations we need as referenced.
5286 // FIXME: instantiation-specific.
5287 if (OperatorDelete)
5288 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005289 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005290 }
Mike Stump11289f42009-09-09 15:08:12 +00005291
Douglas Gregora16548e2009-08-11 05:31:07 +00005292 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5293 E->isGlobalDelete(),
5294 E->isArrayForm(),
5295 move(Operand));
5296}
Mike Stump11289f42009-09-09 15:08:12 +00005297
Douglas Gregora16548e2009-08-11 05:31:07 +00005298template<typename Derived>
5299Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005300TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005301 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005302 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5303 if (Base.isInvalid())
5304 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregor678f90d2010-02-25 01:56:36 +00005306 Sema::TypeTy *ObjectTypePtr = 0;
5307 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005308 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005309 E->getOperatorLoc(),
5310 E->isArrow()? tok::arrow : tok::period,
5311 ObjectTypePtr,
5312 MayBePseudoDestructor);
5313 if (Base.isInvalid())
5314 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005315
Douglas Gregor678f90d2010-02-25 01:56:36 +00005316 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005317 NestedNameSpecifier *Qualifier
5318 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005319 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005320 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005321 if (E->getQualifier() && !Qualifier)
5322 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005323
Douglas Gregor678f90d2010-02-25 01:56:36 +00005324 PseudoDestructorTypeStorage Destroyed;
5325 if (E->getDestroyedTypeInfo()) {
5326 TypeSourceInfo *DestroyedTypeInfo
5327 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5328 if (!DestroyedTypeInfo)
5329 return SemaRef.ExprError();
5330 Destroyed = DestroyedTypeInfo;
5331 } else if (ObjectType->isDependentType()) {
5332 // We aren't likely to be able to resolve the identifier down to a type
5333 // now anyway, so just retain the identifier.
5334 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5335 E->getDestroyedTypeLoc());
5336 } else {
5337 // Look for a destructor known with the given name.
5338 CXXScopeSpec SS;
5339 if (Qualifier) {
5340 SS.setScopeRep(Qualifier);
5341 SS.setRange(E->getQualifierRange());
5342 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005343
Douglas Gregor678f90d2010-02-25 01:56:36 +00005344 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5345 *E->getDestroyedTypeIdentifier(),
5346 E->getDestroyedTypeLoc(),
5347 /*Scope=*/0,
5348 SS, ObjectTypePtr,
5349 false);
5350 if (!T)
5351 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005352
Douglas Gregor678f90d2010-02-25 01:56:36 +00005353 Destroyed
5354 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5355 E->getDestroyedTypeLoc());
5356 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005357
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005358 TypeSourceInfo *ScopeTypeInfo = 0;
5359 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005360 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005361 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005362 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005363 return SemaRef.ExprError();
5364 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005365
Douglas Gregorad8a3362009-09-04 17:36:40 +00005366 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5367 E->getOperatorLoc(),
5368 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005369 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005370 E->getQualifierRange(),
5371 ScopeTypeInfo,
5372 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005373 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005374 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005375}
Mike Stump11289f42009-09-09 15:08:12 +00005376
Douglas Gregorad8a3362009-09-04 17:36:40 +00005377template<typename Derived>
5378Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005379TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005380 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005381 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5382
5383 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5384 Sema::LookupOrdinaryName);
5385
5386 // Transform all the decls.
5387 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5388 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005389 NamedDecl *InstD = static_cast<NamedDecl*>(
5390 getDerived().TransformDecl(Old->getNameLoc(),
5391 *I));
John McCall84d87672009-12-10 09:41:52 +00005392 if (!InstD) {
5393 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5394 // This can happen because of dependent hiding.
5395 if (isa<UsingShadowDecl>(*I))
5396 continue;
5397 else
5398 return SemaRef.ExprError();
5399 }
John McCalle66edc12009-11-24 19:00:30 +00005400
5401 // Expand using declarations.
5402 if (isa<UsingDecl>(InstD)) {
5403 UsingDecl *UD = cast<UsingDecl>(InstD);
5404 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5405 E = UD->shadow_end(); I != E; ++I)
5406 R.addDecl(*I);
5407 continue;
5408 }
5409
5410 R.addDecl(InstD);
5411 }
5412
5413 // Resolve a kind, but don't do any further analysis. If it's
5414 // ambiguous, the callee needs to deal with it.
5415 R.resolveKind();
5416
5417 // Rebuild the nested-name qualifier, if present.
5418 CXXScopeSpec SS;
5419 NestedNameSpecifier *Qualifier = 0;
5420 if (Old->getQualifier()) {
5421 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005422 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005423 if (!Qualifier)
5424 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005425
John McCalle66edc12009-11-24 19:00:30 +00005426 SS.setScopeRep(Qualifier);
5427 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005428 }
5429
Douglas Gregor9262f472010-04-27 18:19:34 +00005430 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005431 CXXRecordDecl *NamingClass
5432 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5433 Old->getNameLoc(),
5434 Old->getNamingClass()));
5435 if (!NamingClass)
5436 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005437
Douglas Gregorda7be082010-04-27 16:10:10 +00005438 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005439 }
5440
5441 // If we have no template arguments, it's a normal declaration name.
5442 if (!Old->hasExplicitTemplateArgs())
5443 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5444
5445 // If we have template arguments, rebuild them, then rebuild the
5446 // templateid expression.
5447 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5448 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5449 TemplateArgumentLoc Loc;
5450 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5451 return SemaRef.ExprError();
5452 TransArgs.addArgument(Loc);
5453 }
5454
5455 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5456 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005457}
Mike Stump11289f42009-09-09 15:08:12 +00005458
Douglas Gregora16548e2009-08-11 05:31:07 +00005459template<typename Derived>
5460Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005461TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005462 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005463
Douglas Gregora16548e2009-08-11 05:31:07 +00005464 QualType T = getDerived().TransformType(E->getQueriedType());
5465 if (T.isNull())
5466 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 T == E->getQueriedType())
5470 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005471
Douglas Gregora16548e2009-08-11 05:31:07 +00005472 // FIXME: Bad location information
5473 SourceLocation FakeLParenLoc
5474 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005475
5476 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005477 E->getLocStart(),
5478 /*FIXME:*/FakeLParenLoc,
5479 T,
5480 E->getLocEnd());
5481}
Mike Stump11289f42009-09-09 15:08:12 +00005482
Douglas Gregora16548e2009-08-11 05:31:07 +00005483template<typename Derived>
5484Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005485TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005486 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005487 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005488 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005489 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005490 if (!NNS)
5491 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005492
5493 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005494 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5495 if (!Name)
5496 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005497
John McCalle66edc12009-11-24 19:00:30 +00005498 if (!E->hasExplicitTemplateArgs()) {
5499 if (!getDerived().AlwaysRebuild() &&
5500 NNS == E->getQualifier() &&
5501 Name == E->getDeclName())
5502 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005503
John McCalle66edc12009-11-24 19:00:30 +00005504 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5505 E->getQualifierRange(),
5506 Name, E->getLocation(),
5507 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005508 }
John McCall6b51f282009-11-23 01:53:49 +00005509
5510 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005511 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005512 TemplateArgumentLoc Loc;
5513 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005514 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005515 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 }
5517
John McCalle66edc12009-11-24 19:00:30 +00005518 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5519 E->getQualifierRange(),
5520 Name, E->getLocation(),
5521 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005522}
5523
5524template<typename Derived>
5525Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005526TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005527 // CXXConstructExprs are always implicit, so when we have a
5528 // 1-argument construction we just transform that argument.
5529 if (E->getNumArgs() == 1 ||
5530 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5531 return getDerived().TransformExpr(E->getArg(0));
5532
Douglas Gregora16548e2009-08-11 05:31:07 +00005533 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5534
5535 QualType T = getDerived().TransformType(E->getType());
5536 if (T.isNull())
5537 return SemaRef.ExprError();
5538
5539 CXXConstructorDecl *Constructor
5540 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005541 getDerived().TransformDecl(E->getLocStart(),
5542 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005543 if (!Constructor)
5544 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregora16548e2009-08-11 05:31:07 +00005546 bool ArgumentChanged = false;
5547 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005548 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005549 ArgEnd = E->arg_end();
5550 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005551 if (getDerived().DropCallArgument(*Arg)) {
5552 ArgumentChanged = true;
5553 break;
5554 }
5555
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5557 if (TransArg.isInvalid())
5558 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregora16548e2009-08-11 05:31:07 +00005560 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5561 Args.push_back(TransArg.takeAs<Expr>());
5562 }
5563
5564 if (!getDerived().AlwaysRebuild() &&
5565 T == E->getType() &&
5566 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005567 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005568 // Mark the constructor as referenced.
5569 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005570 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005571 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005572 }
Mike Stump11289f42009-09-09 15:08:12 +00005573
Douglas Gregordb121ba2009-12-14 16:27:04 +00005574 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5575 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 move_arg(Args));
5577}
Mike Stump11289f42009-09-09 15:08:12 +00005578
Douglas Gregora16548e2009-08-11 05:31:07 +00005579/// \brief Transform a C++ temporary-binding expression.
5580///
Douglas Gregor363b1512009-12-24 18:51:59 +00005581/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5582/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005583template<typename Derived>
5584Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005585TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005586 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005587}
Mike Stump11289f42009-09-09 15:08:12 +00005588
Anders Carlssonba6c4372010-01-29 02:39:32 +00005589/// \brief Transform a C++ reference-binding expression.
5590///
5591/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5592/// transform the subexpression and return that.
5593template<typename Derived>
5594Sema::OwningExprResult
5595TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5596 return getDerived().TransformExpr(E->getSubExpr());
5597}
5598
Mike Stump11289f42009-09-09 15:08:12 +00005599/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005600/// be destroyed after the expression is evaluated.
5601///
Douglas Gregor363b1512009-12-24 18:51:59 +00005602/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5603/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005604template<typename Derived>
5605Sema::OwningExprResult
5606TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005607 CXXExprWithTemporaries *E) {
5608 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005609}
Mike Stump11289f42009-09-09 15:08:12 +00005610
Douglas Gregora16548e2009-08-11 05:31:07 +00005611template<typename Derived>
5612Sema::OwningExprResult
5613TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005614 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5616 QualType T = getDerived().TransformType(E->getType());
5617 if (T.isNull())
5618 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005619
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 CXXConstructorDecl *Constructor
5621 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005622 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005623 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005624 if (!Constructor)
5625 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005626
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 bool ArgumentChanged = false;
5628 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5629 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005630 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005631 ArgEnd = E->arg_end();
5632 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005633 if (getDerived().DropCallArgument(*Arg)) {
5634 ArgumentChanged = true;
5635 break;
5636 }
5637
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5639 if (TransArg.isInvalid())
5640 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005641
Douglas Gregora16548e2009-08-11 05:31:07 +00005642 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5643 Args.push_back((Expr *)TransArg.release());
5644 }
Mike Stump11289f42009-09-09 15:08:12 +00005645
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (!getDerived().AlwaysRebuild() &&
5647 T == E->getType() &&
5648 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005649 !ArgumentChanged) {
5650 // FIXME: Instantiation-specific
5651 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005652 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005653 }
Mike Stump11289f42009-09-09 15:08:12 +00005654
Douglas Gregora16548e2009-08-11 05:31:07 +00005655 // FIXME: Bogus location information
5656 SourceLocation CommaLoc;
5657 if (Args.size() > 1) {
5658 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005659 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5661 }
5662 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5663 T,
5664 /*FIXME:*/E->getTypeBeginLoc(),
5665 move_arg(Args),
5666 &CommaLoc,
5667 E->getLocEnd());
5668}
Mike Stump11289f42009-09-09 15:08:12 +00005669
Douglas Gregora16548e2009-08-11 05:31:07 +00005670template<typename Derived>
5671Sema::OwningExprResult
5672TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005673 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5675 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5676 if (T.isNull())
5677 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005678
Douglas Gregora16548e2009-08-11 05:31:07 +00005679 bool ArgumentChanged = false;
5680 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5681 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5682 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5683 ArgEnd = E->arg_end();
5684 Arg != ArgEnd; ++Arg) {
5685 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5686 if (TransArg.isInvalid())
5687 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005688
Douglas Gregora16548e2009-08-11 05:31:07 +00005689 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5690 FakeCommaLocs.push_back(
5691 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5692 Args.push_back(TransArg.takeAs<Expr>());
5693 }
Mike Stump11289f42009-09-09 15:08:12 +00005694
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 if (!getDerived().AlwaysRebuild() &&
5696 T == E->getTypeAsWritten() &&
5697 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005698 return SemaRef.Owned(E->Retain());
5699
Douglas Gregora16548e2009-08-11 05:31:07 +00005700 // FIXME: we're faking the locations of the commas
5701 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5702 T,
5703 E->getLParenLoc(),
5704 move_arg(Args),
5705 FakeCommaLocs.data(),
5706 E->getRParenLoc());
5707}
Mike Stump11289f42009-09-09 15:08:12 +00005708
Douglas Gregora16548e2009-08-11 05:31:07 +00005709template<typename Derived>
5710Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005711TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005712 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005713 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005714 OwningExprResult Base(SemaRef, (Expr*) 0);
5715 Expr *OldBase;
5716 QualType BaseType;
5717 QualType ObjectType;
5718 if (!E->isImplicitAccess()) {
5719 OldBase = E->getBase();
5720 Base = getDerived().TransformExpr(OldBase);
5721 if (Base.isInvalid())
5722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
John McCall2d74de92009-12-01 22:10:20 +00005724 // Start the member reference and compute the object's type.
5725 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005726 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005727 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5728 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005729 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005730 ObjectTy,
5731 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005732 if (Base.isInvalid())
5733 return SemaRef.ExprError();
5734
5735 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5736 BaseType = ((Expr*) Base.get())->getType();
5737 } else {
5738 OldBase = 0;
5739 BaseType = getDerived().TransformType(E->getBaseType());
5740 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5741 }
Mike Stump11289f42009-09-09 15:08:12 +00005742
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005743 // Transform the first part of the nested-name-specifier that qualifies
5744 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005745 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005746 = getDerived().TransformFirstQualifierInScope(
5747 E->getFirstQualifierFoundInScope(),
5748 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005749
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005750 NestedNameSpecifier *Qualifier = 0;
5751 if (E->getQualifier()) {
5752 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5753 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005754 ObjectType,
5755 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005756 if (!Qualifier)
5757 return SemaRef.ExprError();
5758 }
Mike Stump11289f42009-09-09 15:08:12 +00005759
5760 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005761 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005762 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005763 if (!Name)
5764 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005765
John McCall2d74de92009-12-01 22:10:20 +00005766 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005767 // This is a reference to a member without an explicitly-specified
5768 // template argument list. Optimize for this common case.
5769 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005770 Base.get() == OldBase &&
5771 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005772 Qualifier == E->getQualifier() &&
5773 Name == E->getMember() &&
5774 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005775 return SemaRef.Owned(E->Retain());
5776
John McCall8cd78132009-11-19 22:55:06 +00005777 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005778 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005779 E->isArrow(),
5780 E->getOperatorLoc(),
5781 Qualifier,
5782 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005783 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005784 Name,
5785 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005786 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005787 }
5788
John McCall6b51f282009-11-23 01:53:49 +00005789 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005790 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005791 TemplateArgumentLoc Loc;
5792 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005793 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005794 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005795 }
Mike Stump11289f42009-09-09 15:08:12 +00005796
John McCall8cd78132009-11-19 22:55:06 +00005797 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005798 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005799 E->isArrow(),
5800 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005801 Qualifier,
5802 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005803 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005804 Name,
5805 E->getMemberLoc(),
5806 &TransArgs);
5807}
5808
5809template<typename Derived>
5810Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005811TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005812 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005813 OwningExprResult Base(SemaRef, (Expr*) 0);
5814 QualType BaseType;
5815 if (!Old->isImplicitAccess()) {
5816 Base = getDerived().TransformExpr(Old->getBase());
5817 if (Base.isInvalid())
5818 return SemaRef.ExprError();
5819 BaseType = ((Expr*) Base.get())->getType();
5820 } else {
5821 BaseType = getDerived().TransformType(Old->getBaseType());
5822 }
John McCall10eae182009-11-30 22:42:35 +00005823
5824 NestedNameSpecifier *Qualifier = 0;
5825 if (Old->getQualifier()) {
5826 Qualifier
5827 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005828 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005829 if (Qualifier == 0)
5830 return SemaRef.ExprError();
5831 }
5832
5833 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5834 Sema::LookupOrdinaryName);
5835
5836 // Transform all the decls.
5837 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5838 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005839 NamedDecl *InstD = static_cast<NamedDecl*>(
5840 getDerived().TransformDecl(Old->getMemberLoc(),
5841 *I));
John McCall84d87672009-12-10 09:41:52 +00005842 if (!InstD) {
5843 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5844 // This can happen because of dependent hiding.
5845 if (isa<UsingShadowDecl>(*I))
5846 continue;
5847 else
5848 return SemaRef.ExprError();
5849 }
John McCall10eae182009-11-30 22:42:35 +00005850
5851 // Expand using declarations.
5852 if (isa<UsingDecl>(InstD)) {
5853 UsingDecl *UD = cast<UsingDecl>(InstD);
5854 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5855 E = UD->shadow_end(); I != E; ++I)
5856 R.addDecl(*I);
5857 continue;
5858 }
5859
5860 R.addDecl(InstD);
5861 }
5862
5863 R.resolveKind();
5864
Douglas Gregor9262f472010-04-27 18:19:34 +00005865 // Determine the naming class.
5866 if (!Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005867 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005868 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005869 Old->getMemberLoc(),
5870 Old->getNamingClass()));
5871 if (!NamingClass)
5872 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005873
Douglas Gregorda7be082010-04-27 16:10:10 +00005874 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005875 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005876
John McCall10eae182009-11-30 22:42:35 +00005877 TemplateArgumentListInfo TransArgs;
5878 if (Old->hasExplicitTemplateArgs()) {
5879 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5880 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5881 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5882 TemplateArgumentLoc Loc;
5883 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5884 Loc))
5885 return SemaRef.ExprError();
5886 TransArgs.addArgument(Loc);
5887 }
5888 }
John McCall38836f02010-01-15 08:34:02 +00005889
5890 // FIXME: to do this check properly, we will need to preserve the
5891 // first-qualifier-in-scope here, just in case we had a dependent
5892 // base (and therefore couldn't do the check) and a
5893 // nested-name-qualifier (and therefore could do the lookup).
5894 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005895
John McCall10eae182009-11-30 22:42:35 +00005896 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005897 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005898 Old->getOperatorLoc(),
5899 Old->isArrow(),
5900 Qualifier,
5901 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005902 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005903 R,
5904 (Old->hasExplicitTemplateArgs()
5905 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005906}
5907
5908template<typename Derived>
5909Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005910TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005911 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005912}
5913
Mike Stump11289f42009-09-09 15:08:12 +00005914template<typename Derived>
5915Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005916TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005917 TypeSourceInfo *EncodedTypeInfo
5918 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5919 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005921
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005923 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005924 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005925
5926 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005927 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005928 E->getRParenLoc());
5929}
Mike Stump11289f42009-09-09 15:08:12 +00005930
Douglas Gregora16548e2009-08-11 05:31:07 +00005931template<typename Derived>
5932Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005933TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005934 // Transform arguments.
5935 bool ArgChanged = false;
5936 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5937 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5938 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5939 if (Arg.isInvalid())
5940 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005941
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005942 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5943 Args.push_back(Arg.takeAs<Expr>());
5944 }
5945
5946 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5947 // Class message: transform the receiver type.
5948 TypeSourceInfo *ReceiverTypeInfo
5949 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5950 if (!ReceiverTypeInfo)
5951 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005952
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005953 // If nothing changed, just retain the existing message send.
5954 if (!getDerived().AlwaysRebuild() &&
5955 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5956 return SemaRef.Owned(E->Retain());
5957
5958 // Build a new class message send.
5959 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5960 E->getSelector(),
5961 E->getMethodDecl(),
5962 E->getLeftLoc(),
5963 move_arg(Args),
5964 E->getRightLoc());
5965 }
5966
5967 // Instance message: transform the receiver
5968 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5969 "Only class and instance messages may be instantiated");
5970 OwningExprResult Receiver
5971 = getDerived().TransformExpr(E->getInstanceReceiver());
5972 if (Receiver.isInvalid())
5973 return SemaRef.ExprError();
5974
5975 // If nothing changed, just retain the existing message send.
5976 if (!getDerived().AlwaysRebuild() &&
5977 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5978 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005979
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005980 // Build a new instance message send.
5981 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5982 E->getSelector(),
5983 E->getMethodDecl(),
5984 E->getLeftLoc(),
5985 move_arg(Args),
5986 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005987}
5988
Mike Stump11289f42009-09-09 15:08:12 +00005989template<typename Derived>
5990Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005991TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005992 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005993}
5994
Mike Stump11289f42009-09-09 15:08:12 +00005995template<typename Derived>
5996Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005997TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005998 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005999}
6000
Mike Stump11289f42009-09-09 15:08:12 +00006001template<typename Derived>
6002Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006003TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006004 // Transform the base expression.
6005 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6006 if (Base.isInvalid())
6007 return SemaRef.ExprError();
6008
6009 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006010
Douglas Gregord51d90d2010-04-26 20:11:03 +00006011 // If nothing changed, just retain the existing expression.
6012 if (!getDerived().AlwaysRebuild() &&
6013 Base.get() == E->getBase())
6014 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006015
Douglas Gregord51d90d2010-04-26 20:11:03 +00006016 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6017 E->getLocation(),
6018 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006019}
6020
Mike Stump11289f42009-09-09 15:08:12 +00006021template<typename Derived>
6022Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006023TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006024 // Transform the base expression.
6025 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6026 if (Base.isInvalid())
6027 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006028
Douglas Gregor9faee212010-04-26 20:47:02 +00006029 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006030
Douglas Gregor9faee212010-04-26 20:47:02 +00006031 // If nothing changed, just retain the existing expression.
6032 if (!getDerived().AlwaysRebuild() &&
6033 Base.get() == E->getBase())
6034 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006035
Douglas Gregor9faee212010-04-26 20:47:02 +00006036 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6037 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006038}
6039
Mike Stump11289f42009-09-09 15:08:12 +00006040template<typename Derived>
6041Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006042TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006043 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006044 // If this implicit setter/getter refers to class methods, it cannot have any
6045 // dependent parts. Just retain the existing declaration.
6046 if (E->getInterfaceDecl())
6047 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006048
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006049 // Transform the base expression.
6050 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6051 if (Base.isInvalid())
6052 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006053
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006054 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006055
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006056 // If nothing changed, just retain the existing expression.
6057 if (!getDerived().AlwaysRebuild() &&
6058 Base.get() == E->getBase())
6059 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006060
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006061 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6062 E->getGetterMethod(),
6063 E->getType(),
6064 E->getSetterMethod(),
6065 E->getLocation(),
6066 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregora16548e2009-08-11 05:31:07 +00006068}
6069
Mike Stump11289f42009-09-09 15:08:12 +00006070template<typename Derived>
6071Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006072TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006073 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006074 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006075}
6076
Mike Stump11289f42009-09-09 15:08:12 +00006077template<typename Derived>
6078Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006079TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006080 // Transform the base expression.
6081 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6082 if (Base.isInvalid())
6083 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006084
Douglas Gregord51d90d2010-04-26 20:11:03 +00006085 // If nothing changed, just retain the existing expression.
6086 if (!getDerived().AlwaysRebuild() &&
6087 Base.get() == E->getBase())
6088 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006089
Douglas Gregord51d90d2010-04-26 20:11:03 +00006090 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6091 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006092}
6093
Mike Stump11289f42009-09-09 15:08:12 +00006094template<typename Derived>
6095Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006096TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006097 bool ArgumentChanged = false;
6098 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6099 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6100 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6101 if (SubExpr.isInvalid())
6102 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006103
Douglas Gregora16548e2009-08-11 05:31:07 +00006104 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6105 SubExprs.push_back(SubExpr.takeAs<Expr>());
6106 }
Mike Stump11289f42009-09-09 15:08:12 +00006107
Douglas Gregora16548e2009-08-11 05:31:07 +00006108 if (!getDerived().AlwaysRebuild() &&
6109 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006110 return SemaRef.Owned(E->Retain());
6111
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6113 move_arg(SubExprs),
6114 E->getRParenLoc());
6115}
6116
Mike Stump11289f42009-09-09 15:08:12 +00006117template<typename Derived>
6118Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 // FIXME: Implement this!
6121 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006122 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006123}
6124
Mike Stump11289f42009-09-09 15:08:12 +00006125template<typename Derived>
6126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006128 // FIXME: Implement this!
6129 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006130 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006131}
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregora16548e2009-08-11 05:31:07 +00006133//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006134// Type reconstruction
6135//===----------------------------------------------------------------------===//
6136
Mike Stump11289f42009-09-09 15:08:12 +00006137template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006138QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6139 SourceLocation Star) {
6140 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006141 getDerived().getBaseEntity());
6142}
6143
Mike Stump11289f42009-09-09 15:08:12 +00006144template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006145QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6146 SourceLocation Star) {
6147 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006148 getDerived().getBaseEntity());
6149}
6150
Mike Stump11289f42009-09-09 15:08:12 +00006151template<typename Derived>
6152QualType
John McCall70dd5f62009-10-30 00:06:24 +00006153TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6154 bool WrittenAsLValue,
6155 SourceLocation Sigil) {
6156 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6157 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006158}
6159
6160template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006161QualType
John McCall70dd5f62009-10-30 00:06:24 +00006162TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6163 QualType ClassType,
6164 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006165 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006166 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006167}
6168
6169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006170QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006171TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6172 ArrayType::ArraySizeModifier SizeMod,
6173 const llvm::APInt *Size,
6174 Expr *SizeExpr,
6175 unsigned IndexTypeQuals,
6176 SourceRange BracketsRange) {
6177 if (SizeExpr || !Size)
6178 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6179 IndexTypeQuals, BracketsRange,
6180 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006181
6182 QualType Types[] = {
6183 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6184 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6185 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006186 };
6187 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6188 QualType SizeType;
6189 for (unsigned I = 0; I != NumTypes; ++I)
6190 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6191 SizeType = Types[I];
6192 break;
6193 }
Mike Stump11289f42009-09-09 15:08:12 +00006194
Douglas Gregord6ff3322009-08-04 16:50:30 +00006195 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006196 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006197 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006198 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006199}
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregord6ff3322009-08-04 16:50:30 +00006201template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006202QualType
6203TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006204 ArrayType::ArraySizeModifier SizeMod,
6205 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006206 unsigned IndexTypeQuals,
6207 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006208 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006209 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006210}
6211
6212template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006213QualType
Mike Stump11289f42009-09-09 15:08:12 +00006214TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006215 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006216 unsigned IndexTypeQuals,
6217 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006218 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006219 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006220}
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregord6ff3322009-08-04 16:50:30 +00006222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006223QualType
6224TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006225 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006226 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006227 unsigned IndexTypeQuals,
6228 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006229 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006230 SizeExpr.takeAs<Expr>(),
6231 IndexTypeQuals, BracketsRange);
6232}
6233
6234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006235QualType
6236TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006237 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006238 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006239 unsigned IndexTypeQuals,
6240 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006241 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006242 SizeExpr.takeAs<Expr>(),
6243 IndexTypeQuals, BracketsRange);
6244}
6245
6246template<typename Derived>
6247QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006248 unsigned NumElements,
6249 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006250 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006251 return SemaRef.Context.getVectorType(ElementType, NumElements,
6252 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006253}
Mike Stump11289f42009-09-09 15:08:12 +00006254
Douglas Gregord6ff3322009-08-04 16:50:30 +00006255template<typename Derived>
6256QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6257 unsigned NumElements,
6258 SourceLocation AttributeLoc) {
6259 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6260 NumElements, true);
6261 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006262 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006263 AttributeLoc);
6264 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6265 AttributeLoc);
6266}
Mike Stump11289f42009-09-09 15:08:12 +00006267
Douglas Gregord6ff3322009-08-04 16:50:30 +00006268template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006269QualType
6270TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006271 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006272 SourceLocation AttributeLoc) {
6273 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6274}
Mike Stump11289f42009-09-09 15:08:12 +00006275
Douglas Gregord6ff3322009-08-04 16:50:30 +00006276template<typename Derived>
6277QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006278 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006279 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006280 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006281 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006282 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006283 Quals,
6284 getDerived().getBaseLocation(),
6285 getDerived().getBaseEntity());
6286}
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregord6ff3322009-08-04 16:50:30 +00006288template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006289QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6290 return SemaRef.Context.getFunctionNoProtoType(T);
6291}
6292
6293template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006294QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6295 assert(D && "no decl found");
6296 if (D->isInvalidDecl()) return QualType();
6297
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006298 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006299 TypeDecl *Ty;
6300 if (isa<UsingDecl>(D)) {
6301 UsingDecl *Using = cast<UsingDecl>(D);
6302 assert(Using->isTypeName() &&
6303 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6304
6305 // A valid resolved using typename decl points to exactly one type decl.
6306 assert(++Using->shadow_begin() == Using->shadow_end());
6307 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006308
John McCallb96ec562009-12-04 22:46:56 +00006309 } else {
6310 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6311 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6312 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6313 }
6314
6315 return SemaRef.Context.getTypeDeclType(Ty);
6316}
6317
6318template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006319QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006320 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6321}
6322
6323template<typename Derived>
6324QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6325 return SemaRef.Context.getTypeOfType(Underlying);
6326}
6327
6328template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006329QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006330 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6331}
6332
6333template<typename Derived>
6334QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006335 TemplateName Template,
6336 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006337 const TemplateArgumentListInfo &TemplateArgs) {
6338 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006339}
Mike Stump11289f42009-09-09 15:08:12 +00006340
Douglas Gregor1135c352009-08-06 05:28:30 +00006341template<typename Derived>
6342NestedNameSpecifier *
6343TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6344 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006345 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006346 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006347 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006348 CXXScopeSpec SS;
6349 // FIXME: The source location information is all wrong.
6350 SS.setRange(Range);
6351 SS.setScopeRep(Prefix);
6352 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006353 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006354 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006355 ObjectType,
6356 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006357 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006358}
6359
6360template<typename Derived>
6361NestedNameSpecifier *
6362TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6363 SourceRange Range,
6364 NamespaceDecl *NS) {
6365 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6366}
6367
6368template<typename Derived>
6369NestedNameSpecifier *
6370TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6371 SourceRange Range,
6372 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006373 QualType T) {
6374 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006375 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006376 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006377 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6378 T.getTypePtr());
6379 }
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregor1135c352009-08-06 05:28:30 +00006381 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6382 return 0;
6383}
Mike Stump11289f42009-09-09 15:08:12 +00006384
Douglas Gregor71dc5092009-08-06 06:41:21 +00006385template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006386TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006387TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6388 bool TemplateKW,
6389 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006390 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006391 Template);
6392}
6393
6394template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006395TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006396TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006397 const IdentifierInfo &II,
6398 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006399 CXXScopeSpec SS;
6400 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006401 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006402 UnqualifiedId Name;
6403 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006404 return getSema().ActOnDependentTemplateName(
6405 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006406 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006407 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006408 ObjectType.getAsOpaquePtr(),
6409 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006410 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006411}
Mike Stump11289f42009-09-09 15:08:12 +00006412
Douglas Gregora16548e2009-08-11 05:31:07 +00006413template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006414TemplateName
6415TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6416 OverloadedOperatorKind Operator,
6417 QualType ObjectType) {
6418 CXXScopeSpec SS;
6419 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6420 SS.setScopeRep(Qualifier);
6421 UnqualifiedId Name;
6422 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6423 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6424 Operator, SymbolLocations);
6425 return getSema().ActOnDependentTemplateName(
6426 /*FIXME:*/getDerived().getBaseLocation(),
6427 SS,
6428 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006429 ObjectType.getAsOpaquePtr(),
6430 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006431 .template getAsVal<TemplateName>();
6432}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006433
Douglas Gregor71395fa2009-11-04 00:56:37 +00006434template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006435Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006436TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6437 SourceLocation OpLoc,
6438 ExprArg Callee,
6439 ExprArg First,
6440 ExprArg Second) {
6441 Expr *FirstExpr = (Expr *)First.get();
6442 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006443 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006444 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006445
Douglas Gregora16548e2009-08-11 05:31:07 +00006446 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006447 if (Op == OO_Subscript) {
6448 if (!FirstExpr->getType()->isOverloadableType() &&
6449 !SecondExpr->getType()->isOverloadableType())
6450 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006451 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006452 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006453 } else if (Op == OO_Arrow) {
6454 // -> is never a builtin operation.
6455 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006456 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006457 if (!FirstExpr->getType()->isOverloadableType()) {
6458 // The argument is not of overloadable type, so try to create a
6459 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006460 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006461 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006462
Douglas Gregora16548e2009-08-11 05:31:07 +00006463 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6464 }
6465 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006466 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006467 !SecondExpr->getType()->isOverloadableType()) {
6468 // Neither of the arguments is an overloadable type, so try to
6469 // create a built-in binary operation.
6470 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006471 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006472 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6473 if (Result.isInvalid())
6474 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006475
Douglas Gregora16548e2009-08-11 05:31:07 +00006476 First.release();
6477 Second.release();
6478 return move(Result);
6479 }
6480 }
Mike Stump11289f42009-09-09 15:08:12 +00006481
6482 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006484 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006485
John McCalld14a8642009-11-21 08:51:07 +00006486 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6487 assert(ULE->requiresADL());
6488
6489 // FIXME: Do we have to check
6490 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006491 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006492 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006493 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006494 }
Mike Stump11289f42009-09-09 15:08:12 +00006495
Douglas Gregora16548e2009-08-11 05:31:07 +00006496 // Add any functions found via argument-dependent lookup.
6497 Expr *Args[2] = { FirstExpr, SecondExpr };
6498 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006499
Douglas Gregora16548e2009-08-11 05:31:07 +00006500 // Create the overloaded operator invocation for unary operators.
6501 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006502 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006503 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6504 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6505 }
Mike Stump11289f42009-09-09 15:08:12 +00006506
Sebastian Redladba46e2009-10-29 20:17:01 +00006507 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006508 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6509 OpLoc,
6510 move(First),
6511 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006512
Douglas Gregora16548e2009-08-11 05:31:07 +00006513 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006514 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006515 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006516 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006517 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6518 if (Result.isInvalid())
6519 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006520
Douglas Gregora16548e2009-08-11 05:31:07 +00006521 First.release();
6522 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006523 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006524}
Mike Stump11289f42009-09-09 15:08:12 +00006525
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006526template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006527Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006528TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6529 SourceLocation OperatorLoc,
6530 bool isArrow,
6531 NestedNameSpecifier *Qualifier,
6532 SourceRange QualifierRange,
6533 TypeSourceInfo *ScopeType,
6534 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006535 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006536 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006537 CXXScopeSpec SS;
6538 if (Qualifier) {
6539 SS.setRange(QualifierRange);
6540 SS.setScopeRep(Qualifier);
6541 }
6542
6543 Expr *BaseE = (Expr *)Base.get();
6544 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006545 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006546 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006547 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006548 !BaseType->getAs<PointerType>()->getPointeeType()
6549 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006550 // This pseudo-destructor expression is still a pseudo-destructor.
6551 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6552 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006553 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006554 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006555 /*FIXME?*/true);
6556 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006557
Douglas Gregor678f90d2010-02-25 01:56:36 +00006558 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006559 DeclarationName Name
6560 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6561 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006562
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006563 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006564
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006565 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6566 OperatorLoc, isArrow,
6567 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006568 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006569 /*TemplateArgs*/ 0);
6570}
6571
Douglas Gregord6ff3322009-08-04 16:50:30 +00006572} // end namespace clang
6573
6574#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H