blob: 43ffbfb737b210af0e3c5c6d4717c5d73d29dc44 [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
495 /// \brief Build a new elaborated type.
496 QualType RebuildElaboratedType(QualType T, ElaboratedType::TagKind Tag) {
497 return SemaRef.Context.getElaboratedType(T, Tag);
498 }
Mike Stump11289f42009-09-09 15:08:12 +0000499
500 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000501 ///
502 /// By default, performs semantic analysis when building the typeof type.
503 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000504 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, builds a new TypeOfType with the given underlying type.
509 QualType RebuildTypeOfType(QualType Underlying);
510
Mike Stump11289f42009-09-09 15:08:12 +0000511 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 ///
513 /// By default, performs semantic analysis when building the decltype type.
514 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000515 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregord6ff3322009-08-04 16:50:30 +0000517 /// \brief Build a new template specialization type.
518 ///
519 /// By default, performs semantic analysis when building the template
520 /// specialization type. Subclasses may override this routine to provide
521 /// different behavior.
522 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000523 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000524 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new qualified name type.
527 ///
Mike Stump11289f42009-09-09 15:08:12 +0000528 /// By default, builds a new QualifiedNameType type from the
529 /// nested-name-specifier and the named type. Subclasses may override
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530 /// this routine to provide different behavior.
531 QualType RebuildQualifiedNameType(NestedNameSpecifier *NNS, QualType Named) {
532 return SemaRef.Context.getQualifiedNameType(NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000533 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000534
535 /// \brief Build a new typename type that refers to a template-id.
536 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000537 /// By default, builds a new DependentNameType type from the
Douglas Gregore677daf2010-03-31 22:19:08 +0000538 /// nested-name-specifier
Mike Stump11289f42009-09-09 15:08:12 +0000539 /// and the given type. Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000540 /// different behavior.
Douglas Gregor02085352010-03-31 20:19:30 +0000541 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
542 NestedNameSpecifier *NNS, QualType T) {
Douglas Gregor04922cb2010-02-13 06:05:33 +0000543 if (NNS->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000544 // If the name is still dependent, just build a new dependent name type.
Douglas Gregor04922cb2010-02-13 06:05:33 +0000545 CXXScopeSpec SS;
546 SS.setScopeRep(NNS);
547 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor02085352010-03-31 20:19:30 +0000548 return SemaRef.Context.getDependentNameType(Keyword, NNS,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000549 cast<TemplateSpecializationType>(T));
Douglas Gregor04922cb2010-02-13 06:05:33 +0000550 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000551
Douglas Gregor02085352010-03-31 20:19:30 +0000552 // FIXME: Handle elaborated-type-specifiers separately.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000553 return SemaRef.Context.getQualifiedNameType(NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000554 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000555
556 /// \brief Build a new typename type that refers to an identifier.
557 ///
558 /// By default, performs semantic analysis when building the typename type
Mike Stump11289f42009-09-09 15:08:12 +0000559 /// (or qualified name type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 /// different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000561 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000562 NestedNameSpecifier *NNS,
563 const IdentifierInfo *Id,
564 SourceRange SR) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000565 CXXScopeSpec SS;
566 SS.setScopeRep(NNS);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000567
Douglas Gregore677daf2010-03-31 22:19:08 +0000568 if (NNS->isDependent()) {
569 // If the name is still dependent, just build a new dependent name type.
570 if (!SemaRef.computeDeclContext(SS))
571 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
572 }
573
574 TagDecl::TagKind Kind = TagDecl::TK_enum;
575 switch (Keyword) {
576 case ETK_None:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000577 // Fall through.
Douglas Gregore677daf2010-03-31 22:19:08 +0000578 case ETK_Typename:
Douglas Gregorbbdf20a2010-04-24 15:35:55 +0000579 return SemaRef.CheckTypenameType(Keyword, NNS, *Id, SR);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000580
Douglas Gregore677daf2010-03-31 22:19:08 +0000581 case ETK_Class: Kind = TagDecl::TK_class; break;
582 case ETK_Struct: Kind = TagDecl::TK_struct; break;
583 case ETK_Union: Kind = TagDecl::TK_union; break;
584 case ETK_Enum: Kind = TagDecl::TK_enum; break;
585 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000586
Douglas Gregore677daf2010-03-31 22:19:08 +0000587 // We had a dependent elaborated-type-specifier that as been transformed
588 // into a non-dependent elaborated-type-specifier. Find the tag we're
589 // referring to.
590 LookupResult Result(SemaRef, Id, SR.getEnd(), Sema::LookupTagName);
591 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
592 if (!DC)
593 return QualType();
594
595 TagDecl *Tag = 0;
596 SemaRef.LookupQualifiedName(Result, DC);
597 switch (Result.getResultKind()) {
598 case LookupResult::NotFound:
599 case LookupResult::NotFoundInCurrentInstantiation:
600 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000601
Douglas Gregore677daf2010-03-31 22:19:08 +0000602 case LookupResult::Found:
603 Tag = Result.getAsSingle<TagDecl>();
604 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000605
Douglas Gregore677daf2010-03-31 22:19:08 +0000606 case LookupResult::FoundOverloaded:
607 case LookupResult::FoundUnresolvedValue:
608 llvm_unreachable("Tag lookup cannot find non-tags");
609 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000610
Douglas Gregore677daf2010-03-31 22:19:08 +0000611 case LookupResult::Ambiguous:
612 // Let the LookupResult structure handle ambiguities.
613 return QualType();
614 }
615
616 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000617 // FIXME: Would be nice to highlight just the source range.
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 SemaRef.Diag(SR.getEnd(), diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000619 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000620 return QualType();
621 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000622
Douglas Gregore677daf2010-03-31 22:19:08 +0000623 // FIXME: Terrible location information
624 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, SR.getEnd(), *Id)) {
625 SemaRef.Diag(SR.getBegin(), diag::err_use_with_wrong_tag) << Id;
626 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
627 return QualType();
628 }
629
630 // Build the elaborated-type-specifier type.
631 QualType T = SemaRef.Context.getTypeDeclType(Tag);
632 T = SemaRef.Context.getQualifiedNameType(NNS, T);
633 return SemaRef.Context.getElaboratedType(T, Kind);
Douglas Gregor1135c352009-08-06 05:28:30 +0000634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Douglas Gregor1135c352009-08-06 05:28:30 +0000636 /// \brief Build a new nested-name-specifier given the prefix and an
637 /// identifier that names the next step in the nested-name-specifier.
638 ///
639 /// By default, performs semantic analysis when building the new
640 /// nested-name-specifier. Subclasses may override this routine to provide
641 /// different behavior.
642 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
643 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000644 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000645 QualType ObjectType,
646 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000647
648 /// \brief Build a new nested-name-specifier given the prefix and the
649 /// namespace named in the next step in the nested-name-specifier.
650 ///
651 /// By default, performs semantic analysis when building the new
652 /// nested-name-specifier. Subclasses may override this routine to provide
653 /// different behavior.
654 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
655 SourceRange Range,
656 NamespaceDecl *NS);
657
658 /// \brief Build a new nested-name-specifier given the prefix and the
659 /// type named in the next step in the nested-name-specifier.
660 ///
661 /// By default, performs semantic analysis when building the new
662 /// nested-name-specifier. Subclasses may override this routine to provide
663 /// different behavior.
664 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
665 SourceRange Range,
666 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000667 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000668
669 /// \brief Build a new template name given a nested name specifier, a flag
670 /// indicating whether the "template" keyword was provided, and the template
671 /// that the template name refers to.
672 ///
673 /// By default, builds the new template name directly. Subclasses may override
674 /// this routine to provide different behavior.
675 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
676 bool TemplateKW,
677 TemplateDecl *Template);
678
Douglas Gregor71dc5092009-08-06 06:41:21 +0000679 /// \brief Build a new template name given a nested name specifier and the
680 /// name that is referred to as a template.
681 ///
682 /// By default, performs semantic analysis to determine whether the name can
683 /// be resolved to a specific template, then builds the appropriate kind of
684 /// template name. Subclasses may override this routine to provide different
685 /// behavior.
686 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000687 const IdentifierInfo &II,
688 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Douglas Gregor71395fa2009-11-04 00:56:37 +0000690 /// \brief Build a new template name given a nested name specifier and the
691 /// overloaded operator name that is referred to as a template.
692 ///
693 /// By default, performs semantic analysis to determine whether the name can
694 /// be resolved to a specific template, then builds the appropriate kind of
695 /// template name. Subclasses may override this routine to provide different
696 /// behavior.
697 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
698 OverloadedOperatorKind Operator,
699 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000700
Douglas Gregorebe10102009-08-20 07:17:43 +0000701 /// \brief Build a new compound statement.
702 ///
703 /// By default, performs semantic analysis to build the new statement.
704 /// Subclasses may override this routine to provide different behavior.
705 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
706 MultiStmtArg Statements,
707 SourceLocation RBraceLoc,
708 bool IsStmtExpr) {
709 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
710 IsStmtExpr);
711 }
712
713 /// \brief Build a new case statement.
714 ///
715 /// By default, performs semantic analysis to build the new statement.
716 /// Subclasses may override this routine to provide different behavior.
717 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
718 ExprArg LHS,
719 SourceLocation EllipsisLoc,
720 ExprArg RHS,
721 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000722 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000723 ColonLoc);
724 }
Mike Stump11289f42009-09-09 15:08:12 +0000725
Douglas Gregorebe10102009-08-20 07:17:43 +0000726 /// \brief Attach the body to a new case statement.
727 ///
728 /// By default, performs semantic analysis to build the new statement.
729 /// Subclasses may override this routine to provide different behavior.
730 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
731 getSema().ActOnCaseStmtBody(S.get(), move(Body));
732 return move(S);
733 }
Mike Stump11289f42009-09-09 15:08:12 +0000734
Douglas Gregorebe10102009-08-20 07:17:43 +0000735 /// \brief Build a new default statement.
736 ///
737 /// By default, performs semantic analysis to build the new statement.
738 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000739 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 SourceLocation ColonLoc,
741 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000742 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000743 /*CurScope=*/0);
744 }
Mike Stump11289f42009-09-09 15:08:12 +0000745
Douglas Gregorebe10102009-08-20 07:17:43 +0000746 /// \brief Build a new label statement.
747 ///
748 /// By default, performs semantic analysis to build the new statement.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 IdentifierInfo *Id,
752 SourceLocation ColonLoc,
753 StmtArg SubStmt) {
754 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
755 }
Mike Stump11289f42009-09-09 15:08:12 +0000756
Douglas Gregorebe10102009-08-20 07:17:43 +0000757 /// \brief Build a new "if" statement.
758 ///
759 /// By default, performs semantic analysis to build the new statement.
760 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000761 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::ExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000762 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000763 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000764 if (Cond.get()) {
765 // Convert the condition to a boolean value.
766 Cond = getSema().ActOnBooleanCondition(0, IfLoc, move(Cond));
767 if (Cond.isInvalid())
768 return getSema().StmtError();
769 }
770
771 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
772 return getSema().ActOnIfStmt(IfLoc, FullCond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000773 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000774 }
Mike Stump11289f42009-09-09 15:08:12 +0000775
Douglas Gregorebe10102009-08-20 07:17:43 +0000776 /// \brief Start building a new switch statement.
777 ///
778 /// By default, performs semantic analysis to build the new statement.
779 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000780 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
781 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000782 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000783 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
784 DeclPtrTy::make(CondVar));
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 Attach the body to the switch statement.
788 ///
789 /// By default, performs semantic analysis to build the new statement.
790 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000791 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000792 StmtArg Switch, StmtArg Body) {
793 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
794 move(Body));
795 }
796
797 /// \brief Build a new while statement.
798 ///
799 /// By default, performs semantic analysis to build the new statement.
800 /// Subclasses may override this routine to provide different behavior.
801 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000802 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000803 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 StmtArg Body) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000805 if (Cond.get()) {
806 // Convert the condition to a boolean value.
807 Cond = getSema().ActOnBooleanCondition(0, WhileLoc, move(Cond));
808 if (Cond.isInvalid())
809 return getSema().StmtError();
810 }
811
812 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
813 return getSema().ActOnWhileStmt(WhileLoc, FullCond,
814 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000815 }
Mike Stump11289f42009-09-09 15:08:12 +0000816
Douglas Gregorebe10102009-08-20 07:17:43 +0000817 /// \brief Build a new do-while statement.
818 ///
819 /// By default, performs semantic analysis to build the new statement.
820 /// Subclasses may override this routine to provide different behavior.
821 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
822 SourceLocation WhileLoc,
823 SourceLocation LParenLoc,
824 ExprArg Cond,
825 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000826 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 move(Cond), RParenLoc);
828 }
829
830 /// \brief Build a new for statement.
831 ///
832 /// By default, performs semantic analysis to build the new statement.
833 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000834 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000835 SourceLocation LParenLoc,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000836 StmtArg Init, Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000837 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000838 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000839 if (Cond.get()) {
840 // Convert the condition to a boolean value.
841 Cond = getSema().ActOnBooleanCondition(0, ForLoc, move(Cond));
842 if (Cond.isInvalid())
843 return getSema().StmtError();
844 }
845
846 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
847 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), FullCond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000848 DeclPtrTy::make(CondVar),
849 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000850 }
Mike Stump11289f42009-09-09 15:08:12 +0000851
Douglas Gregorebe10102009-08-20 07:17:43 +0000852 /// \brief Build a new goto statement.
853 ///
854 /// By default, performs semantic analysis to build the new statement.
855 /// Subclasses may override this routine to provide different behavior.
856 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
857 SourceLocation LabelLoc,
858 LabelStmt *Label) {
859 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
860 }
861
862 /// \brief Build a new indirect goto statement.
863 ///
864 /// By default, performs semantic analysis to build the new statement.
865 /// Subclasses may override this routine to provide different behavior.
866 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
867 SourceLocation StarLoc,
868 ExprArg Target) {
869 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
870 }
Mike Stump11289f42009-09-09 15:08:12 +0000871
Douglas Gregorebe10102009-08-20 07:17:43 +0000872 /// \brief Build a new return statement.
873 ///
874 /// By default, performs semantic analysis to build the new statement.
875 /// Subclasses may override this routine to provide different behavior.
876 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
877 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000878
Douglas Gregorebe10102009-08-20 07:17:43 +0000879 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
880 }
Mike Stump11289f42009-09-09 15:08:12 +0000881
Douglas Gregorebe10102009-08-20 07:17:43 +0000882 /// \brief Build a new declaration statement.
883 ///
884 /// By default, performs semantic analysis to build the new statement.
885 /// Subclasses may override this routine to provide different behavior.
886 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000887 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000888 SourceLocation EndLoc) {
889 return getSema().Owned(
890 new (getSema().Context) DeclStmt(
891 DeclGroupRef::Create(getSema().Context,
892 Decls, NumDecls),
893 StartLoc, EndLoc));
894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Anders Carlssonaaeef072010-01-24 05:50:09 +0000896 /// \brief Build a new inline asm statement.
897 ///
898 /// By default, performs semantic analysis to build the new statement.
899 /// Subclasses may override this routine to provide different behavior.
900 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
901 bool IsSimple,
902 bool IsVolatile,
903 unsigned NumOutputs,
904 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000905 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000906 MultiExprArg Constraints,
907 MultiExprArg Exprs,
908 ExprArg AsmString,
909 MultiExprArg Clobbers,
910 SourceLocation RParenLoc,
911 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000912 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000913 NumInputs, Names, move(Constraints),
914 move(Exprs), move(AsmString), move(Clobbers),
915 RParenLoc, MSAsm);
916 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000917
918 /// \brief Build a new Objective-C @try statement.
919 ///
920 /// By default, performs semantic analysis to build the new statement.
921 /// Subclasses may override this routine to provide different behavior.
922 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
923 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000924 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000925 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000926 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000927 move(Finally));
928 }
929
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000930 /// \brief Rebuild an Objective-C exception declaration.
931 ///
932 /// By default, performs semantic analysis to build the new declaration.
933 /// Subclasses may override this routine to provide different behavior.
934 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
935 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000936 return getSema().BuildObjCExceptionDecl(TInfo, T,
937 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000938 ExceptionDecl->getLocation());
939 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000940
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000941 /// \brief Build a new Objective-C @catch statement.
942 ///
943 /// By default, performs semantic analysis to build the new statement.
944 /// Subclasses may override this routine to provide different behavior.
945 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
946 SourceLocation RParenLoc,
947 VarDecl *Var,
948 StmtArg Body) {
949 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
950 Sema::DeclPtrTy::make(Var),
951 move(Body));
952 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000953
Douglas Gregor306de2f2010-04-22 23:59:56 +0000954 /// \brief Build a new Objective-C @finally statement.
955 ///
956 /// By default, performs semantic analysis to build the new statement.
957 /// Subclasses may override this routine to provide different behavior.
958 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
959 StmtArg Body) {
960 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
961 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000962
Douglas Gregor6148de72010-04-22 22:01:21 +0000963 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
967 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
968 ExprArg Operand) {
969 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
970 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000971
Douglas Gregor6148de72010-04-22 22:01:21 +0000972 /// \brief Build a new Objective-C @synchronized statement.
973 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000974 /// By default, performs semantic analysis to build the new statement.
975 /// Subclasses may override this routine to provide different behavior.
976 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
977 ExprArg Object,
978 StmtArg Body) {
979 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
980 move(Body));
981 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000982
983 /// \brief Build a new Objective-C fast enumeration statement.
984 ///
985 /// By default, performs semantic analysis to build the new statement.
986 /// Subclasses may override this routine to provide different behavior.
987 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
988 SourceLocation LParenLoc,
989 StmtArg Element,
990 ExprArg Collection,
991 SourceLocation RParenLoc,
992 StmtArg Body) {
993 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000994 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000995 move(Collection),
996 RParenLoc,
997 move(Body));
998 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new C++ exception declaration.
1001 ///
1002 /// By default, performs semantic analysis to build the new decaration.
1003 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001004 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +00001005 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 IdentifierInfo *Name,
1007 SourceLocation Loc,
1008 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +00001009 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 TypeRange);
1011 }
1012
1013 /// \brief Build a new C++ catch statement.
1014 ///
1015 /// By default, performs semantic analysis to build the new statement.
1016 /// Subclasses may override this routine to provide different behavior.
1017 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
1018 VarDecl *ExceptionDecl,
1019 StmtArg Handler) {
1020 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +00001021 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001022 Handler.takeAs<Stmt>()));
1023 }
Mike Stump11289f42009-09-09 15:08:12 +00001024
Douglas Gregorebe10102009-08-20 07:17:43 +00001025 /// \brief Build a new C++ try statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
1029 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1030 StmtArg TryBlock,
1031 MultiStmtArg Handlers) {
1032 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1033 }
Mike Stump11289f42009-09-09 15:08:12 +00001034
Douglas Gregora16548e2009-08-11 05:31:07 +00001035 /// \brief Build a new expression that references a declaration.
1036 ///
1037 /// By default, performs semantic analysis to build the new expression.
1038 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001039 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1040 LookupResult &R,
1041 bool RequiresADL) {
1042 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1043 }
1044
1045
1046 /// \brief Build a new expression that references a declaration.
1047 ///
1048 /// By default, performs semantic analysis to build the new expression.
1049 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001050 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1051 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001052 ValueDecl *VD, SourceLocation Loc,
1053 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001054 CXXScopeSpec SS;
1055 SS.setScopeRep(Qualifier);
1056 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001057
1058 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001059
John McCallce546572009-12-08 09:08:17 +00001060 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001061 }
Mike Stump11289f42009-09-09 15:08:12 +00001062
Douglas Gregora16548e2009-08-11 05:31:07 +00001063 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001064 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001065 /// By default, performs semantic analysis to build the new expression.
1066 /// Subclasses may override this routine to provide different behavior.
1067 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1068 SourceLocation RParen) {
1069 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1070 }
1071
Douglas Gregorad8a3362009-09-04 17:36:40 +00001072 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001073 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001074 /// By default, performs semantic analysis to build the new expression.
1075 /// Subclasses may override this routine to provide different behavior.
1076 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1077 SourceLocation OperatorLoc,
1078 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001079 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001080 SourceRange QualifierRange,
1081 TypeSourceInfo *ScopeType,
1082 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001083 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001084 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001085
Douglas Gregora16548e2009-08-11 05:31:07 +00001086 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001088 /// By default, performs semantic analysis to build the new expression.
1089 /// Subclasses may override this routine to provide different behavior.
1090 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1091 UnaryOperator::Opcode Opc,
1092 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001093 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001094 }
Mike Stump11289f42009-09-09 15:08:12 +00001095
Douglas Gregor882211c2010-04-28 22:16:22 +00001096 /// \brief Build a new builtin offsetof expression.
1097 ///
1098 /// By default, performs semantic analysis to build the new expression.
1099 /// Subclasses may override this routine to provide different behavior.
1100 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1101 TypeSourceInfo *Type,
1102 Action::OffsetOfComponent *Components,
1103 unsigned NumComponents,
1104 SourceLocation RParenLoc) {
1105 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1106 NumComponents, RParenLoc);
1107 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001108
Douglas Gregora16548e2009-08-11 05:31:07 +00001109 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001110 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001111 /// By default, performs semantic analysis to build the new expression.
1112 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001113 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001114 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001115 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001116 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 }
1118
Mike Stump11289f42009-09-09 15:08:12 +00001119 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001120 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001121 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 /// By default, performs semantic analysis to build the new expression.
1123 /// Subclasses may override this routine to provide different behavior.
1124 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1125 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001126 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1128 OpLoc, isSizeOf, R);
1129 if (Result.isInvalid())
1130 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001131
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 SubExpr.release();
1133 return move(Result);
1134 }
Mike Stump11289f42009-09-09 15:08:12 +00001135
Douglas Gregora16548e2009-08-11 05:31:07 +00001136 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001137 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001138 /// By default, performs semantic analysis to build the new expression.
1139 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001140 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001141 SourceLocation LBracketLoc,
1142 ExprArg RHS,
1143 SourceLocation RBracketLoc) {
1144 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001145 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001146 RBracketLoc);
1147 }
1148
1149 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001150 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001151 /// By default, performs semantic analysis to build the new expression.
1152 /// Subclasses may override this routine to provide different behavior.
1153 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1154 MultiExprArg Args,
1155 SourceLocation *CommaLocs,
1156 SourceLocation RParenLoc) {
1157 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1158 move(Args), CommaLocs, RParenLoc);
1159 }
1160
1161 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001162 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001163 /// By default, performs semantic analysis to build the new expression.
1164 /// Subclasses may override this routine to provide different behavior.
1165 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001166 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001167 NestedNameSpecifier *Qualifier,
1168 SourceRange QualifierRange,
1169 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001170 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001171 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001172 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001173 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001174 if (!Member->getDeclName()) {
1175 // We have a reference to an unnamed field.
1176 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001177
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001178 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001179 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1180 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001181 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001182
Mike Stump11289f42009-09-09 15:08:12 +00001183 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001184 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001185 Member, MemberLoc,
1186 cast<FieldDecl>(Member)->getType());
1187 return getSema().Owned(ME);
1188 }
Mike Stump11289f42009-09-09 15:08:12 +00001189
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001190 CXXScopeSpec SS;
1191 if (Qualifier) {
1192 SS.setRange(QualifierRange);
1193 SS.setScopeRep(Qualifier);
1194 }
1195
John McCall2d74de92009-12-01 22:10:20 +00001196 QualType BaseType = ((Expr*) Base.get())->getType();
1197
John McCall16df1e52010-03-30 21:47:33 +00001198 // FIXME: this involves duplicating earlier analysis in a lot of
1199 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001200 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1201 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001202 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001203 R.resolveKind();
1204
John McCall2d74de92009-12-01 22:10:20 +00001205 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
1206 OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001207 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001208 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001209 }
Mike Stump11289f42009-09-09 15:08:12 +00001210
Douglas Gregora16548e2009-08-11 05:31:07 +00001211 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001212 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001213 /// By default, performs semantic analysis to build the new expression.
1214 /// Subclasses may override this routine to provide different behavior.
1215 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1216 BinaryOperator::Opcode Opc,
1217 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001218 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001219 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 }
1221
1222 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001223 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 /// By default, performs semantic analysis to build the new expression.
1225 /// Subclasses may override this routine to provide different behavior.
1226 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1227 SourceLocation QuestionLoc,
1228 ExprArg LHS,
1229 SourceLocation ColonLoc,
1230 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001231 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 move(LHS), move(RHS));
1233 }
1234
Douglas Gregora16548e2009-08-11 05:31:07 +00001235 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001236 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001237 /// By default, performs semantic analysis to build the new expression.
1238 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001239 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1240 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001241 SourceLocation RParenLoc,
1242 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001243 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1244 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 }
Mike Stump11289f42009-09-09 15:08:12 +00001246
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001248 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001249 /// By default, performs semantic analysis to build the new expression.
1250 /// Subclasses may override this routine to provide different behavior.
1251 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001252 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001253 SourceLocation RParenLoc,
1254 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001255 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1256 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001257 }
Mike Stump11289f42009-09-09 15:08:12 +00001258
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001260 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// By default, performs semantic analysis to build the new expression.
1262 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001263 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001264 SourceLocation OpLoc,
1265 SourceLocation AccessorLoc,
1266 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001267
John McCall10eae182009-11-30 22:42:35 +00001268 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001269 QualType BaseType = ((Expr*) Base.get())->getType();
1270 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001271 OpLoc, /*IsArrow*/ false,
1272 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001273 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001274 AccessorLoc,
1275 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001276 }
Mike Stump11289f42009-09-09 15:08:12 +00001277
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001279 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 /// By default, performs semantic analysis to build the new expression.
1281 /// Subclasses may override this routine to provide different behavior.
1282 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1283 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001284 SourceLocation RBraceLoc,
1285 QualType ResultTy) {
1286 OwningExprResult Result
1287 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1288 if (Result.isInvalid() || ResultTy->isDependentType())
1289 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001290
Douglas Gregord3d93062009-11-09 17:16:50 +00001291 // Patch in the result type we were given, which may have been computed
1292 // when the initial InitListExpr was built.
1293 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1294 ILE->setType(ResultTy);
1295 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 }
Mike Stump11289f42009-09-09 15:08:12 +00001297
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 /// \brief Build a new designated initializer expression.
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 RebuildDesignatedInitExpr(Designation &Desig,
1303 MultiExprArg ArrayExprs,
1304 SourceLocation EqualOrColonLoc,
1305 bool GNUSyntax,
1306 ExprArg Init) {
1307 OwningExprResult Result
1308 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1309 move(Init));
1310 if (Result.isInvalid())
1311 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001312
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 ArrayExprs.release();
1314 return move(Result);
1315 }
Mike Stump11289f42009-09-09 15:08:12 +00001316
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001318 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001319 /// By default, builds the implicit value initialization without performing
1320 /// any semantic analysis. Subclasses may override this routine to provide
1321 /// different behavior.
1322 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1323 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1324 }
Mike Stump11289f42009-09-09 15:08:12 +00001325
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001327 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
1330 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1331 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001332 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 RParenLoc);
1334 }
1335
1336 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001337 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
1340 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1341 MultiExprArg SubExprs,
1342 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001343 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001344 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 }
Mike Stump11289f42009-09-09 15:08:12 +00001346
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001348 ///
1349 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 /// rather than attempting to map the label statement itself.
1351 /// Subclasses may override this routine to provide different behavior.
1352 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1353 SourceLocation LabelLoc,
1354 LabelStmt *Label) {
1355 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1356 }
Mike Stump11289f42009-09-09 15:08:12 +00001357
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001359 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
1362 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1363 StmtArg SubStmt,
1364 SourceLocation RParenLoc) {
1365 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1366 }
Mike Stump11289f42009-09-09 15:08:12 +00001367
Douglas Gregora16548e2009-08-11 05:31:07 +00001368 /// \brief Build a new __builtin_types_compatible_p expression.
1369 ///
1370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
1372 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1373 QualType T1, QualType T2,
1374 SourceLocation RParenLoc) {
1375 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1376 T1.getAsOpaquePtr(),
1377 T2.getAsOpaquePtr(),
1378 RParenLoc);
1379 }
Mike Stump11289f42009-09-09 15:08:12 +00001380
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// \brief Build a new __builtin_choose_expr expression.
1382 ///
1383 /// By default, performs semantic analysis to build the new expression.
1384 /// Subclasses may override this routine to provide different behavior.
1385 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1386 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1387 SourceLocation RParenLoc) {
1388 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1389 move(Cond), move(LHS), move(RHS),
1390 RParenLoc);
1391 }
Mike Stump11289f42009-09-09 15:08:12 +00001392
Douglas Gregora16548e2009-08-11 05:31:07 +00001393 /// \brief Build a new overloaded operator call expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// The semantic analysis provides the behavior of template instantiation,
1397 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001398 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001399 /// argument-dependent lookup, etc. Subclasses may override this routine to
1400 /// provide different behavior.
1401 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1402 SourceLocation OpLoc,
1403 ExprArg Callee,
1404 ExprArg First,
1405 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001406
1407 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 /// reinterpret_cast.
1409 ///
1410 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001411 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 /// Subclasses may override this routine to provide different behavior.
1413 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1414 Stmt::StmtClass Class,
1415 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001416 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 SourceLocation RAngleLoc,
1418 SourceLocation LParenLoc,
1419 ExprArg SubExpr,
1420 SourceLocation RParenLoc) {
1421 switch (Class) {
1422 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001423 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001424 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 move(SubExpr), RParenLoc);
1426
1427 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001428 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001429 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001431
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001433 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001434 RAngleLoc, LParenLoc,
1435 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001439 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001440 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001442
Douglas Gregora16548e2009-08-11 05:31:07 +00001443 default:
1444 assert(false && "Invalid C++ named cast");
1445 break;
1446 }
Mike Stump11289f42009-09-09 15:08:12 +00001447
Douglas Gregora16548e2009-08-11 05:31:07 +00001448 return getSema().ExprError();
1449 }
Mike Stump11289f42009-09-09 15:08:12 +00001450
Douglas Gregora16548e2009-08-11 05:31:07 +00001451 /// \brief Build a new C++ static_cast expression.
1452 ///
1453 /// By default, performs semantic analysis to build the new expression.
1454 /// Subclasses may override this routine to provide different behavior.
1455 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1456 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001457 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 SourceLocation RAngleLoc,
1459 SourceLocation LParenLoc,
1460 ExprArg SubExpr,
1461 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001462 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1463 TInfo, move(SubExpr),
1464 SourceRange(LAngleLoc, RAngleLoc),
1465 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 }
1467
1468 /// \brief Build a new C++ dynamic_cast expression.
1469 ///
1470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OwningExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
1473 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001474 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 SourceLocation RAngleLoc,
1476 SourceLocation LParenLoc,
1477 ExprArg SubExpr,
1478 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001479 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
1480 TInfo, move(SubExpr),
1481 SourceRange(LAngleLoc, RAngleLoc),
1482 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001483 }
1484
1485 /// \brief Build a new C++ reinterpret_cast expression.
1486 ///
1487 /// By default, performs semantic analysis to build the new expression.
1488 /// Subclasses may override this routine to provide different behavior.
1489 OwningExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
1490 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001491 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 SourceLocation RAngleLoc,
1493 SourceLocation LParenLoc,
1494 ExprArg SubExpr,
1495 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001496 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
1497 TInfo, move(SubExpr),
1498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
1501
1502 /// \brief Build a new C++ const_cast expression.
1503 ///
1504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OwningExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
1507 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001508 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001509 SourceLocation RAngleLoc,
1510 SourceLocation LParenLoc,
1511 ExprArg SubExpr,
1512 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001513 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
1514 TInfo, move(SubExpr),
1515 SourceRange(LAngleLoc, RAngleLoc),
1516 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 }
Mike Stump11289f42009-09-09 15:08:12 +00001518
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 /// \brief Build a new C++ functional-style cast expression.
1520 ///
1521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OwningExprResult RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001524 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 SourceLocation LParenLoc,
1526 ExprArg SubExpr,
1527 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001528 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001530 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001532 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001533 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 RParenLoc);
1535 }
Mike Stump11289f42009-09-09 15:08:12 +00001536
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 /// \brief Build a new C++ typeid(type) expression.
1538 ///
1539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001541 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1542 SourceLocation TypeidLoc,
1543 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001545 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001546 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 }
Mike Stump11289f42009-09-09 15:08:12 +00001548
Douglas Gregora16548e2009-08-11 05:31:07 +00001549 /// \brief Build a new C++ typeid(expr) expression.
1550 ///
1551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001553 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1554 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 ExprArg Operand,
1556 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001557 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1558 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001559 }
1560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new C++ "this" expression.
1562 ///
1563 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001564 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001566 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001567 QualType ThisType,
1568 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001570 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1571 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001572 }
1573
1574 /// \brief Build a new C++ throw expression.
1575 ///
1576 /// By default, performs semantic analysis to build the new expression.
1577 /// Subclasses may override this routine to provide different behavior.
1578 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1579 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1580 }
1581
1582 /// \brief Build a new C++ default-argument expression.
1583 ///
1584 /// By default, builds a new default-argument expression, which does not
1585 /// require any semantic analysis. Subclasses may override this routine to
1586 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001587 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001588 ParmVarDecl *Param) {
1589 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1590 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 }
1592
1593 /// \brief Build a new C++ zero-initialization expression.
1594 ///
1595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001597 OwningExprResult RebuildCXXZeroInitValueExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 SourceLocation LParenLoc,
1599 QualType T,
1600 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001601 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1602 T.getAsOpaquePtr(), LParenLoc,
1603 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 0, RParenLoc);
1605 }
Mike Stump11289f42009-09-09 15:08:12 +00001606
Douglas Gregora16548e2009-08-11 05:31:07 +00001607 /// \brief Build a new C++ "new" expression.
1608 ///
1609 /// By default, performs semantic analysis to build the new expression.
1610 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001611 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001612 bool UseGlobal,
1613 SourceLocation PlacementLParen,
1614 MultiExprArg PlacementArgs,
1615 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001616 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001617 QualType AllocType,
1618 SourceLocation TypeLoc,
1619 SourceRange TypeRange,
1620 ExprArg ArraySize,
1621 SourceLocation ConstructorLParen,
1622 MultiExprArg ConstructorArgs,
1623 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001624 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001625 PlacementLParen,
1626 move(PlacementArgs),
1627 PlacementRParen,
1628 ParenTypeId,
1629 AllocType,
1630 TypeLoc,
1631 TypeRange,
1632 move(ArraySize),
1633 ConstructorLParen,
1634 move(ConstructorArgs),
1635 ConstructorRParen);
1636 }
Mike Stump11289f42009-09-09 15:08:12 +00001637
Douglas Gregora16548e2009-08-11 05:31:07 +00001638 /// \brief Build a new C++ "delete" expression.
1639 ///
1640 /// By default, performs semantic analysis to build the new expression.
1641 /// Subclasses may override this routine to provide different behavior.
1642 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1643 bool IsGlobalDelete,
1644 bool IsArrayForm,
1645 ExprArg Operand) {
1646 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1647 move(Operand));
1648 }
Mike Stump11289f42009-09-09 15:08:12 +00001649
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 /// \brief Build a new unary type trait expression.
1651 ///
1652 /// By default, performs semantic analysis to build the new expression.
1653 /// Subclasses may override this routine to provide different behavior.
1654 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1655 SourceLocation StartLoc,
1656 SourceLocation LParenLoc,
1657 QualType T,
1658 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001659 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001660 T.getAsOpaquePtr(), RParenLoc);
1661 }
1662
Mike Stump11289f42009-09-09 15:08:12 +00001663 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 /// expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001668 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 SourceRange QualifierRange,
1670 DeclarationName Name,
1671 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001672 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001673 CXXScopeSpec SS;
1674 SS.setRange(QualifierRange);
1675 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001676
1677 if (TemplateArgs)
1678 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1679 *TemplateArgs);
1680
1681 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001682 }
1683
1684 /// \brief Build a new template-id expression.
1685 ///
1686 /// By default, performs semantic analysis to build the new expression.
1687 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001688 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1689 LookupResult &R,
1690 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001691 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001692 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001693 }
1694
1695 /// \brief Build a new object-construction expression.
1696 ///
1697 /// By default, performs semantic analysis to build the new expression.
1698 /// Subclasses may override this routine to provide different behavior.
1699 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001700 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 CXXConstructorDecl *Constructor,
1702 bool IsElidable,
1703 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001704 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001705 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001706 ConvertedArgs))
1707 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001708
Douglas Gregordb121ba2009-12-14 16:27:04 +00001709 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1710 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001711 }
1712
1713 /// \brief Build a new object-construction expression.
1714 ///
1715 /// By default, performs semantic analysis to build the new expression.
1716 /// Subclasses may override this routine to provide different behavior.
1717 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1718 QualType T,
1719 SourceLocation LParenLoc,
1720 MultiExprArg Args,
1721 SourceLocation *Commas,
1722 SourceLocation RParenLoc) {
1723 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1724 T.getAsOpaquePtr(),
1725 LParenLoc,
1726 move(Args),
1727 Commas,
1728 RParenLoc);
1729 }
1730
1731 /// \brief Build a new object-construction expression.
1732 ///
1733 /// By default, performs semantic analysis to build the new expression.
1734 /// Subclasses may override this routine to provide different behavior.
1735 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1736 QualType T,
1737 SourceLocation LParenLoc,
1738 MultiExprArg Args,
1739 SourceLocation *Commas,
1740 SourceLocation RParenLoc) {
1741 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1742 /*FIXME*/LParenLoc),
1743 T.getAsOpaquePtr(),
1744 LParenLoc,
1745 move(Args),
1746 Commas,
1747 RParenLoc);
1748 }
Mike Stump11289f42009-09-09 15:08:12 +00001749
Douglas Gregora16548e2009-08-11 05:31:07 +00001750 /// \brief Build a new member reference expression.
1751 ///
1752 /// By default, performs semantic analysis to build the new expression.
1753 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001754 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001755 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 bool IsArrow,
1757 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001758 NestedNameSpecifier *Qualifier,
1759 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001760 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001762 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001763 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001765 SS.setRange(QualifierRange);
1766 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001767
John McCall2d74de92009-12-01 22:10:20 +00001768 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1769 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001770 SS, FirstQualifierInScope,
1771 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001772 }
1773
John McCall10eae182009-11-30 22:42:35 +00001774 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001775 ///
1776 /// By default, performs semantic analysis to build the new expression.
1777 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001778 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001779 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001780 SourceLocation OperatorLoc,
1781 bool IsArrow,
1782 NestedNameSpecifier *Qualifier,
1783 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001784 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001785 LookupResult &R,
1786 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001787 CXXScopeSpec SS;
1788 SS.setRange(QualifierRange);
1789 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001790
John McCall2d74de92009-12-01 22:10:20 +00001791 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1792 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001793 SS, FirstQualifierInScope,
1794 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001795 }
Mike Stump11289f42009-09-09 15:08:12 +00001796
Douglas Gregora16548e2009-08-11 05:31:07 +00001797 /// \brief Build a new Objective-C @encode expression.
1798 ///
1799 /// By default, performs semantic analysis to build the new expression.
1800 /// Subclasses may override this routine to provide different behavior.
1801 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001802 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001804 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001806 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001807
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001808 /// \brief Build a new Objective-C class message.
1809 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1810 Selector Sel,
1811 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001812 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001813 MultiExprArg Args,
1814 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001815 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1816 ReceiverTypeInfo->getType(),
1817 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001818 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001819 move(Args));
1820 }
1821
1822 /// \brief Build a new Objective-C instance message.
1823 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1824 Selector Sel,
1825 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001826 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001827 MultiExprArg Args,
1828 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001829 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1830 return SemaRef.BuildInstanceMessage(move(Receiver),
1831 ReceiverType,
1832 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001833 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001834 move(Args));
1835 }
1836
Douglas Gregord51d90d2010-04-26 20:11:03 +00001837 /// \brief Build a new Objective-C ivar reference expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
1841 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1842 SourceLocation IvarLoc,
1843 bool IsArrow, bool IsFreeIvar) {
1844 // FIXME: We lose track of the IsFreeIvar bit.
1845 CXXScopeSpec SS;
1846 Expr *Base = BaseArg.takeAs<Expr>();
1847 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1848 Sema::LookupMemberName);
1849 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1850 /*FIME:*/IvarLoc,
1851 SS, DeclPtrTy());
1852 if (Result.isInvalid())
1853 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854
Douglas Gregord51d90d2010-04-26 20:11:03 +00001855 if (Result.get())
1856 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001857
1858 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001859 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001860 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001861 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001862 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001863 /*TemplateArgs=*/0);
1864 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001865
1866 /// \brief Build a new Objective-C property reference expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001870 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001871 ObjCPropertyDecl *Property,
1872 SourceLocation PropertyLoc) {
1873 CXXScopeSpec SS;
1874 Expr *Base = BaseArg.takeAs<Expr>();
1875 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1876 Sema::LookupMemberName);
1877 bool IsArrow = false;
1878 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1879 /*FIME:*/PropertyLoc,
1880 SS, DeclPtrTy());
1881 if (Result.isInvalid())
1882 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001883
Douglas Gregor9faee212010-04-26 20:47:02 +00001884 if (Result.get())
1885 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001886
1887 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001888 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001889 /*FIXME:*/PropertyLoc, IsArrow,
1890 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001891 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001892 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001893 /*TemplateArgs=*/0);
1894 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001895
1896 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001897 /// expression.
1898 ///
1899 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001900 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001901 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1902 ObjCMethodDecl *Getter,
1903 QualType T,
1904 ObjCMethodDecl *Setter,
1905 SourceLocation NameLoc,
1906 ExprArg Base) {
1907 // Since these expressions can only be value-dependent, we do not need to
1908 // perform semantic analysis again.
1909 return getSema().Owned(
1910 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1911 Setter,
1912 NameLoc,
1913 Base.takeAs<Expr>()));
1914 }
1915
Douglas Gregord51d90d2010-04-26 20:11:03 +00001916 /// \brief Build a new Objective-C "isa" expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
1920 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1921 bool IsArrow) {
1922 CXXScopeSpec SS;
1923 Expr *Base = BaseArg.takeAs<Expr>();
1924 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1925 Sema::LookupMemberName);
1926 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1927 /*FIME:*/IsaLoc,
1928 SS, DeclPtrTy());
1929 if (Result.isInvalid())
1930 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001931
Douglas Gregord51d90d2010-04-26 20:11:03 +00001932 if (Result.get())
1933 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001934
1935 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001936 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001937 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001938 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001939 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001940 /*TemplateArgs=*/0);
1941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 /// \brief Build a new shuffle vector expression.
1944 ///
1945 /// By default, performs semantic analysis to build the new expression.
1946 /// Subclasses may override this routine to provide different behavior.
1947 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1948 MultiExprArg SubExprs,
1949 SourceLocation RParenLoc) {
1950 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001951 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001952 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1953 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1954 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1955 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001956
Douglas Gregora16548e2009-08-11 05:31:07 +00001957 // Build a reference to the __builtin_shufflevector builtin
1958 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001959 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001960 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001961 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001963
1964 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001965 unsigned NumSubExprs = SubExprs.size();
1966 Expr **Subs = (Expr **)SubExprs.release();
1967 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1968 Subs, NumSubExprs,
1969 Builtin->getResultType(),
1970 RParenLoc);
1971 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001972
Douglas Gregora16548e2009-08-11 05:31:07 +00001973 // Type-check the __builtin_shufflevector expression.
1974 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1975 if (Result.isInvalid())
1976 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001977
Douglas Gregora16548e2009-08-11 05:31:07 +00001978 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001979 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001981};
Douglas Gregora16548e2009-08-11 05:31:07 +00001982
Douglas Gregorebe10102009-08-20 07:17:43 +00001983template<typename Derived>
1984Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1985 if (!S)
1986 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001987
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 switch (S->getStmtClass()) {
1989 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001990
Douglas Gregorebe10102009-08-20 07:17:43 +00001991 // Transform individual statement nodes
1992#define STMT(Node, Parent) \
1993 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1994#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001995#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 // Transform expressions by calling TransformExpr.
1998#define STMT(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001999#define ABSTRACT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002000#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002001#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002002 {
2003 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
2004 if (E.isInvalid())
2005 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002006
Anders Carlssonafb2dad2009-12-16 02:09:40 +00002007 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00002008 }
Mike Stump11289f42009-09-09 15:08:12 +00002009 }
2010
Douglas Gregorebe10102009-08-20 07:17:43 +00002011 return SemaRef.Owned(S->Retain());
2012}
Mike Stump11289f42009-09-09 15:08:12 +00002013
2014
Douglas Gregore922c772009-08-04 22:27:00 +00002015template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002016Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 if (!E)
2018 return SemaRef.Owned(E);
2019
2020 switch (E->getStmtClass()) {
2021 case Stmt::NoStmtClass: break;
2022#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Hunt656bb312010-05-05 15:24:00 +00002023#define ABSTRACT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002024#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002025 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002026#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002027 }
2028
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002030}
2031
2032template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002033NestedNameSpecifier *
2034TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002035 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002036 QualType ObjectType,
2037 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002038 if (!NNS)
2039 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002040
Douglas Gregorebe10102009-08-20 07:17:43 +00002041 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 NestedNameSpecifier *Prefix = NNS->getPrefix();
2043 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002044 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002045 ObjectType,
2046 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002047 if (!Prefix)
2048 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002049
2050 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002051 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002052 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002053 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002054 }
Mike Stump11289f42009-09-09 15:08:12 +00002055
Douglas Gregor1135c352009-08-06 05:28:30 +00002056 switch (NNS->getKind()) {
2057 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002058 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002059 "Identifier nested-name-specifier with no prefix or object type");
2060 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2061 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002062 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002063
2064 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002065 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002066 ObjectType,
2067 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregor1135c352009-08-06 05:28:30 +00002069 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002070 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002071 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002072 getDerived().TransformDecl(Range.getBegin(),
2073 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002075 Prefix == NNS->getPrefix() &&
2076 NS == NNS->getAsNamespace())
2077 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002078
Douglas Gregor1135c352009-08-06 05:28:30 +00002079 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2080 }
Mike Stump11289f42009-09-09 15:08:12 +00002081
Douglas Gregor1135c352009-08-06 05:28:30 +00002082 case NestedNameSpecifier::Global:
2083 // There is no meaningful transformation that one could perform on the
2084 // global scope.
2085 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregor1135c352009-08-06 05:28:30 +00002087 case NestedNameSpecifier::TypeSpecWithTemplate:
2088 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002089 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002090 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2091 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002092 if (T.isNull())
2093 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregor1135c352009-08-06 05:28:30 +00002095 if (!getDerived().AlwaysRebuild() &&
2096 Prefix == NNS->getPrefix() &&
2097 T == QualType(NNS->getAsType(), 0))
2098 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002099
2100 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2101 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002102 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002103 }
2104 }
Mike Stump11289f42009-09-09 15:08:12 +00002105
Douglas Gregor1135c352009-08-06 05:28:30 +00002106 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002107 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002108}
2109
2110template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002111DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002112TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002113 SourceLocation Loc,
2114 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002115 if (!Name)
2116 return Name;
2117
2118 switch (Name.getNameKind()) {
2119 case DeclarationName::Identifier:
2120 case DeclarationName::ObjCZeroArgSelector:
2121 case DeclarationName::ObjCOneArgSelector:
2122 case DeclarationName::ObjCMultiArgSelector:
2123 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002124 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002125 case DeclarationName::CXXUsingDirective:
2126 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregorf816bd72009-09-03 22:13:48 +00002128 case DeclarationName::CXXConstructorName:
2129 case DeclarationName::CXXDestructorName:
2130 case DeclarationName::CXXConversionFunctionName: {
2131 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002132 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002133 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002134 if (T.isNull())
2135 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregorf816bd72009-09-03 22:13:48 +00002137 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002138 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002139 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002140 }
Mike Stump11289f42009-09-09 15:08:12 +00002141 }
2142
Douglas Gregorf816bd72009-09-03 22:13:48 +00002143 return DeclarationName();
2144}
2145
2146template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002147TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002148TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2149 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002150 SourceLocation Loc = getDerived().getBaseLocation();
2151
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002153 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002154 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002155 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2156 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 if (!NNS)
2158 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002159
Douglas Gregor71dc5092009-08-06 06:41:21 +00002160 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002161 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002162 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163 if (!TransTemplate)
2164 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002165
Douglas Gregor71dc5092009-08-06 06:41:21 +00002166 if (!getDerived().AlwaysRebuild() &&
2167 NNS == QTN->getQualifier() &&
2168 TransTemplate == Template)
2169 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002170
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2172 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 make it into the AST.
2176 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002177 }
Mike Stump11289f42009-09-09 15:08:12 +00002178
Douglas Gregor71dc5092009-08-06 06:41:21 +00002179 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002180 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002181 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002182 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2183 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002184 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002185 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002186
Douglas Gregor71dc5092009-08-06 06:41:21 +00002187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002188 NNS == DTN->getQualifier() &&
2189 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002190 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregor71395fa2009-11-04 00:56:37 +00002192 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002193 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002194 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002195
2196 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002197 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002198 }
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregor71dc5092009-08-06 06:41:21 +00002200 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002201 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002202 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002203 if (!TransTemplate)
2204 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregor71dc5092009-08-06 06:41:21 +00002206 if (!getDerived().AlwaysRebuild() &&
2207 TransTemplate == Template)
2208 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregor71dc5092009-08-06 06:41:21 +00002210 return TemplateName(TransTemplate);
2211 }
Mike Stump11289f42009-09-09 15:08:12 +00002212
John McCalle66edc12009-11-24 19:00:30 +00002213 // These should be getting filtered out before they reach the AST.
2214 assert(false && "overloaded function decl survived to here");
2215 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002216}
2217
2218template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002219void TreeTransform<Derived>::InventTemplateArgumentLoc(
2220 const TemplateArgument &Arg,
2221 TemplateArgumentLoc &Output) {
2222 SourceLocation Loc = getDerived().getBaseLocation();
2223 switch (Arg.getKind()) {
2224 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002225 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002226 break;
2227
2228 case TemplateArgument::Type:
2229 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002230 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002231
John McCall0ad16662009-10-29 08:12:44 +00002232 break;
2233
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002234 case TemplateArgument::Template:
2235 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2236 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002237
John McCall0ad16662009-10-29 08:12:44 +00002238 case TemplateArgument::Expression:
2239 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2240 break;
2241
2242 case TemplateArgument::Declaration:
2243 case TemplateArgument::Integral:
2244 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002245 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002246 break;
2247 }
2248}
2249
2250template<typename Derived>
2251bool TreeTransform<Derived>::TransformTemplateArgument(
2252 const TemplateArgumentLoc &Input,
2253 TemplateArgumentLoc &Output) {
2254 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002255 switch (Arg.getKind()) {
2256 case TemplateArgument::Null:
2257 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002258 Output = Input;
2259 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002260
Douglas Gregore922c772009-08-04 22:27:00 +00002261 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002262 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002263 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002264 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002265
2266 DI = getDerived().TransformType(DI);
2267 if (!DI) return true;
2268
2269 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2270 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002271 }
Mike Stump11289f42009-09-09 15:08:12 +00002272
Douglas Gregore922c772009-08-04 22:27:00 +00002273 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002274 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002275 DeclarationName Name;
2276 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2277 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002278 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002279 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002280 if (!D) return true;
2281
John McCall0d07eb32009-10-29 18:45:58 +00002282 Expr *SourceExpr = Input.getSourceDeclExpression();
2283 if (SourceExpr) {
2284 EnterExpressionEvaluationContext Unevaluated(getSema(),
2285 Action::Unevaluated);
2286 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2287 if (E.isInvalid())
2288 SourceExpr = NULL;
2289 else {
2290 SourceExpr = E.takeAs<Expr>();
2291 SourceExpr->Retain();
2292 }
2293 }
2294
2295 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002296 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002297 }
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002299 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002300 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002301 TemplateName Template
2302 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2303 if (Template.isNull())
2304 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002305
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002306 Output = TemplateArgumentLoc(TemplateArgument(Template),
2307 Input.getTemplateQualifierRange(),
2308 Input.getTemplateNameLoc());
2309 return false;
2310 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002311
Douglas Gregore922c772009-08-04 22:27:00 +00002312 case TemplateArgument::Expression: {
2313 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002314 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002315 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002316
John McCall0ad16662009-10-29 08:12:44 +00002317 Expr *InputExpr = Input.getSourceExpression();
2318 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2319
2320 Sema::OwningExprResult E
2321 = getDerived().TransformExpr(InputExpr);
2322 if (E.isInvalid()) return true;
2323
2324 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002325 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002326 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2327 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002328 }
Mike Stump11289f42009-09-09 15:08:12 +00002329
Douglas Gregore922c772009-08-04 22:27:00 +00002330 case TemplateArgument::Pack: {
2331 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2332 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002333 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002334 AEnd = Arg.pack_end();
2335 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002336
John McCall0ad16662009-10-29 08:12:44 +00002337 // FIXME: preserve source information here when we start
2338 // caring about parameter packs.
2339
John McCall0d07eb32009-10-29 18:45:58 +00002340 TemplateArgumentLoc InputArg;
2341 TemplateArgumentLoc OutputArg;
2342 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2343 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002344 return true;
2345
John McCall0d07eb32009-10-29 18:45:58 +00002346 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002347 }
2348 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002349 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002350 true);
John McCall0d07eb32009-10-29 18:45:58 +00002351 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002352 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002353 }
2354 }
Mike Stump11289f42009-09-09 15:08:12 +00002355
Douglas Gregore922c772009-08-04 22:27:00 +00002356 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002357 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002358}
2359
Douglas Gregord6ff3322009-08-04 16:50:30 +00002360//===----------------------------------------------------------------------===//
2361// Type transformation
2362//===----------------------------------------------------------------------===//
2363
2364template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002365QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002366 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002367 if (getDerived().AlreadyTransformed(T))
2368 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002369
John McCall550e0c22009-10-21 00:40:46 +00002370 // Temporary workaround. All of these transformations should
2371 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002372 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002373 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002374
Douglas Gregorfe17d252010-02-16 19:09:40 +00002375 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002376
John McCall550e0c22009-10-21 00:40:46 +00002377 if (!NewDI)
2378 return QualType();
2379
2380 return NewDI->getType();
2381}
2382
2383template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002384TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2385 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002386 if (getDerived().AlreadyTransformed(DI->getType()))
2387 return DI;
2388
2389 TypeLocBuilder TLB;
2390
2391 TypeLoc TL = DI->getTypeLoc();
2392 TLB.reserve(TL.getFullDataSize());
2393
Douglas Gregorfe17d252010-02-16 19:09:40 +00002394 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002395 if (Result.isNull())
2396 return 0;
2397
John McCallbcd03502009-12-07 02:54:59 +00002398 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002399}
2400
2401template<typename Derived>
2402QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002403TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2404 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002405 switch (T.getTypeLocClass()) {
2406#define ABSTRACT_TYPELOC(CLASS, PARENT)
2407#define TYPELOC(CLASS, PARENT) \
2408 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002409 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2410 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002411#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002412 }
Mike Stump11289f42009-09-09 15:08:12 +00002413
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002414 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002415 return QualType();
2416}
2417
2418/// FIXME: By default, this routine adds type qualifiers only to types
2419/// that can have qualifiers, and silently suppresses those qualifiers
2420/// that are not permitted (e.g., qualifiers on reference or function
2421/// types). This is the right thing for template instantiation, but
2422/// probably not for other clients.
2423template<typename Derived>
2424QualType
2425TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002426 QualifiedTypeLoc T,
2427 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002428 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002429
Douglas Gregorfe17d252010-02-16 19:09:40 +00002430 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2431 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002432 if (Result.isNull())
2433 return QualType();
2434
2435 // Silently suppress qualifiers if the result type can't be qualified.
2436 // FIXME: this is the right thing for template instantiation, but
2437 // probably not for other clients.
2438 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002439 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002440
John McCall550e0c22009-10-21 00:40:46 +00002441 Result = SemaRef.Context.getQualifiedType(Result, Quals);
2442
2443 TLB.push<QualifiedTypeLoc>(Result);
2444
2445 // No location information to preserve.
2446
2447 return Result;
2448}
2449
2450template <class TyLoc> static inline
2451QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2452 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2453 NewT.setNameLoc(T.getNameLoc());
2454 return T.getType();
2455}
2456
John McCall550e0c22009-10-21 00:40:46 +00002457template<typename Derived>
2458QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002459 BuiltinTypeLoc T,
2460 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002461 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2462 NewT.setBuiltinLoc(T.getBuiltinLoc());
2463 if (T.needsExtraLocalData())
2464 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2465 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002466}
Mike Stump11289f42009-09-09 15:08:12 +00002467
Douglas Gregord6ff3322009-08-04 16:50:30 +00002468template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002469QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002470 ComplexTypeLoc T,
2471 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002472 // FIXME: recurse?
2473 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002474}
Mike Stump11289f42009-09-09 15:08:12 +00002475
Douglas Gregord6ff3322009-08-04 16:50:30 +00002476template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002477QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002478 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002479 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002480 QualType PointeeType
2481 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002482 if (PointeeType.isNull())
2483 return QualType();
2484
2485 QualType Result = TL.getType();
2486 if (PointeeType->isObjCInterfaceType()) {
2487 // A dependent pointer type 'T *' has is being transformed such
2488 // that an Objective-C class type is being replaced for 'T'. The
2489 // resulting pointer type is an ObjCObjectPointerType, not a
2490 // PointerType.
2491 const ObjCInterfaceType *IFace = PointeeType->getAs<ObjCInterfaceType>();
2492 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType,
2493 const_cast<ObjCProtocolDecl **>(
2494 IFace->qual_begin()),
2495 IFace->getNumProtocols());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002496
2497 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2498 NewT.setStarLoc(TL.getSigilLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002499 NewT.setHasProtocolsAsWritten(false);
2500 NewT.setLAngleLoc(SourceLocation());
2501 NewT.setRAngleLoc(SourceLocation());
2502 NewT.setHasBaseTypeAsWritten(true);
2503 return Result;
2504 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002505
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002506 if (getDerived().AlwaysRebuild() ||
2507 PointeeType != TL.getPointeeLoc().getType()) {
2508 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2509 if (Result.isNull())
2510 return QualType();
2511 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002512
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002513 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2514 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002515 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002516}
Mike Stump11289f42009-09-09 15:08:12 +00002517
2518template<typename Derived>
2519QualType
John McCall550e0c22009-10-21 00:40:46 +00002520TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002521 BlockPointerTypeLoc TL,
2522 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002523 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002524 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2525 if (PointeeType.isNull())
2526 return QualType();
2527
2528 QualType Result = TL.getType();
2529 if (getDerived().AlwaysRebuild() ||
2530 PointeeType != TL.getPointeeLoc().getType()) {
2531 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002532 TL.getSigilLoc());
2533 if (Result.isNull())
2534 return QualType();
2535 }
2536
Douglas Gregor049211a2010-04-22 16:50:51 +00002537 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002538 NewT.setSigilLoc(TL.getSigilLoc());
2539 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002540}
2541
John McCall70dd5f62009-10-30 00:06:24 +00002542/// Transforms a reference type. Note that somewhat paradoxically we
2543/// don't care whether the type itself is an l-value type or an r-value
2544/// type; we only care if the type was *written* as an l-value type
2545/// or an r-value type.
2546template<typename Derived>
2547QualType
2548TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002549 ReferenceTypeLoc TL,
2550 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002551 const ReferenceType *T = TL.getTypePtr();
2552
2553 // Note that this works with the pointee-as-written.
2554 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2555 if (PointeeType.isNull())
2556 return QualType();
2557
2558 QualType Result = TL.getType();
2559 if (getDerived().AlwaysRebuild() ||
2560 PointeeType != T->getPointeeTypeAsWritten()) {
2561 Result = getDerived().RebuildReferenceType(PointeeType,
2562 T->isSpelledAsLValue(),
2563 TL.getSigilLoc());
2564 if (Result.isNull())
2565 return QualType();
2566 }
2567
2568 // r-value references can be rebuilt as l-value references.
2569 ReferenceTypeLoc NewTL;
2570 if (isa<LValueReferenceType>(Result))
2571 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2572 else
2573 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2574 NewTL.setSigilLoc(TL.getSigilLoc());
2575
2576 return Result;
2577}
2578
Mike Stump11289f42009-09-09 15:08:12 +00002579template<typename Derived>
2580QualType
John McCall550e0c22009-10-21 00:40:46 +00002581TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002582 LValueReferenceTypeLoc TL,
2583 QualType ObjectType) {
2584 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002585}
2586
Mike Stump11289f42009-09-09 15:08:12 +00002587template<typename Derived>
2588QualType
John McCall550e0c22009-10-21 00:40:46 +00002589TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002590 RValueReferenceTypeLoc TL,
2591 QualType ObjectType) {
2592 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002593}
Mike Stump11289f42009-09-09 15:08:12 +00002594
Douglas Gregord6ff3322009-08-04 16:50:30 +00002595template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002596QualType
John McCall550e0c22009-10-21 00:40:46 +00002597TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002598 MemberPointerTypeLoc TL,
2599 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002600 MemberPointerType *T = TL.getTypePtr();
2601
2602 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002603 if (PointeeType.isNull())
2604 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002605
John McCall550e0c22009-10-21 00:40:46 +00002606 // TODO: preserve source information for this.
2607 QualType ClassType
2608 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002609 if (ClassType.isNull())
2610 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002611
John McCall550e0c22009-10-21 00:40:46 +00002612 QualType Result = TL.getType();
2613 if (getDerived().AlwaysRebuild() ||
2614 PointeeType != T->getPointeeType() ||
2615 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002616 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2617 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002618 if (Result.isNull())
2619 return QualType();
2620 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002621
John McCall550e0c22009-10-21 00:40:46 +00002622 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2623 NewTL.setSigilLoc(TL.getSigilLoc());
2624
2625 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002626}
2627
Mike Stump11289f42009-09-09 15:08:12 +00002628template<typename Derived>
2629QualType
John McCall550e0c22009-10-21 00:40:46 +00002630TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002631 ConstantArrayTypeLoc TL,
2632 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002633 ConstantArrayType *T = TL.getTypePtr();
2634 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002635 if (ElementType.isNull())
2636 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002637
John McCall550e0c22009-10-21 00:40:46 +00002638 QualType Result = TL.getType();
2639 if (getDerived().AlwaysRebuild() ||
2640 ElementType != T->getElementType()) {
2641 Result = getDerived().RebuildConstantArrayType(ElementType,
2642 T->getSizeModifier(),
2643 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002644 T->getIndexTypeCVRQualifiers(),
2645 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002646 if (Result.isNull())
2647 return QualType();
2648 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002649
John McCall550e0c22009-10-21 00:40:46 +00002650 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2651 NewTL.setLBracketLoc(TL.getLBracketLoc());
2652 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002653
John McCall550e0c22009-10-21 00:40:46 +00002654 Expr *Size = TL.getSizeExpr();
2655 if (Size) {
2656 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2657 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2658 }
2659 NewTL.setSizeExpr(Size);
2660
2661 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002662}
Mike Stump11289f42009-09-09 15:08:12 +00002663
Douglas Gregord6ff3322009-08-04 16:50:30 +00002664template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002665QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002666 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002667 IncompleteArrayTypeLoc TL,
2668 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002669 IncompleteArrayType *T = TL.getTypePtr();
2670 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002671 if (ElementType.isNull())
2672 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002673
John McCall550e0c22009-10-21 00:40:46 +00002674 QualType Result = TL.getType();
2675 if (getDerived().AlwaysRebuild() ||
2676 ElementType != T->getElementType()) {
2677 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002678 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002679 T->getIndexTypeCVRQualifiers(),
2680 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002681 if (Result.isNull())
2682 return QualType();
2683 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002684
John McCall550e0c22009-10-21 00:40:46 +00002685 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2686 NewTL.setLBracketLoc(TL.getLBracketLoc());
2687 NewTL.setRBracketLoc(TL.getRBracketLoc());
2688 NewTL.setSizeExpr(0);
2689
2690 return Result;
2691}
2692
2693template<typename Derived>
2694QualType
2695TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002696 VariableArrayTypeLoc TL,
2697 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002698 VariableArrayType *T = TL.getTypePtr();
2699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2700 if (ElementType.isNull())
2701 return QualType();
2702
2703 // Array bounds are not potentially evaluated contexts
2704 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2705
2706 Sema::OwningExprResult SizeResult
2707 = getDerived().TransformExpr(T->getSizeExpr());
2708 if (SizeResult.isInvalid())
2709 return QualType();
2710
2711 Expr *Size = static_cast<Expr*>(SizeResult.get());
2712
2713 QualType Result = TL.getType();
2714 if (getDerived().AlwaysRebuild() ||
2715 ElementType != T->getElementType() ||
2716 Size != T->getSizeExpr()) {
2717 Result = getDerived().RebuildVariableArrayType(ElementType,
2718 T->getSizeModifier(),
2719 move(SizeResult),
2720 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002721 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002722 if (Result.isNull())
2723 return QualType();
2724 }
2725 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002726
John McCall550e0c22009-10-21 00:40:46 +00002727 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2728 NewTL.setLBracketLoc(TL.getLBracketLoc());
2729 NewTL.setRBracketLoc(TL.getRBracketLoc());
2730 NewTL.setSizeExpr(Size);
2731
2732 return Result;
2733}
2734
2735template<typename Derived>
2736QualType
2737TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002738 DependentSizedArrayTypeLoc TL,
2739 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002740 DependentSizedArrayType *T = TL.getTypePtr();
2741 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2742 if (ElementType.isNull())
2743 return QualType();
2744
2745 // Array bounds are not potentially evaluated contexts
2746 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2747
2748 Sema::OwningExprResult SizeResult
2749 = getDerived().TransformExpr(T->getSizeExpr());
2750 if (SizeResult.isInvalid())
2751 return QualType();
2752
2753 Expr *Size = static_cast<Expr*>(SizeResult.get());
2754
2755 QualType Result = TL.getType();
2756 if (getDerived().AlwaysRebuild() ||
2757 ElementType != T->getElementType() ||
2758 Size != T->getSizeExpr()) {
2759 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2760 T->getSizeModifier(),
2761 move(SizeResult),
2762 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002763 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002764 if (Result.isNull())
2765 return QualType();
2766 }
2767 else SizeResult.take();
2768
2769 // We might have any sort of array type now, but fortunately they
2770 // all have the same location layout.
2771 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2772 NewTL.setLBracketLoc(TL.getLBracketLoc());
2773 NewTL.setRBracketLoc(TL.getRBracketLoc());
2774 NewTL.setSizeExpr(Size);
2775
2776 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002777}
Mike Stump11289f42009-09-09 15:08:12 +00002778
2779template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002780QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002781 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002782 DependentSizedExtVectorTypeLoc TL,
2783 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002784 DependentSizedExtVectorType *T = TL.getTypePtr();
2785
2786 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002787 QualType ElementType = getDerived().TransformType(T->getElementType());
2788 if (ElementType.isNull())
2789 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002790
Douglas Gregore922c772009-08-04 22:27:00 +00002791 // Vector sizes are not potentially evaluated contexts
2792 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2793
Douglas Gregord6ff3322009-08-04 16:50:30 +00002794 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2795 if (Size.isInvalid())
2796 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002797
John McCall550e0c22009-10-21 00:40:46 +00002798 QualType Result = TL.getType();
2799 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002800 ElementType != T->getElementType() ||
2801 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002802 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002803 move(Size),
2804 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002805 if (Result.isNull())
2806 return QualType();
2807 }
2808 else Size.take();
2809
2810 // Result might be dependent or not.
2811 if (isa<DependentSizedExtVectorType>(Result)) {
2812 DependentSizedExtVectorTypeLoc NewTL
2813 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2814 NewTL.setNameLoc(TL.getNameLoc());
2815 } else {
2816 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2817 NewTL.setNameLoc(TL.getNameLoc());
2818 }
2819
2820 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002821}
Mike Stump11289f42009-09-09 15:08:12 +00002822
2823template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002824QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002825 VectorTypeLoc TL,
2826 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002827 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002828 QualType ElementType = getDerived().TransformType(T->getElementType());
2829 if (ElementType.isNull())
2830 return QualType();
2831
John McCall550e0c22009-10-21 00:40:46 +00002832 QualType Result = TL.getType();
2833 if (getDerived().AlwaysRebuild() ||
2834 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002835 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
2836 T->isAltiVec(), T->isPixel());
John McCall550e0c22009-10-21 00:40:46 +00002837 if (Result.isNull())
2838 return QualType();
2839 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002840
John McCall550e0c22009-10-21 00:40:46 +00002841 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2842 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002843
John McCall550e0c22009-10-21 00:40:46 +00002844 return Result;
2845}
2846
2847template<typename Derived>
2848QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002849 ExtVectorTypeLoc TL,
2850 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002851 VectorType *T = TL.getTypePtr();
2852 QualType ElementType = getDerived().TransformType(T->getElementType());
2853 if (ElementType.isNull())
2854 return QualType();
2855
2856 QualType Result = TL.getType();
2857 if (getDerived().AlwaysRebuild() ||
2858 ElementType != T->getElementType()) {
2859 Result = getDerived().RebuildExtVectorType(ElementType,
2860 T->getNumElements(),
2861 /*FIXME*/ SourceLocation());
2862 if (Result.isNull())
2863 return QualType();
2864 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002865
John McCall550e0c22009-10-21 00:40:46 +00002866 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2867 NewTL.setNameLoc(TL.getNameLoc());
2868
2869 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002870}
Mike Stump11289f42009-09-09 15:08:12 +00002871
2872template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002873ParmVarDecl *
2874TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2875 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2876 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2877 if (!NewDI)
2878 return 0;
2879
2880 if (NewDI == OldDI)
2881 return OldParm;
2882 else
2883 return ParmVarDecl::Create(SemaRef.Context,
2884 OldParm->getDeclContext(),
2885 OldParm->getLocation(),
2886 OldParm->getIdentifier(),
2887 NewDI->getType(),
2888 NewDI,
2889 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002890 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002891 /* DefArg */ NULL);
2892}
2893
2894template<typename Derived>
2895bool TreeTransform<Derived>::
2896 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2897 llvm::SmallVectorImpl<QualType> &PTypes,
2898 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2899 FunctionProtoType *T = TL.getTypePtr();
2900
2901 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2902 ParmVarDecl *OldParm = TL.getArg(i);
2903
2904 QualType NewType;
2905 ParmVarDecl *NewParm;
2906
2907 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002908 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2909 if (!NewParm)
2910 return true;
2911 NewType = NewParm->getType();
2912
2913 // Deal with the possibility that we don't have a parameter
2914 // declaration for this parameter.
2915 } else {
2916 NewParm = 0;
2917
2918 QualType OldType = T->getArgType(i);
2919 NewType = getDerived().TransformType(OldType);
2920 if (NewType.isNull())
2921 return true;
2922 }
2923
2924 PTypes.push_back(NewType);
2925 PVars.push_back(NewParm);
2926 }
2927
2928 return false;
2929}
2930
2931template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002932QualType
John McCall550e0c22009-10-21 00:40:46 +00002933TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002934 FunctionProtoTypeLoc TL,
2935 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002936 // Transform the parameters. We do this first for the benefit of template
2937 // instantiations, so that the ParmVarDecls get/ placed into the template
2938 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002939 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002940 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002941 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2942 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002943
Douglas Gregor14cf7522010-04-30 18:55:50 +00002944 FunctionProtoType *T = TL.getTypePtr();
2945 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2946 if (ResultType.isNull())
2947 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002948
John McCall550e0c22009-10-21 00:40:46 +00002949 QualType Result = TL.getType();
2950 if (getDerived().AlwaysRebuild() ||
2951 ResultType != T->getResultType() ||
2952 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2953 Result = getDerived().RebuildFunctionProtoType(ResultType,
2954 ParamTypes.data(),
2955 ParamTypes.size(),
2956 T->isVariadic(),
2957 T->getTypeQuals());
2958 if (Result.isNull())
2959 return QualType();
2960 }
Mike Stump11289f42009-09-09 15:08:12 +00002961
John McCall550e0c22009-10-21 00:40:46 +00002962 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2963 NewTL.setLParenLoc(TL.getLParenLoc());
2964 NewTL.setRParenLoc(TL.getRParenLoc());
2965 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2966 NewTL.setArg(i, ParamDecls[i]);
2967
2968 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969}
Mike Stump11289f42009-09-09 15:08:12 +00002970
Douglas Gregord6ff3322009-08-04 16:50:30 +00002971template<typename Derived>
2972QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002973 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002974 FunctionNoProtoTypeLoc TL,
2975 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002976 FunctionNoProtoType *T = TL.getTypePtr();
2977 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2978 if (ResultType.isNull())
2979 return QualType();
2980
2981 QualType Result = TL.getType();
2982 if (getDerived().AlwaysRebuild() ||
2983 ResultType != T->getResultType())
2984 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2985
2986 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2987 NewTL.setLParenLoc(TL.getLParenLoc());
2988 NewTL.setRParenLoc(TL.getRParenLoc());
2989
2990 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002991}
Mike Stump11289f42009-09-09 15:08:12 +00002992
John McCallb96ec562009-12-04 22:46:56 +00002993template<typename Derived> QualType
2994TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002995 UnresolvedUsingTypeLoc TL,
2996 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002997 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002998 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002999 if (!D)
3000 return QualType();
3001
3002 QualType Result = TL.getType();
3003 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3004 Result = getDerived().RebuildUnresolvedUsingType(D);
3005 if (Result.isNull())
3006 return QualType();
3007 }
3008
3009 // We might get an arbitrary type spec type back. We should at
3010 // least always get a type spec type, though.
3011 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3012 NewTL.setNameLoc(TL.getNameLoc());
3013
3014 return Result;
3015}
3016
Douglas Gregord6ff3322009-08-04 16:50:30 +00003017template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003018QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003019 TypedefTypeLoc TL,
3020 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003021 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003022 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003023 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3024 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003025 if (!Typedef)
3026 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003027
John McCall550e0c22009-10-21 00:40:46 +00003028 QualType Result = TL.getType();
3029 if (getDerived().AlwaysRebuild() ||
3030 Typedef != T->getDecl()) {
3031 Result = getDerived().RebuildTypedefType(Typedef);
3032 if (Result.isNull())
3033 return QualType();
3034 }
Mike Stump11289f42009-09-09 15:08:12 +00003035
John McCall550e0c22009-10-21 00:40:46 +00003036 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3037 NewTL.setNameLoc(TL.getNameLoc());
3038
3039 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003040}
Mike Stump11289f42009-09-09 15:08:12 +00003041
Douglas Gregord6ff3322009-08-04 16:50:30 +00003042template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003043QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003044 TypeOfExprTypeLoc TL,
3045 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003046 // typeof expressions are not potentially evaluated contexts
3047 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003048
John McCalle8595032010-01-13 20:03:27 +00003049 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003050 if (E.isInvalid())
3051 return QualType();
3052
John McCall550e0c22009-10-21 00:40:46 +00003053 QualType Result = TL.getType();
3054 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003055 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003056 Result = getDerived().RebuildTypeOfExprType(move(E));
3057 if (Result.isNull())
3058 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003059 }
John McCall550e0c22009-10-21 00:40:46 +00003060 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003061
John McCall550e0c22009-10-21 00:40:46 +00003062 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003063 NewTL.setTypeofLoc(TL.getTypeofLoc());
3064 NewTL.setLParenLoc(TL.getLParenLoc());
3065 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003066
3067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003068}
Mike Stump11289f42009-09-09 15:08:12 +00003069
3070template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003071QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003072 TypeOfTypeLoc TL,
3073 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003074 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3075 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3076 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003077 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003078
John McCall550e0c22009-10-21 00:40:46 +00003079 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003080 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3081 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003082 if (Result.isNull())
3083 return QualType();
3084 }
Mike Stump11289f42009-09-09 15:08:12 +00003085
John McCall550e0c22009-10-21 00:40:46 +00003086 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003087 NewTL.setTypeofLoc(TL.getTypeofLoc());
3088 NewTL.setLParenLoc(TL.getLParenLoc());
3089 NewTL.setRParenLoc(TL.getRParenLoc());
3090 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003091
3092 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003093}
Mike Stump11289f42009-09-09 15:08:12 +00003094
3095template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003096QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003097 DecltypeTypeLoc TL,
3098 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003099 DecltypeType *T = TL.getTypePtr();
3100
Douglas Gregore922c772009-08-04 22:27:00 +00003101 // decltype expressions are not potentially evaluated contexts
3102 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003103
Douglas Gregord6ff3322009-08-04 16:50:30 +00003104 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3105 if (E.isInvalid())
3106 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003107
John McCall550e0c22009-10-21 00:40:46 +00003108 QualType Result = TL.getType();
3109 if (getDerived().AlwaysRebuild() ||
3110 E.get() != T->getUnderlyingExpr()) {
3111 Result = getDerived().RebuildDecltypeType(move(E));
3112 if (Result.isNull())
3113 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114 }
John McCall550e0c22009-10-21 00:40:46 +00003115 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003116
John McCall550e0c22009-10-21 00:40:46 +00003117 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3118 NewTL.setNameLoc(TL.getNameLoc());
3119
3120 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121}
3122
3123template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003124QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003125 RecordTypeLoc TL,
3126 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003127 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003128 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003129 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3130 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003131 if (!Record)
3132 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003133
John McCall550e0c22009-10-21 00:40:46 +00003134 QualType Result = TL.getType();
3135 if (getDerived().AlwaysRebuild() ||
3136 Record != T->getDecl()) {
3137 Result = getDerived().RebuildRecordType(Record);
3138 if (Result.isNull())
3139 return QualType();
3140 }
Mike Stump11289f42009-09-09 15:08:12 +00003141
John McCall550e0c22009-10-21 00:40:46 +00003142 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3143 NewTL.setNameLoc(TL.getNameLoc());
3144
3145 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003146}
Mike Stump11289f42009-09-09 15:08:12 +00003147
3148template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003149QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003150 EnumTypeLoc TL,
3151 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003152 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003153 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003154 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3155 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003156 if (!Enum)
3157 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003158
John McCall550e0c22009-10-21 00:40:46 +00003159 QualType Result = TL.getType();
3160 if (getDerived().AlwaysRebuild() ||
3161 Enum != T->getDecl()) {
3162 Result = getDerived().RebuildEnumType(Enum);
3163 if (Result.isNull())
3164 return QualType();
3165 }
Mike Stump11289f42009-09-09 15:08:12 +00003166
John McCall550e0c22009-10-21 00:40:46 +00003167 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3168 NewTL.setNameLoc(TL.getNameLoc());
3169
3170 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003171}
John McCallfcc33b02009-09-05 00:15:47 +00003172
3173template <typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003174QualType TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003175 ElaboratedTypeLoc TL,
3176 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003177 ElaboratedType *T = TL.getTypePtr();
3178
3179 // FIXME: this should be a nested type.
John McCallfcc33b02009-09-05 00:15:47 +00003180 QualType Underlying = getDerived().TransformType(T->getUnderlyingType());
3181 if (Underlying.isNull())
3182 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003183
John McCall550e0c22009-10-21 00:40:46 +00003184 QualType Result = TL.getType();
3185 if (getDerived().AlwaysRebuild() ||
3186 Underlying != T->getUnderlyingType()) {
3187 Result = getDerived().RebuildElaboratedType(Underlying, T->getTagKind());
3188 if (Result.isNull())
3189 return QualType();
3190 }
Mike Stump11289f42009-09-09 15:08:12 +00003191
John McCall550e0c22009-10-21 00:40:46 +00003192 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3193 NewTL.setNameLoc(TL.getNameLoc());
3194
3195 return Result;
John McCallfcc33b02009-09-05 00:15:47 +00003196}
Mike Stump11289f42009-09-09 15:08:12 +00003197
John McCalle78aac42010-03-10 03:28:59 +00003198template<typename Derived>
3199QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3200 TypeLocBuilder &TLB,
3201 InjectedClassNameTypeLoc TL,
3202 QualType ObjectType) {
3203 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3204 TL.getTypePtr()->getDecl());
3205 if (!D) return QualType();
3206
3207 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3208 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3209 return T;
3210}
3211
Mike Stump11289f42009-09-09 15:08:12 +00003212
Douglas Gregord6ff3322009-08-04 16:50:30 +00003213template<typename Derived>
3214QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003215 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003216 TemplateTypeParmTypeLoc TL,
3217 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003218 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003219}
3220
Mike Stump11289f42009-09-09 15:08:12 +00003221template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003222QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003223 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003224 SubstTemplateTypeParmTypeLoc TL,
3225 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003226 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003227}
3228
3229template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003230QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3231 const TemplateSpecializationType *TST,
3232 QualType ObjectType) {
3233 // FIXME: this entire method is a temporary workaround; callers
3234 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003235
John McCall0ad16662009-10-29 08:12:44 +00003236 // Fake up a TemplateSpecializationTypeLoc.
3237 TypeLocBuilder TLB;
3238 TemplateSpecializationTypeLoc TL
3239 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3240
John McCall0d07eb32009-10-29 18:45:58 +00003241 SourceLocation BaseLoc = getDerived().getBaseLocation();
3242
3243 TL.setTemplateNameLoc(BaseLoc);
3244 TL.setLAngleLoc(BaseLoc);
3245 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003246 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3247 const TemplateArgument &TA = TST->getArg(i);
3248 TemplateArgumentLoc TAL;
3249 getDerived().InventTemplateArgumentLoc(TA, TAL);
3250 TL.setArgLocInfo(i, TAL.getLocInfo());
3251 }
3252
3253 TypeLocBuilder IgnoredTLB;
3254 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003255}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003256
Douglas Gregorc59e5612009-10-19 22:04:39 +00003257template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003258QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003259 TypeLocBuilder &TLB,
3260 TemplateSpecializationTypeLoc TL,
3261 QualType ObjectType) {
3262 const TemplateSpecializationType *T = TL.getTypePtr();
3263
Mike Stump11289f42009-09-09 15:08:12 +00003264 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003265 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003266 if (Template.isNull())
3267 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003268
John McCall6b51f282009-11-23 01:53:49 +00003269 TemplateArgumentListInfo NewTemplateArgs;
3270 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3271 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3272
3273 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3274 TemplateArgumentLoc Loc;
3275 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003276 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003277 NewTemplateArgs.addArgument(Loc);
3278 }
Mike Stump11289f42009-09-09 15:08:12 +00003279
John McCall0ad16662009-10-29 08:12:44 +00003280 // FIXME: maybe don't rebuild if all the template arguments are the same.
3281
3282 QualType Result =
3283 getDerived().RebuildTemplateSpecializationType(Template,
3284 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003285 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003286
3287 if (!Result.isNull()) {
3288 TemplateSpecializationTypeLoc NewTL
3289 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3290 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3291 NewTL.setLAngleLoc(TL.getLAngleLoc());
3292 NewTL.setRAngleLoc(TL.getRAngleLoc());
3293 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3294 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003295 }
Mike Stump11289f42009-09-09 15:08:12 +00003296
John McCall0ad16662009-10-29 08:12:44 +00003297 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003298}
Mike Stump11289f42009-09-09 15:08:12 +00003299
3300template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003301QualType
3302TreeTransform<Derived>::TransformQualifiedNameType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003303 QualifiedNameTypeLoc TL,
3304 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003305 QualifiedNameType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003306 NestedNameSpecifier *NNS
3307 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00003308 SourceRange(),
3309 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003310 if (!NNS)
3311 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003312
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313 QualType Named = getDerived().TransformType(T->getNamedType());
3314 if (Named.isNull())
3315 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003316
John McCall550e0c22009-10-21 00:40:46 +00003317 QualType Result = TL.getType();
3318 if (getDerived().AlwaysRebuild() ||
3319 NNS != T->getQualifier() ||
3320 Named != T->getNamedType()) {
3321 Result = getDerived().RebuildQualifiedNameType(NNS, Named);
3322 if (Result.isNull())
3323 return QualType();
3324 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003325
John McCall550e0c22009-10-21 00:40:46 +00003326 QualifiedNameTypeLoc NewTL = TLB.push<QualifiedNameTypeLoc>(Result);
3327 NewTL.setNameLoc(TL.getNameLoc());
3328
3329 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003330}
Mike Stump11289f42009-09-09 15:08:12 +00003331
3332template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003333QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3334 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003335 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003336 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003337
3338 /* FIXME: preserve source information better than this */
3339 SourceRange SR(TL.getNameLoc());
3340
Douglas Gregord6ff3322009-08-04 16:50:30 +00003341 NestedNameSpecifier *NNS
Douglas Gregorfe17d252010-02-16 19:09:40 +00003342 = getDerived().TransformNestedNameSpecifier(T->getQualifier(), SR,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003343 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003344 if (!NNS)
3345 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003346
John McCall550e0c22009-10-21 00:40:46 +00003347 QualType Result;
3348
Douglas Gregord6ff3322009-08-04 16:50:30 +00003349 if (const TemplateSpecializationType *TemplateId = T->getTemplateId()) {
Mike Stump11289f42009-09-09 15:08:12 +00003350 QualType NewTemplateId
Douglas Gregord6ff3322009-08-04 16:50:30 +00003351 = getDerived().TransformType(QualType(TemplateId, 0));
3352 if (NewTemplateId.isNull())
3353 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003354
Douglas Gregord6ff3322009-08-04 16:50:30 +00003355 if (!getDerived().AlwaysRebuild() &&
3356 NNS == T->getQualifier() &&
3357 NewTemplateId == QualType(TemplateId, 0))
3358 return QualType(T, 0);
Mike Stump11289f42009-09-09 15:08:12 +00003359
Alexis Hunta8136cc2010-05-05 15:23:54 +00003360 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003361 NewTemplateId);
John McCall550e0c22009-10-21 00:40:46 +00003362 } else {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003363 Result = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
Douglas Gregor02085352010-03-31 20:19:30 +00003364 T->getIdentifier(), SR);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365 }
John McCall550e0c22009-10-21 00:40:46 +00003366 if (Result.isNull())
3367 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003368
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003369 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00003370 NewTL.setNameLoc(TL.getNameLoc());
3371
3372 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003373}
Mike Stump11289f42009-09-09 15:08:12 +00003374
Douglas Gregord6ff3322009-08-04 16:50:30 +00003375template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003376QualType
3377TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003378 ObjCInterfaceTypeLoc TL,
3379 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003380 // ObjCInterfaceType is never dependent.
3381 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382}
Mike Stump11289f42009-09-09 15:08:12 +00003383
3384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003385QualType
3386TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003387 ObjCObjectPointerTypeLoc TL,
3388 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003389 // ObjCObjectPointerType is never dependent.
3390 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003391}
3392
Douglas Gregord6ff3322009-08-04 16:50:30 +00003393//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003394// Statement transformation
3395//===----------------------------------------------------------------------===//
3396template<typename Derived>
3397Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003398TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3399 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003400}
3401
3402template<typename Derived>
3403Sema::OwningStmtResult
3404TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3405 return getDerived().TransformCompoundStmt(S, false);
3406}
3407
3408template<typename Derived>
3409Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003410TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003411 bool IsStmtExpr) {
3412 bool SubStmtChanged = false;
3413 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3414 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3415 B != BEnd; ++B) {
3416 OwningStmtResult Result = getDerived().TransformStmt(*B);
3417 if (Result.isInvalid())
3418 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003419
Douglas Gregorebe10102009-08-20 07:17:43 +00003420 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3421 Statements.push_back(Result.takeAs<Stmt>());
3422 }
Mike Stump11289f42009-09-09 15:08:12 +00003423
Douglas Gregorebe10102009-08-20 07:17:43 +00003424 if (!getDerived().AlwaysRebuild() &&
3425 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003426 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003427
3428 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3429 move_arg(Statements),
3430 S->getRBracLoc(),
3431 IsStmtExpr);
3432}
Mike Stump11289f42009-09-09 15:08:12 +00003433
Douglas Gregorebe10102009-08-20 07:17:43 +00003434template<typename Derived>
3435Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003436TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003437 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3438 {
3439 // The case value expressions are not potentially evaluated.
3440 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003441
Eli Friedman06577382009-11-19 03:14:00 +00003442 // Transform the left-hand case value.
3443 LHS = getDerived().TransformExpr(S->getLHS());
3444 if (LHS.isInvalid())
3445 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003446
Eli Friedman06577382009-11-19 03:14:00 +00003447 // Transform the right-hand case value (for the GNU case-range extension).
3448 RHS = getDerived().TransformExpr(S->getRHS());
3449 if (RHS.isInvalid())
3450 return SemaRef.StmtError();
3451 }
Mike Stump11289f42009-09-09 15:08:12 +00003452
Douglas Gregorebe10102009-08-20 07:17:43 +00003453 // Build the case statement.
3454 // Case statements are always rebuilt so that they will attached to their
3455 // transformed switch statement.
3456 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3457 move(LHS),
3458 S->getEllipsisLoc(),
3459 move(RHS),
3460 S->getColonLoc());
3461 if (Case.isInvalid())
3462 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003463
Douglas Gregorebe10102009-08-20 07:17:43 +00003464 // Transform the statement following the case
3465 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3466 if (SubStmt.isInvalid())
3467 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003468
Douglas Gregorebe10102009-08-20 07:17:43 +00003469 // Attach the body to the case statement
3470 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3471}
3472
3473template<typename Derived>
3474Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003475TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003476 // Transform the statement following the default case
3477 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3478 if (SubStmt.isInvalid())
3479 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregorebe10102009-08-20 07:17:43 +00003481 // Default statements are always rebuilt
3482 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3483 move(SubStmt));
3484}
Mike Stump11289f42009-09-09 15:08:12 +00003485
Douglas Gregorebe10102009-08-20 07:17:43 +00003486template<typename Derived>
3487Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003488TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003489 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3490 if (SubStmt.isInvalid())
3491 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003492
Douglas Gregorebe10102009-08-20 07:17:43 +00003493 // FIXME: Pass the real colon location in.
3494 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3495 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3496 move(SubStmt));
3497}
Mike Stump11289f42009-09-09 15:08:12 +00003498
Douglas Gregorebe10102009-08-20 07:17:43 +00003499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003500Sema::OwningStmtResult
3501TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003503 OwningExprResult Cond(SemaRef);
3504 VarDecl *ConditionVar = 0;
3505 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003506 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003507 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003508 getDerived().TransformDefinition(
3509 S->getConditionVariable()->getLocation(),
3510 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003511 if (!ConditionVar)
3512 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003513 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003514 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003515
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003516 if (Cond.isInvalid())
3517 return SemaRef.StmtError();
3518 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003519
Douglas Gregorebe10102009-08-20 07:17:43 +00003520 // Transform the "then" branch.
3521 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3522 if (Then.isInvalid())
3523 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003524
Douglas Gregorebe10102009-08-20 07:17:43 +00003525 // Transform the "else" branch.
3526 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3527 if (Else.isInvalid())
3528 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003529
Douglas Gregorebe10102009-08-20 07:17:43 +00003530 if (!getDerived().AlwaysRebuild() &&
Douglas Gregore60e41a2010-05-06 17:25:47 +00003531 Cond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003532 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003533 Then.get() == S->getThen() &&
3534 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003535 return SemaRef.Owned(S->Retain());
3536
Douglas Gregore60e41a2010-05-06 17:25:47 +00003537 return getDerived().RebuildIfStmt(S->getIfLoc(), move(Cond), ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003538 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003539 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003540}
3541
3542template<typename Derived>
3543Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003544TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003545 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003546 OwningExprResult Cond(SemaRef);
3547 VarDecl *ConditionVar = 0;
3548 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003549 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003550 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003551 getDerived().TransformDefinition(
3552 S->getConditionVariable()->getLocation(),
3553 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003554 if (!ConditionVar)
3555 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003556 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003557 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003558
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003559 if (Cond.isInvalid())
3560 return SemaRef.StmtError();
3561 }
Mike Stump11289f42009-09-09 15:08:12 +00003562
Douglas Gregorebe10102009-08-20 07:17:43 +00003563 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003564 OwningStmtResult Switch
3565 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3566 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003567 if (Switch.isInvalid())
3568 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003569
Douglas Gregorebe10102009-08-20 07:17:43 +00003570 // Transform the body of the switch statement.
3571 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3572 if (Body.isInvalid())
3573 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003574
Douglas Gregorebe10102009-08-20 07:17:43 +00003575 // Complete the switch statement.
3576 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3577 move(Body));
3578}
Mike Stump11289f42009-09-09 15:08:12 +00003579
Douglas Gregorebe10102009-08-20 07:17:43 +00003580template<typename Derived>
3581Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003582TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003584 OwningExprResult Cond(SemaRef);
3585 VarDecl *ConditionVar = 0;
3586 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003587 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003588 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003589 getDerived().TransformDefinition(
3590 S->getConditionVariable()->getLocation(),
3591 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003592 if (!ConditionVar)
3593 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003594 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003595 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003596
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003597 if (Cond.isInvalid())
3598 return SemaRef.StmtError();
3599 }
Mike Stump11289f42009-09-09 15:08:12 +00003600
Douglas Gregorebe10102009-08-20 07:17:43 +00003601 // Transform the body
3602 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3603 if (Body.isInvalid())
3604 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003605
Douglas Gregorebe10102009-08-20 07:17:43 +00003606 if (!getDerived().AlwaysRebuild() &&
Douglas Gregore60e41a2010-05-06 17:25:47 +00003607 Cond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003608 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003609 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003610 return SemaRef.Owned(S->Retain());
3611
Douglas Gregore60e41a2010-05-06 17:25:47 +00003612 return getDerived().RebuildWhileStmt(S->getWhileLoc(), move(Cond),
3613 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003614}
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616template<typename Derived>
3617Sema::OwningStmtResult
3618TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
3619 // Transform the condition
3620 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3621 if (Cond.isInvalid())
3622 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003623
Douglas Gregorebe10102009-08-20 07:17:43 +00003624 // Transform the body
3625 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3626 if (Body.isInvalid())
3627 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregorebe10102009-08-20 07:17:43 +00003629 if (!getDerived().AlwaysRebuild() &&
3630 Cond.get() == S->getCond() &&
3631 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003632 return SemaRef.Owned(S->Retain());
3633
Douglas Gregorebe10102009-08-20 07:17:43 +00003634 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3635 /*FIXME:*/S->getWhileLoc(), move(Cond),
3636 S->getRParenLoc());
3637}
Mike Stump11289f42009-09-09 15:08:12 +00003638
Douglas Gregorebe10102009-08-20 07:17:43 +00003639template<typename Derived>
3640Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003641TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003642 // Transform the initialization statement
3643 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3644 if (Init.isInvalid())
3645 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003646
Douglas Gregorebe10102009-08-20 07:17:43 +00003647 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003648 OwningExprResult Cond(SemaRef);
3649 VarDecl *ConditionVar = 0;
3650 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003651 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003652 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003653 getDerived().TransformDefinition(
3654 S->getConditionVariable()->getLocation(),
3655 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003656 if (!ConditionVar)
3657 return SemaRef.StmtError();
3658 } else {
3659 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003660
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003661 if (Cond.isInvalid())
3662 return SemaRef.StmtError();
3663 }
Mike Stump11289f42009-09-09 15:08:12 +00003664
Douglas Gregorebe10102009-08-20 07:17:43 +00003665 // Transform the increment
3666 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3667 if (Inc.isInvalid())
3668 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003669
Douglas Gregorebe10102009-08-20 07:17:43 +00003670 // Transform the body
3671 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3672 if (Body.isInvalid())
3673 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003674
Douglas Gregorebe10102009-08-20 07:17:43 +00003675 if (!getDerived().AlwaysRebuild() &&
3676 Init.get() == S->getInit() &&
3677 Cond.get() == S->getCond() &&
3678 Inc.get() == S->getInc() &&
3679 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003680 return SemaRef.Owned(S->Retain());
3681
Douglas Gregorebe10102009-08-20 07:17:43 +00003682 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00003683 move(Init), move(Cond), ConditionVar,
Anders Carlssonafb2dad2009-12-16 02:09:40 +00003684 getSema().MakeFullExpr(Inc),
Douglas Gregorebe10102009-08-20 07:17:43 +00003685 S->getRParenLoc(), move(Body));
3686}
3687
3688template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003689Sema::OwningStmtResult
3690TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003691 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003692 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003693 S->getLabel());
3694}
3695
3696template<typename Derived>
3697Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003698TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003699 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3700 if (Target.isInvalid())
3701 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003702
Douglas Gregorebe10102009-08-20 07:17:43 +00003703 if (!getDerived().AlwaysRebuild() &&
3704 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003705 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003706
3707 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3708 move(Target));
3709}
3710
3711template<typename Derived>
3712Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003713TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3714 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003715}
Mike Stump11289f42009-09-09 15:08:12 +00003716
Douglas Gregorebe10102009-08-20 07:17:43 +00003717template<typename Derived>
3718Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003719TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3720 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003721}
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>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003726 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3727 if (Result.isInvalid())
3728 return SemaRef.StmtError();
3729
Mike Stump11289f42009-09-09 15:08:12 +00003730 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003731 // to tell whether the return type of the function has changed.
3732 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3733}
Mike Stump11289f42009-09-09 15:08:12 +00003734
Douglas Gregorebe10102009-08-20 07:17:43 +00003735template<typename Derived>
3736Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003737TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003738 bool DeclChanged = false;
3739 llvm::SmallVector<Decl *, 4> Decls;
3740 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3741 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003742 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3743 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003744 if (!Transformed)
3745 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003746
Douglas Gregorebe10102009-08-20 07:17:43 +00003747 if (Transformed != *D)
3748 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003749
Douglas Gregorebe10102009-08-20 07:17:43 +00003750 Decls.push_back(Transformed);
3751 }
Mike Stump11289f42009-09-09 15:08:12 +00003752
Douglas Gregorebe10102009-08-20 07:17:43 +00003753 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003754 return SemaRef.Owned(S->Retain());
3755
3756 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003757 S->getStartLoc(), S->getEndLoc());
3758}
Mike Stump11289f42009-09-09 15:08:12 +00003759
Douglas Gregorebe10102009-08-20 07:17:43 +00003760template<typename Derived>
3761Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003762TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003763 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003764 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003765}
3766
3767template<typename Derived>
3768Sema::OwningStmtResult
3769TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003770
Anders Carlssonaaeef072010-01-24 05:50:09 +00003771 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3772 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003773 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003774
Anders Carlssonaaeef072010-01-24 05:50:09 +00003775 OwningExprResult AsmString(SemaRef);
3776 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3777
3778 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003779
Anders Carlssonaaeef072010-01-24 05:50:09 +00003780 // Go through the outputs.
3781 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003782 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003783
Anders Carlssonaaeef072010-01-24 05:50:09 +00003784 // No need to transform the constraint literal.
3785 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003786
Anders Carlssonaaeef072010-01-24 05:50:09 +00003787 // Transform the output expr.
3788 Expr *OutputExpr = S->getOutputExpr(I);
3789 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3790 if (Result.isInvalid())
3791 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003792
Anders Carlssonaaeef072010-01-24 05:50:09 +00003793 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003794
Anders Carlssonaaeef072010-01-24 05:50:09 +00003795 Exprs.push_back(Result.takeAs<Expr>());
3796 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003797
Anders Carlssonaaeef072010-01-24 05:50:09 +00003798 // Go through the inputs.
3799 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003800 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003801
Anders Carlssonaaeef072010-01-24 05:50:09 +00003802 // No need to transform the constraint literal.
3803 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003804
Anders Carlssonaaeef072010-01-24 05:50:09 +00003805 // Transform the input expr.
3806 Expr *InputExpr = S->getInputExpr(I);
3807 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3808 if (Result.isInvalid())
3809 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003810
Anders Carlssonaaeef072010-01-24 05:50:09 +00003811 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003812
Anders Carlssonaaeef072010-01-24 05:50:09 +00003813 Exprs.push_back(Result.takeAs<Expr>());
3814 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003815
Anders Carlssonaaeef072010-01-24 05:50:09 +00003816 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3817 return SemaRef.Owned(S->Retain());
3818
3819 // Go through the clobbers.
3820 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3821 Clobbers.push_back(S->getClobber(I)->Retain());
3822
3823 // No need to transform the asm string literal.
3824 AsmString = SemaRef.Owned(S->getAsmString());
3825
3826 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3827 S->isSimple(),
3828 S->isVolatile(),
3829 S->getNumOutputs(),
3830 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003831 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003832 move_arg(Constraints),
3833 move_arg(Exprs),
3834 move(AsmString),
3835 move_arg(Clobbers),
3836 S->getRParenLoc(),
3837 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003838}
3839
3840
3841template<typename Derived>
3842Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003843TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003844 // Transform the body of the @try.
3845 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3846 if (TryBody.isInvalid())
3847 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003848
Douglas Gregor96c79492010-04-23 22:50:49 +00003849 // Transform the @catch statements (if present).
3850 bool AnyCatchChanged = false;
3851 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3852 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3853 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003854 if (Catch.isInvalid())
3855 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003856 if (Catch.get() != S->getCatchStmt(I))
3857 AnyCatchChanged = true;
3858 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003859 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003860
Douglas Gregor306de2f2010-04-22 23:59:56 +00003861 // Transform the @finally statement (if present).
3862 OwningStmtResult Finally(SemaRef);
3863 if (S->getFinallyStmt()) {
3864 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3865 if (Finally.isInvalid())
3866 return SemaRef.StmtError();
3867 }
3868
3869 // If nothing changed, just retain this statement.
3870 if (!getDerived().AlwaysRebuild() &&
3871 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003872 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003873 Finally.get() == S->getFinallyStmt())
3874 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003875
Douglas Gregor306de2f2010-04-22 23:59:56 +00003876 // Build a new statement.
3877 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003878 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003879}
Mike Stump11289f42009-09-09 15:08:12 +00003880
Douglas Gregorebe10102009-08-20 07:17:43 +00003881template<typename Derived>
3882Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003883TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003884 // Transform the @catch parameter, if there is one.
3885 VarDecl *Var = 0;
3886 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3887 TypeSourceInfo *TSInfo = 0;
3888 if (FromVar->getTypeSourceInfo()) {
3889 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3890 if (!TSInfo)
3891 return SemaRef.StmtError();
3892 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003893
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003894 QualType T;
3895 if (TSInfo)
3896 T = TSInfo->getType();
3897 else {
3898 T = getDerived().TransformType(FromVar->getType());
3899 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003901 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003902
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003903 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3904 if (!Var)
3905 return SemaRef.StmtError();
3906 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003907
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003908 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3909 if (Body.isInvalid())
3910 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003911
3912 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003913 S->getRParenLoc(),
3914 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003915}
Mike Stump11289f42009-09-09 15:08:12 +00003916
Douglas Gregorebe10102009-08-20 07:17:43 +00003917template<typename Derived>
3918Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003919TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003920 // Transform the body.
3921 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
3922 if (Body.isInvalid())
3923 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003924
Douglas Gregor306de2f2010-04-22 23:59:56 +00003925 // If nothing changed, just retain this statement.
3926 if (!getDerived().AlwaysRebuild() &&
3927 Body.get() == S->getFinallyBody())
3928 return SemaRef.Owned(S->Retain());
3929
3930 // Build a new statement.
3931 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
3932 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003933}
Mike Stump11289f42009-09-09 15:08:12 +00003934
Douglas Gregorebe10102009-08-20 07:17:43 +00003935template<typename Derived>
3936Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003937TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00003938 OwningExprResult Operand(SemaRef);
3939 if (S->getThrowExpr()) {
3940 Operand = getDerived().TransformExpr(S->getThrowExpr());
3941 if (Operand.isInvalid())
3942 return getSema().StmtError();
3943 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003944
Douglas Gregor2900c162010-04-22 21:44:01 +00003945 if (!getDerived().AlwaysRebuild() &&
3946 Operand.get() == S->getThrowExpr())
3947 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003948
Douglas Gregor2900c162010-04-22 21:44:01 +00003949 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00003950}
Mike Stump11289f42009-09-09 15:08:12 +00003951
Douglas Gregorebe10102009-08-20 07:17:43 +00003952template<typename Derived>
3953Sema::OwningStmtResult
3954TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003955 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00003956 // Transform the object we are locking.
3957 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
3958 if (Object.isInvalid())
3959 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003960
Douglas Gregor6148de72010-04-22 22:01:21 +00003961 // Transform the body.
3962 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
3963 if (Body.isInvalid())
3964 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003965
Douglas Gregor6148de72010-04-22 22:01:21 +00003966 // If nothing change, just retain the current statement.
3967 if (!getDerived().AlwaysRebuild() &&
3968 Object.get() == S->getSynchExpr() &&
3969 Body.get() == S->getSynchBody())
3970 return SemaRef.Owned(S->Retain());
3971
3972 // Build a new statement.
3973 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
3974 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003975}
3976
3977template<typename Derived>
3978Sema::OwningStmtResult
3979TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00003980 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00003981 // Transform the element statement.
3982 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
3983 if (Element.isInvalid())
3984 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003985
Douglas Gregorf68a5082010-04-22 23:10:45 +00003986 // Transform the collection expression.
3987 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
3988 if (Collection.isInvalid())
3989 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003990
Douglas Gregorf68a5082010-04-22 23:10:45 +00003991 // Transform the body.
3992 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3993 if (Body.isInvalid())
3994 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003995
Douglas Gregorf68a5082010-04-22 23:10:45 +00003996 // If nothing changed, just retain this statement.
3997 if (!getDerived().AlwaysRebuild() &&
3998 Element.get() == S->getElement() &&
3999 Collection.get() == S->getCollection() &&
4000 Body.get() == S->getBody())
4001 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004002
Douglas Gregorf68a5082010-04-22 23:10:45 +00004003 // Build a new statement.
4004 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4005 /*FIXME:*/S->getForLoc(),
4006 move(Element),
4007 move(Collection),
4008 S->getRParenLoc(),
4009 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004010}
4011
4012
4013template<typename Derived>
4014Sema::OwningStmtResult
4015TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4016 // Transform the exception declaration, if any.
4017 VarDecl *Var = 0;
4018 if (S->getExceptionDecl()) {
4019 VarDecl *ExceptionDecl = S->getExceptionDecl();
4020 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4021 ExceptionDecl->getDeclName());
4022
4023 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4024 if (T.isNull())
4025 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004026
Douglas Gregorebe10102009-08-20 07:17:43 +00004027 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4028 T,
John McCallbcd03502009-12-07 02:54:59 +00004029 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004030 ExceptionDecl->getIdentifier(),
4031 ExceptionDecl->getLocation(),
4032 /*FIXME: Inaccurate*/
4033 SourceRange(ExceptionDecl->getLocation()));
4034 if (!Var || Var->isInvalidDecl()) {
4035 if (Var)
4036 Var->Destroy(SemaRef.Context);
4037 return SemaRef.StmtError();
4038 }
4039 }
Mike Stump11289f42009-09-09 15:08:12 +00004040
Douglas Gregorebe10102009-08-20 07:17:43 +00004041 // Transform the actual exception handler.
4042 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4043 if (Handler.isInvalid()) {
4044 if (Var)
4045 Var->Destroy(SemaRef.Context);
4046 return SemaRef.StmtError();
4047 }
Mike Stump11289f42009-09-09 15:08:12 +00004048
Douglas Gregorebe10102009-08-20 07:17:43 +00004049 if (!getDerived().AlwaysRebuild() &&
4050 !Var &&
4051 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004052 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004053
4054 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4055 Var,
4056 move(Handler));
4057}
Mike Stump11289f42009-09-09 15:08:12 +00004058
Douglas Gregorebe10102009-08-20 07:17:43 +00004059template<typename Derived>
4060Sema::OwningStmtResult
4061TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4062 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004063 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004064 = getDerived().TransformCompoundStmt(S->getTryBlock());
4065 if (TryBlock.isInvalid())
4066 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004067
Douglas Gregorebe10102009-08-20 07:17:43 +00004068 // Transform the handlers.
4069 bool HandlerChanged = false;
4070 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4071 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004072 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004073 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4074 if (Handler.isInvalid())
4075 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004076
Douglas Gregorebe10102009-08-20 07:17:43 +00004077 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4078 Handlers.push_back(Handler.takeAs<Stmt>());
4079 }
Mike Stump11289f42009-09-09 15:08:12 +00004080
Douglas Gregorebe10102009-08-20 07:17:43 +00004081 if (!getDerived().AlwaysRebuild() &&
4082 TryBlock.get() == S->getTryBlock() &&
4083 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004084 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004085
4086 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004087 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004088}
Mike Stump11289f42009-09-09 15:08:12 +00004089
Douglas Gregorebe10102009-08-20 07:17:43 +00004090//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004091// Expression transformation
4092//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004093template<typename Derived>
4094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004095TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004096 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004097}
Mike Stump11289f42009-09-09 15:08:12 +00004098
4099template<typename Derived>
4100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004101TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004102 NestedNameSpecifier *Qualifier = 0;
4103 if (E->getQualifier()) {
4104 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004105 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004106 if (!Qualifier)
4107 return SemaRef.ExprError();
4108 }
John McCallce546572009-12-08 09:08:17 +00004109
4110 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004111 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4112 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004113 if (!ND)
4114 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004115
Alexis Hunta8136cc2010-05-05 15:23:54 +00004116 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004117 Qualifier == E->getQualifier() &&
4118 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004119 !E->hasExplicitTemplateArgumentList()) {
4120
4121 // Mark it referenced in the new context regardless.
4122 // FIXME: this is a bit instantiation-specific.
4123 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4124
Mike Stump11289f42009-09-09 15:08:12 +00004125 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004126 }
John McCallce546572009-12-08 09:08:17 +00004127
4128 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4129 if (E->hasExplicitTemplateArgumentList()) {
4130 TemplateArgs = &TransArgs;
4131 TransArgs.setLAngleLoc(E->getLAngleLoc());
4132 TransArgs.setRAngleLoc(E->getRAngleLoc());
4133 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4134 TemplateArgumentLoc Loc;
4135 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4136 return SemaRef.ExprError();
4137 TransArgs.addArgument(Loc);
4138 }
4139 }
4140
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004141 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004142 ND, E->getLocation(), TemplateArgs);
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>::TransformIntegerLiteral(IntegerLiteral *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>::TransformFloatingLiteral(FloatingLiteral *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>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004160 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004161}
Mike Stump11289f42009-09-09 15:08:12 +00004162
Douglas Gregora16548e2009-08-11 05:31:07 +00004163template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004164Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004165TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004166 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004167}
Mike Stump11289f42009-09-09 15:08:12 +00004168
Douglas Gregora16548e2009-08-11 05:31:07 +00004169template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004170Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004171TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004172 return SemaRef.Owned(E->Retain());
4173}
4174
4175template<typename Derived>
4176Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004177TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004178 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4179 if (SubExpr.isInvalid())
4180 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004181
Douglas Gregora16548e2009-08-11 05:31:07 +00004182 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004183 return SemaRef.Owned(E->Retain());
4184
4185 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004186 E->getRParen());
4187}
4188
Mike Stump11289f42009-09-09 15:08:12 +00004189template<typename Derived>
4190Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004191TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4192 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004193 if (SubExpr.isInvalid())
4194 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004195
Douglas Gregora16548e2009-08-11 05:31:07 +00004196 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004197 return SemaRef.Owned(E->Retain());
4198
Douglas Gregora16548e2009-08-11 05:31:07 +00004199 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4200 E->getOpcode(),
4201 move(SubExpr));
4202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
Douglas Gregora16548e2009-08-11 05:31:07 +00004204template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004205Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004206TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4207 // Transform the type.
4208 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4209 if (!Type)
4210 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004211
Douglas Gregor882211c2010-04-28 22:16:22 +00004212 // Transform all of the components into components similar to what the
4213 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004214 // FIXME: It would be slightly more efficient in the non-dependent case to
4215 // just map FieldDecls, rather than requiring the rebuilder to look for
4216 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004217 // template code that we don't care.
4218 bool ExprChanged = false;
4219 typedef Action::OffsetOfComponent Component;
4220 typedef OffsetOfExpr::OffsetOfNode Node;
4221 llvm::SmallVector<Component, 4> Components;
4222 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4223 const Node &ON = E->getComponent(I);
4224 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004225 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004226 Comp.LocStart = ON.getRange().getBegin();
4227 Comp.LocEnd = ON.getRange().getEnd();
4228 switch (ON.getKind()) {
4229 case Node::Array: {
4230 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4231 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4232 if (Index.isInvalid())
4233 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004234
Douglas Gregor882211c2010-04-28 22:16:22 +00004235 ExprChanged = ExprChanged || Index.get() != FromIndex;
4236 Comp.isBrackets = true;
4237 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4238 break;
4239 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004240
Douglas Gregor882211c2010-04-28 22:16:22 +00004241 case Node::Field:
4242 case Node::Identifier:
4243 Comp.isBrackets = false;
4244 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004245 if (!Comp.U.IdentInfo)
4246 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004247
Douglas Gregor882211c2010-04-28 22:16:22 +00004248 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004249
Douglas Gregord1702062010-04-29 00:18:15 +00004250 case Node::Base:
4251 // Will be recomputed during the rebuild.
4252 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004253 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004254
Douglas Gregor882211c2010-04-28 22:16:22 +00004255 Components.push_back(Comp);
4256 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004257
Douglas Gregor882211c2010-04-28 22:16:22 +00004258 // If nothing changed, retain the existing expression.
4259 if (!getDerived().AlwaysRebuild() &&
4260 Type == E->getTypeSourceInfo() &&
4261 !ExprChanged)
4262 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004263
Douglas Gregor882211c2010-04-28 22:16:22 +00004264 // Build a new offsetof expression.
4265 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4266 Components.data(), Components.size(),
4267 E->getRParenLoc());
4268}
4269
4270template<typename Derived>
4271Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004272TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004273 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004274 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004275
John McCallbcd03502009-12-07 02:54:59 +00004276 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004277 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004278 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004279
John McCall4c98fd82009-11-04 07:28:41 +00004280 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004281 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004282
John McCall4c98fd82009-11-04 07:28:41 +00004283 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004284 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 E->getSourceRange());
4286 }
Mike Stump11289f42009-09-09 15:08:12 +00004287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004289 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004290 // C++0x [expr.sizeof]p1:
4291 // The operand is either an expression, which is an unevaluated operand
4292 // [...]
4293 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004294
Douglas Gregora16548e2009-08-11 05:31:07 +00004295 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4296 if (SubExpr.isInvalid())
4297 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004298
Douglas Gregora16548e2009-08-11 05:31:07 +00004299 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4300 return SemaRef.Owned(E->Retain());
4301 }
Mike Stump11289f42009-09-09 15:08:12 +00004302
Douglas Gregora16548e2009-08-11 05:31:07 +00004303 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4304 E->isSizeOf(),
4305 E->getSourceRange());
4306}
Mike Stump11289f42009-09-09 15:08:12 +00004307
Douglas Gregora16548e2009-08-11 05:31:07 +00004308template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004309Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004310TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004311 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4312 if (LHS.isInvalid())
4313 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004314
Douglas Gregora16548e2009-08-11 05:31:07 +00004315 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4316 if (RHS.isInvalid())
4317 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004318
4319
Douglas Gregora16548e2009-08-11 05:31:07 +00004320 if (!getDerived().AlwaysRebuild() &&
4321 LHS.get() == E->getLHS() &&
4322 RHS.get() == E->getRHS())
4323 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004324
Douglas Gregora16548e2009-08-11 05:31:07 +00004325 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4326 /*FIXME:*/E->getLHS()->getLocStart(),
4327 move(RHS),
4328 E->getRBracketLoc());
4329}
Mike Stump11289f42009-09-09 15:08:12 +00004330
4331template<typename Derived>
4332Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004333TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004334 // Transform the callee.
4335 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4336 if (Callee.isInvalid())
4337 return SemaRef.ExprError();
4338
4339 // Transform arguments.
4340 bool ArgChanged = false;
4341 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4342 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4343 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4344 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4345 if (Arg.isInvalid())
4346 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004347
Douglas Gregora16548e2009-08-11 05:31:07 +00004348 // FIXME: Wrong source location information for the ','.
4349 FakeCommaLocs.push_back(
4350 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004351
4352 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004353 Args.push_back(Arg.takeAs<Expr>());
4354 }
Mike Stump11289f42009-09-09 15:08:12 +00004355
Douglas Gregora16548e2009-08-11 05:31:07 +00004356 if (!getDerived().AlwaysRebuild() &&
4357 Callee.get() == E->getCallee() &&
4358 !ArgChanged)
4359 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004360
Douglas Gregora16548e2009-08-11 05:31:07 +00004361 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004362 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004363 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4364 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4365 move_arg(Args),
4366 FakeCommaLocs.data(),
4367 E->getRParenLoc());
4368}
Mike Stump11289f42009-09-09 15:08:12 +00004369
4370template<typename Derived>
4371Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004372TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004373 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4374 if (Base.isInvalid())
4375 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004377 NestedNameSpecifier *Qualifier = 0;
4378 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004379 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004380 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004381 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004382 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004383 return SemaRef.ExprError();
4384 }
Mike Stump11289f42009-09-09 15:08:12 +00004385
Eli Friedman2cfcef62009-12-04 06:40:45 +00004386 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004387 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4388 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004389 if (!Member)
4390 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004391
John McCall16df1e52010-03-30 21:47:33 +00004392 NamedDecl *FoundDecl = E->getFoundDecl();
4393 if (FoundDecl == E->getMemberDecl()) {
4394 FoundDecl = Member;
4395 } else {
4396 FoundDecl = cast_or_null<NamedDecl>(
4397 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4398 if (!FoundDecl)
4399 return SemaRef.ExprError();
4400 }
4401
Douglas Gregora16548e2009-08-11 05:31:07 +00004402 if (!getDerived().AlwaysRebuild() &&
4403 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004404 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004405 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004406 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004407 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004408
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004409 // Mark it referenced in the new context regardless.
4410 // FIXME: this is a bit instantiation-specific.
4411 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004412 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004413 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004414
John McCall6b51f282009-11-23 01:53:49 +00004415 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004416 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004417 TransArgs.setLAngleLoc(E->getLAngleLoc());
4418 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004419 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004420 TemplateArgumentLoc Loc;
4421 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004422 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004423 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004424 }
4425 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004426
Douglas Gregora16548e2009-08-11 05:31:07 +00004427 // FIXME: Bogus source location for the operator
4428 SourceLocation FakeOperatorLoc
4429 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4430
John McCall38836f02010-01-15 08:34:02 +00004431 // FIXME: to do this check properly, we will need to preserve the
4432 // first-qualifier-in-scope here, just in case we had a dependent
4433 // base (and therefore couldn't do the check) and a
4434 // nested-name-qualifier (and therefore could do the lookup).
4435 NamedDecl *FirstQualifierInScope = 0;
4436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4438 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004439 Qualifier,
4440 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004441 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004442 Member,
John McCall16df1e52010-03-30 21:47:33 +00004443 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004444 (E->hasExplicitTemplateArgumentList()
4445 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004446 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004447}
Mike Stump11289f42009-09-09 15:08:12 +00004448
Douglas Gregora16548e2009-08-11 05:31:07 +00004449template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004450Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004451TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4453 if (LHS.isInvalid())
4454 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004455
Douglas Gregora16548e2009-08-11 05:31:07 +00004456 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4457 if (RHS.isInvalid())
4458 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004459
Douglas Gregora16548e2009-08-11 05:31:07 +00004460 if (!getDerived().AlwaysRebuild() &&
4461 LHS.get() == E->getLHS() &&
4462 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004463 return SemaRef.Owned(E->Retain());
4464
Douglas Gregora16548e2009-08-11 05:31:07 +00004465 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4466 move(LHS), move(RHS));
4467}
4468
Mike Stump11289f42009-09-09 15:08:12 +00004469template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004470Sema::OwningExprResult
4471TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004472 CompoundAssignOperator *E) {
4473 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004474}
Mike Stump11289f42009-09-09 15:08:12 +00004475
Douglas Gregora16548e2009-08-11 05:31:07 +00004476template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004477Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004478TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004479 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4480 if (Cond.isInvalid())
4481 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004482
Douglas Gregora16548e2009-08-11 05:31:07 +00004483 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4484 if (LHS.isInvalid())
4485 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004486
Douglas Gregora16548e2009-08-11 05:31:07 +00004487 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4488 if (RHS.isInvalid())
4489 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004490
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 if (!getDerived().AlwaysRebuild() &&
4492 Cond.get() == E->getCond() &&
4493 LHS.get() == E->getLHS() &&
4494 RHS.get() == E->getRHS())
4495 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004496
4497 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004498 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004499 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004500 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004501 move(RHS));
4502}
Mike Stump11289f42009-09-09 15:08:12 +00004503
4504template<typename Derived>
4505Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004506TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004507 // Implicit casts are eliminated during transformation, since they
4508 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004509 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004510}
Mike Stump11289f42009-09-09 15:08:12 +00004511
Douglas Gregora16548e2009-08-11 05:31:07 +00004512template<typename Derived>
4513Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004514TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004515 TypeSourceInfo *OldT;
4516 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004517 {
4518 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004519 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004520 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4521 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004522
John McCall97513962010-01-15 18:39:57 +00004523 OldT = E->getTypeInfoAsWritten();
4524 NewT = getDerived().TransformType(OldT);
4525 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 return SemaRef.ExprError();
4527 }
Mike Stump11289f42009-09-09 15:08:12 +00004528
Douglas Gregor6131b442009-12-12 18:16:41 +00004529 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004530 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004531 if (SubExpr.isInvalid())
4532 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004533
Douglas Gregora16548e2009-08-11 05:31:07 +00004534 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004535 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004536 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004537 return SemaRef.Owned(E->Retain());
4538
John McCall97513962010-01-15 18:39:57 +00004539 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4540 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 E->getRParenLoc(),
4542 move(SubExpr));
4543}
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004546Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004547TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004548 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4549 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4550 if (!NewT)
4551 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004552
Douglas Gregora16548e2009-08-11 05:31:07 +00004553 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4554 if (Init.isInvalid())
4555 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004556
Douglas Gregora16548e2009-08-11 05:31:07 +00004557 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004558 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004559 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004560 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004561
John McCall5d7aa7f2010-01-19 22:33:45 +00004562 // Note: the expression type doesn't necessarily match the
4563 // type-as-written, but that's okay, because it should always be
4564 // derivable from the initializer.
4565
John McCalle15bbff2010-01-18 19:35:47 +00004566 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004567 /*FIXME:*/E->getInitializer()->getLocEnd(),
4568 move(Init));
4569}
Mike Stump11289f42009-09-09 15:08:12 +00004570
Douglas Gregora16548e2009-08-11 05:31:07 +00004571template<typename Derived>
4572Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004573TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004574 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4575 if (Base.isInvalid())
4576 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004577
Douglas Gregora16548e2009-08-11 05:31:07 +00004578 if (!getDerived().AlwaysRebuild() &&
4579 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004580 return SemaRef.Owned(E->Retain());
4581
Douglas Gregora16548e2009-08-11 05:31:07 +00004582 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004583 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004584 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4585 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4586 E->getAccessorLoc(),
4587 E->getAccessor());
4588}
Mike Stump11289f42009-09-09 15:08:12 +00004589
Douglas Gregora16548e2009-08-11 05:31:07 +00004590template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004591Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004592TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004593 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004594
Douglas Gregora16548e2009-08-11 05:31:07 +00004595 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4596 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4597 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4598 if (Init.isInvalid())
4599 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601 InitChanged = InitChanged || Init.get() != E->getInit(I);
4602 Inits.push_back(Init.takeAs<Expr>());
4603 }
Mike Stump11289f42009-09-09 15:08:12 +00004604
Douglas Gregora16548e2009-08-11 05:31:07 +00004605 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004606 return SemaRef.Owned(E->Retain());
4607
Douglas Gregora16548e2009-08-11 05:31:07 +00004608 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004609 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004610}
Mike Stump11289f42009-09-09 15:08:12 +00004611
Douglas Gregora16548e2009-08-11 05:31:07 +00004612template<typename Derived>
4613Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004614TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004616
Douglas Gregorebe10102009-08-20 07:17:43 +00004617 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004618 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4619 if (Init.isInvalid())
4620 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004621
Douglas Gregorebe10102009-08-20 07:17:43 +00004622 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4624 bool ExprChanged = false;
4625 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4626 DEnd = E->designators_end();
4627 D != DEnd; ++D) {
4628 if (D->isFieldDesignator()) {
4629 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4630 D->getDotLoc(),
4631 D->getFieldLoc()));
4632 continue;
4633 }
Mike Stump11289f42009-09-09 15:08:12 +00004634
Douglas Gregora16548e2009-08-11 05:31:07 +00004635 if (D->isArrayDesignator()) {
4636 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4637 if (Index.isInvalid())
4638 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004639
4640 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004641 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004642
Douglas Gregora16548e2009-08-11 05:31:07 +00004643 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4644 ArrayExprs.push_back(Index.release());
4645 continue;
4646 }
Mike Stump11289f42009-09-09 15:08:12 +00004647
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004649 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004650 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4651 if (Start.isInvalid())
4652 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004653
Douglas Gregora16548e2009-08-11 05:31:07 +00004654 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4655 if (End.isInvalid())
4656 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
4658 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004659 End.get(),
4660 D->getLBracketLoc(),
4661 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004662
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4664 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004665
Douglas Gregora16548e2009-08-11 05:31:07 +00004666 ArrayExprs.push_back(Start.release());
4667 ArrayExprs.push_back(End.release());
4668 }
Mike Stump11289f42009-09-09 15:08:12 +00004669
Douglas Gregora16548e2009-08-11 05:31:07 +00004670 if (!getDerived().AlwaysRebuild() &&
4671 Init.get() == E->getInit() &&
4672 !ExprChanged)
4673 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004674
Douglas Gregora16548e2009-08-11 05:31:07 +00004675 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4676 E->getEqualOrColonLoc(),
4677 E->usesGNUSyntax(), move(Init));
4678}
Mike Stump11289f42009-09-09 15:08:12 +00004679
Douglas Gregora16548e2009-08-11 05:31:07 +00004680template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004681Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004682TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004683 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004684 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004685
Douglas Gregor3da3c062009-10-28 00:29:27 +00004686 // FIXME: Will we ever have proper type location here? Will we actually
4687 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004688 QualType T = getDerived().TransformType(E->getType());
4689 if (T.isNull())
4690 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004691
Douglas Gregora16548e2009-08-11 05:31:07 +00004692 if (!getDerived().AlwaysRebuild() &&
4693 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004694 return SemaRef.Owned(E->Retain());
4695
Douglas Gregora16548e2009-08-11 05:31:07 +00004696 return getDerived().RebuildImplicitValueInitExpr(T);
4697}
Mike Stump11289f42009-09-09 15:08:12 +00004698
Douglas Gregora16548e2009-08-11 05:31:07 +00004699template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004700Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004701TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004702 // FIXME: Do we want the type as written?
4703 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregora16548e2009-08-11 05:31:07 +00004705 {
4706 // FIXME: Source location isn't quite accurate.
4707 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4708 T = getDerived().TransformType(E->getType());
4709 if (T.isNull())
4710 return SemaRef.ExprError();
4711 }
Mike Stump11289f42009-09-09 15:08:12 +00004712
Douglas Gregora16548e2009-08-11 05:31:07 +00004713 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4714 if (SubExpr.isInvalid())
4715 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004716
Douglas Gregora16548e2009-08-11 05:31:07 +00004717 if (!getDerived().AlwaysRebuild() &&
4718 T == E->getType() &&
4719 SubExpr.get() == E->getSubExpr())
4720 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004721
Douglas Gregora16548e2009-08-11 05:31:07 +00004722 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4723 T, E->getRParenLoc());
4724}
4725
4726template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004727Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004728TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004729 bool ArgumentChanged = false;
4730 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4731 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4732 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4733 if (Init.isInvalid())
4734 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004735
Douglas Gregora16548e2009-08-11 05:31:07 +00004736 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4737 Inits.push_back(Init.takeAs<Expr>());
4738 }
Mike Stump11289f42009-09-09 15:08:12 +00004739
Douglas Gregora16548e2009-08-11 05:31:07 +00004740 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4741 move_arg(Inits),
4742 E->getRParenLoc());
4743}
Mike Stump11289f42009-09-09 15:08:12 +00004744
Douglas Gregora16548e2009-08-11 05:31:07 +00004745/// \brief Transform an address-of-label expression.
4746///
4747/// By default, the transformation of an address-of-label expression always
4748/// rebuilds the expression, so that the label identifier can be resolved to
4749/// the corresponding label statement by semantic analysis.
4750template<typename Derived>
4751Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004752TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004753 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4754 E->getLabel());
4755}
Mike Stump11289f42009-09-09 15:08:12 +00004756
4757template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004758Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004759TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004760 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004761 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4762 if (SubStmt.isInvalid())
4763 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregora16548e2009-08-11 05:31:07 +00004765 if (!getDerived().AlwaysRebuild() &&
4766 SubStmt.get() == E->getSubStmt())
4767 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004768
4769 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004770 move(SubStmt),
4771 E->getRParenLoc());
4772}
Mike Stump11289f42009-09-09 15:08:12 +00004773
Douglas Gregora16548e2009-08-11 05:31:07 +00004774template<typename Derived>
4775Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004776TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 QualType T1, T2;
4778 {
4779 // FIXME: Source location isn't quite accurate.
4780 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004781
Douglas Gregora16548e2009-08-11 05:31:07 +00004782 T1 = getDerived().TransformType(E->getArgType1());
4783 if (T1.isNull())
4784 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004785
Douglas Gregora16548e2009-08-11 05:31:07 +00004786 T2 = getDerived().TransformType(E->getArgType2());
4787 if (T2.isNull())
4788 return SemaRef.ExprError();
4789 }
4790
4791 if (!getDerived().AlwaysRebuild() &&
4792 T1 == E->getArgType1() &&
4793 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004794 return SemaRef.Owned(E->Retain());
4795
Douglas Gregora16548e2009-08-11 05:31:07 +00004796 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4797 T1, T2, E->getRParenLoc());
4798}
Mike Stump11289f42009-09-09 15:08:12 +00004799
Douglas Gregora16548e2009-08-11 05:31:07 +00004800template<typename Derived>
4801Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004802TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004803 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4804 if (Cond.isInvalid())
4805 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004806
Douglas Gregora16548e2009-08-11 05:31:07 +00004807 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4808 if (LHS.isInvalid())
4809 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4812 if (RHS.isInvalid())
4813 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004814
Douglas Gregora16548e2009-08-11 05:31:07 +00004815 if (!getDerived().AlwaysRebuild() &&
4816 Cond.get() == E->getCond() &&
4817 LHS.get() == E->getLHS() &&
4818 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004819 return SemaRef.Owned(E->Retain());
4820
Douglas Gregora16548e2009-08-11 05:31:07 +00004821 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4822 move(Cond), move(LHS), move(RHS),
4823 E->getRParenLoc());
4824}
Mike Stump11289f42009-09-09 15:08:12 +00004825
Douglas Gregora16548e2009-08-11 05:31:07 +00004826template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004827Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004828TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004829 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004830}
4831
4832template<typename Derived>
4833Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004834TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004835 switch (E->getOperator()) {
4836 case OO_New:
4837 case OO_Delete:
4838 case OO_Array_New:
4839 case OO_Array_Delete:
4840 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4841 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004842
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004843 case OO_Call: {
4844 // This is a call to an object's operator().
4845 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4846
4847 // Transform the object itself.
4848 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4849 if (Object.isInvalid())
4850 return SemaRef.ExprError();
4851
4852 // FIXME: Poor location information
4853 SourceLocation FakeLParenLoc
4854 = SemaRef.PP.getLocForEndOfToken(
4855 static_cast<Expr *>(Object.get())->getLocEnd());
4856
4857 // Transform the call arguments.
4858 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4859 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4860 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004861 if (getDerived().DropCallArgument(E->getArg(I)))
4862 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004863
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004864 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4865 if (Arg.isInvalid())
4866 return SemaRef.ExprError();
4867
4868 // FIXME: Poor source location information.
4869 SourceLocation FakeCommaLoc
4870 = SemaRef.PP.getLocForEndOfToken(
4871 static_cast<Expr *>(Arg.get())->getLocEnd());
4872 FakeCommaLocs.push_back(FakeCommaLoc);
4873 Args.push_back(Arg.release());
4874 }
4875
4876 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4877 move_arg(Args),
4878 FakeCommaLocs.data(),
4879 E->getLocEnd());
4880 }
4881
4882#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4883 case OO_##Name:
4884#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4885#include "clang/Basic/OperatorKinds.def"
4886 case OO_Subscript:
4887 // Handled below.
4888 break;
4889
4890 case OO_Conditional:
4891 llvm_unreachable("conditional operator is not actually overloadable");
4892 return SemaRef.ExprError();
4893
4894 case OO_None:
4895 case NUM_OVERLOADED_OPERATORS:
4896 llvm_unreachable("not an overloaded operator?");
4897 return SemaRef.ExprError();
4898 }
4899
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4901 if (Callee.isInvalid())
4902 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004903
John McCall47f29ea2009-12-08 09:21:05 +00004904 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004905 if (First.isInvalid())
4906 return SemaRef.ExprError();
4907
4908 OwningExprResult Second(SemaRef);
4909 if (E->getNumArgs() == 2) {
4910 Second = getDerived().TransformExpr(E->getArg(1));
4911 if (Second.isInvalid())
4912 return SemaRef.ExprError();
4913 }
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregora16548e2009-08-11 05:31:07 +00004915 if (!getDerived().AlwaysRebuild() &&
4916 Callee.get() == E->getCallee() &&
4917 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00004918 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
4919 return SemaRef.Owned(E->Retain());
4920
Douglas Gregora16548e2009-08-11 05:31:07 +00004921 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
4922 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004923 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00004924 move(First),
4925 move(Second));
4926}
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregora16548e2009-08-11 05:31:07 +00004928template<typename Derived>
4929Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004930TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
4931 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004932}
Mike Stump11289f42009-09-09 15:08:12 +00004933
Douglas Gregora16548e2009-08-11 05:31:07 +00004934template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004935Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004936TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004937 TypeSourceInfo *OldT;
4938 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004939 {
4940 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004941 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004942 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4943 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004944
John McCall97513962010-01-15 18:39:57 +00004945 OldT = E->getTypeInfoAsWritten();
4946 NewT = getDerived().TransformType(OldT);
4947 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004948 return SemaRef.ExprError();
4949 }
Mike Stump11289f42009-09-09 15:08:12 +00004950
Douglas Gregor6131b442009-12-12 18:16:41 +00004951 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004952 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004953 if (SubExpr.isInvalid())
4954 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004955
Douglas Gregora16548e2009-08-11 05:31:07 +00004956 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004957 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004958 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004959 return SemaRef.Owned(E->Retain());
4960
Douglas Gregora16548e2009-08-11 05:31:07 +00004961 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00004962 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004963 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
4964 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
4965 SourceLocation FakeRParenLoc
4966 = SemaRef.PP.getLocForEndOfToken(
4967 E->getSubExpr()->getSourceRange().getEnd());
4968 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004969 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004970 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00004971 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004972 FakeRAngleLoc,
4973 FakeRAngleLoc,
4974 move(SubExpr),
4975 FakeRParenLoc);
4976}
Mike Stump11289f42009-09-09 15:08:12 +00004977
Douglas Gregora16548e2009-08-11 05:31:07 +00004978template<typename Derived>
4979Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004980TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
4981 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004982}
Mike Stump11289f42009-09-09 15:08:12 +00004983
4984template<typename Derived>
4985Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004986TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
4987 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00004988}
4989
Douglas Gregora16548e2009-08-11 05:31:07 +00004990template<typename Derived>
4991Sema::OwningExprResult
4992TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004993 CXXReinterpretCastExpr *E) {
4994 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004995}
Mike Stump11289f42009-09-09 15:08:12 +00004996
Douglas Gregora16548e2009-08-11 05:31:07 +00004997template<typename Derived>
4998Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004999TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5000 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005001}
Mike Stump11289f42009-09-09 15:08:12 +00005002
Douglas Gregora16548e2009-08-11 05:31:07 +00005003template<typename Derived>
5004Sema::OwningExprResult
5005TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005006 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005007 TypeSourceInfo *OldT;
5008 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005009 {
5010 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005011
John McCall97513962010-01-15 18:39:57 +00005012 OldT = E->getTypeInfoAsWritten();
5013 NewT = getDerived().TransformType(OldT);
5014 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005015 return SemaRef.ExprError();
5016 }
Mike Stump11289f42009-09-09 15:08:12 +00005017
Douglas Gregor6131b442009-12-12 18:16:41 +00005018 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005019 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005020 if (SubExpr.isInvalid())
5021 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregora16548e2009-08-11 05:31:07 +00005023 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005024 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005025 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005026 return SemaRef.Owned(E->Retain());
5027
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 // FIXME: The end of the type's source range is wrong
5029 return getDerived().RebuildCXXFunctionalCastExpr(
5030 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005031 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005032 /*FIXME:*/E->getSubExpr()->getLocStart(),
5033 move(SubExpr),
5034 E->getRParenLoc());
5035}
Mike Stump11289f42009-09-09 15:08:12 +00005036
Douglas Gregora16548e2009-08-11 05:31:07 +00005037template<typename Derived>
5038Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005039TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005040 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005041 TypeSourceInfo *TInfo
5042 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5043 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005044 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005045
Douglas Gregora16548e2009-08-11 05:31:07 +00005046 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005047 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005048 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005049
Douglas Gregor9da64192010-04-26 22:37:10 +00005050 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5051 E->getLocStart(),
5052 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005053 E->getLocEnd());
5054 }
Mike Stump11289f42009-09-09 15:08:12 +00005055
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 // We don't know whether the expression is potentially evaluated until
5057 // after we perform semantic analysis, so the expression is potentially
5058 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005059 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005060 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005061
Douglas Gregora16548e2009-08-11 05:31:07 +00005062 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5063 if (SubExpr.isInvalid())
5064 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005065
Douglas Gregora16548e2009-08-11 05:31:07 +00005066 if (!getDerived().AlwaysRebuild() &&
5067 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005068 return SemaRef.Owned(E->Retain());
5069
Douglas Gregor9da64192010-04-26 22:37:10 +00005070 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5071 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005072 move(SubExpr),
5073 E->getLocEnd());
5074}
5075
5076template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005077Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005078TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005079 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005080}
Mike Stump11289f42009-09-09 15:08:12 +00005081
Douglas Gregora16548e2009-08-11 05:31:07 +00005082template<typename Derived>
5083Sema::OwningExprResult
5084TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005085 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005086 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005087}
Mike Stump11289f42009-09-09 15:08:12 +00005088
Douglas Gregora16548e2009-08-11 05:31:07 +00005089template<typename Derived>
5090Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005091TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005092 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094 QualType T = getDerived().TransformType(E->getType());
5095 if (T.isNull())
5096 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005097
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 if (!getDerived().AlwaysRebuild() &&
5099 T == E->getType())
5100 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005101
Douglas Gregorb15af892010-01-07 23:12:05 +00005102 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005103}
Mike Stump11289f42009-09-09 15:08:12 +00005104
Douglas Gregora16548e2009-08-11 05:31:07 +00005105template<typename Derived>
5106Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005107TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005108 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5109 if (SubExpr.isInvalid())
5110 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112 if (!getDerived().AlwaysRebuild() &&
5113 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005114 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005115
5116 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5117}
Mike Stump11289f42009-09-09 15:08:12 +00005118
Douglas Gregora16548e2009-08-11 05:31:07 +00005119template<typename Derived>
5120Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005121TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005122 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005123 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5124 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005125 if (!Param)
5126 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005127
Chandler Carruth794da4c2010-02-08 06:42:49 +00005128 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 Param == E->getParam())
5130 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregor033f6752009-12-23 23:03:06 +00005132 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005133}
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135template<typename Derived>
5136Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005137TreeTransform<Derived>::TransformCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005138 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5139
5140 QualType T = getDerived().TransformType(E->getType());
5141 if (T.isNull())
5142 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005143
Douglas Gregora16548e2009-08-11 05:31:07 +00005144 if (!getDerived().AlwaysRebuild() &&
5145 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005146 return SemaRef.Owned(E->Retain());
5147
5148 return getDerived().RebuildCXXZeroInitValueExpr(E->getTypeBeginLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 /*FIXME:*/E->getTypeBeginLoc(),
5150 T,
5151 E->getRParenLoc());
5152}
Mike Stump11289f42009-09-09 15:08:12 +00005153
Douglas Gregora16548e2009-08-11 05:31:07 +00005154template<typename Derived>
5155Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005156TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005157 // Transform the type that we're allocating
5158 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5159 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5160 if (AllocType.isNull())
5161 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005162
Douglas Gregora16548e2009-08-11 05:31:07 +00005163 // Transform the size of the array we're allocating (if any).
5164 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5165 if (ArraySize.isInvalid())
5166 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005167
Douglas Gregora16548e2009-08-11 05:31:07 +00005168 // Transform the placement arguments (if any).
5169 bool ArgumentChanged = false;
5170 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5171 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5172 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5173 if (Arg.isInvalid())
5174 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005175
Douglas Gregora16548e2009-08-11 05:31:07 +00005176 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5177 PlacementArgs.push_back(Arg.take());
5178 }
Mike Stump11289f42009-09-09 15:08:12 +00005179
Douglas Gregorebe10102009-08-20 07:17:43 +00005180 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5182 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
5183 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5184 if (Arg.isInvalid())
5185 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5188 ConstructorArgs.push_back(Arg.take());
5189 }
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregord2d9da02010-02-26 00:38:10 +00005191 // Transform constructor, new operator, and delete operator.
5192 CXXConstructorDecl *Constructor = 0;
5193 if (E->getConstructor()) {
5194 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005195 getDerived().TransformDecl(E->getLocStart(),
5196 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005197 if (!Constructor)
5198 return SemaRef.ExprError();
5199 }
5200
5201 FunctionDecl *OperatorNew = 0;
5202 if (E->getOperatorNew()) {
5203 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005204 getDerived().TransformDecl(E->getLocStart(),
5205 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005206 if (!OperatorNew)
5207 return SemaRef.ExprError();
5208 }
5209
5210 FunctionDecl *OperatorDelete = 0;
5211 if (E->getOperatorDelete()) {
5212 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005213 getDerived().TransformDecl(E->getLocStart(),
5214 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005215 if (!OperatorDelete)
5216 return SemaRef.ExprError();
5217 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005218
Douglas Gregora16548e2009-08-11 05:31:07 +00005219 if (!getDerived().AlwaysRebuild() &&
5220 AllocType == E->getAllocatedType() &&
5221 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005222 Constructor == E->getConstructor() &&
5223 OperatorNew == E->getOperatorNew() &&
5224 OperatorDelete == E->getOperatorDelete() &&
5225 !ArgumentChanged) {
5226 // Mark any declarations we need as referenced.
5227 // FIXME: instantiation-specific.
5228 if (Constructor)
5229 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5230 if (OperatorNew)
5231 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5232 if (OperatorDelete)
5233 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005234 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005235 }
Mike Stump11289f42009-09-09 15:08:12 +00005236
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005237 if (!ArraySize.get()) {
5238 // If no array size was specified, but the new expression was
5239 // instantiated with an array type (e.g., "new T" where T is
5240 // instantiated with "int[4]"), extract the outer bound from the
5241 // array type as our array size. We do this with constant and
5242 // dependently-sized array types.
5243 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5244 if (!ArrayT) {
5245 // Do nothing
5246 } else if (const ConstantArrayType *ConsArrayT
5247 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005248 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005249 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005250 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005251 SemaRef.Context.getSizeType(),
5252 /*FIXME:*/E->getLocStart()));
5253 AllocType = ConsArrayT->getElementType();
5254 } else if (const DependentSizedArrayType *DepArrayT
5255 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5256 if (DepArrayT->getSizeExpr()) {
5257 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5258 AllocType = DepArrayT->getElementType();
5259 }
5260 }
5261 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005262 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5263 E->isGlobalNew(),
5264 /*FIXME:*/E->getLocStart(),
5265 move_arg(PlacementArgs),
5266 /*FIXME:*/E->getLocStart(),
5267 E->isParenTypeId(),
5268 AllocType,
5269 /*FIXME:*/E->getLocStart(),
5270 /*FIXME:*/SourceRange(),
5271 move(ArraySize),
5272 /*FIXME:*/E->getLocStart(),
5273 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005274 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005275}
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregora16548e2009-08-11 05:31:07 +00005277template<typename Derived>
5278Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005279TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005280 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5281 if (Operand.isInvalid())
5282 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005283
Douglas Gregord2d9da02010-02-26 00:38:10 +00005284 // Transform the delete operator, if known.
5285 FunctionDecl *OperatorDelete = 0;
5286 if (E->getOperatorDelete()) {
5287 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005288 getDerived().TransformDecl(E->getLocStart(),
5289 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005290 if (!OperatorDelete)
5291 return SemaRef.ExprError();
5292 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
Douglas Gregora16548e2009-08-11 05:31:07 +00005294 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005295 Operand.get() == E->getArgument() &&
5296 OperatorDelete == E->getOperatorDelete()) {
5297 // Mark any declarations we need as referenced.
5298 // FIXME: instantiation-specific.
5299 if (OperatorDelete)
5300 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005301 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005302 }
Mike Stump11289f42009-09-09 15:08:12 +00005303
Douglas Gregora16548e2009-08-11 05:31:07 +00005304 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5305 E->isGlobalDelete(),
5306 E->isArrayForm(),
5307 move(Operand));
5308}
Mike Stump11289f42009-09-09 15:08:12 +00005309
Douglas Gregora16548e2009-08-11 05:31:07 +00005310template<typename Derived>
5311Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005312TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005313 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005314 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5315 if (Base.isInvalid())
5316 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005317
Douglas Gregor678f90d2010-02-25 01:56:36 +00005318 Sema::TypeTy *ObjectTypePtr = 0;
5319 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005320 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005321 E->getOperatorLoc(),
5322 E->isArrow()? tok::arrow : tok::period,
5323 ObjectTypePtr,
5324 MayBePseudoDestructor);
5325 if (Base.isInvalid())
5326 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005327
Douglas Gregor678f90d2010-02-25 01:56:36 +00005328 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005329 NestedNameSpecifier *Qualifier
5330 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005331 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005332 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005333 if (E->getQualifier() && !Qualifier)
5334 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005335
Douglas Gregor678f90d2010-02-25 01:56:36 +00005336 PseudoDestructorTypeStorage Destroyed;
5337 if (E->getDestroyedTypeInfo()) {
5338 TypeSourceInfo *DestroyedTypeInfo
5339 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5340 if (!DestroyedTypeInfo)
5341 return SemaRef.ExprError();
5342 Destroyed = DestroyedTypeInfo;
5343 } else if (ObjectType->isDependentType()) {
5344 // We aren't likely to be able to resolve the identifier down to a type
5345 // now anyway, so just retain the identifier.
5346 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5347 E->getDestroyedTypeLoc());
5348 } else {
5349 // Look for a destructor known with the given name.
5350 CXXScopeSpec SS;
5351 if (Qualifier) {
5352 SS.setScopeRep(Qualifier);
5353 SS.setRange(E->getQualifierRange());
5354 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005355
Douglas Gregor678f90d2010-02-25 01:56:36 +00005356 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5357 *E->getDestroyedTypeIdentifier(),
5358 E->getDestroyedTypeLoc(),
5359 /*Scope=*/0,
5360 SS, ObjectTypePtr,
5361 false);
5362 if (!T)
5363 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005364
Douglas Gregor678f90d2010-02-25 01:56:36 +00005365 Destroyed
5366 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5367 E->getDestroyedTypeLoc());
5368 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005369
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005370 TypeSourceInfo *ScopeTypeInfo = 0;
5371 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005372 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005373 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005374 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005375 return SemaRef.ExprError();
5376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005377
Douglas Gregorad8a3362009-09-04 17:36:40 +00005378 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5379 E->getOperatorLoc(),
5380 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005381 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005382 E->getQualifierRange(),
5383 ScopeTypeInfo,
5384 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005385 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005386 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005387}
Mike Stump11289f42009-09-09 15:08:12 +00005388
Douglas Gregorad8a3362009-09-04 17:36:40 +00005389template<typename Derived>
5390Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005391TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005392 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005393 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5394
5395 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5396 Sema::LookupOrdinaryName);
5397
5398 // Transform all the decls.
5399 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5400 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005401 NamedDecl *InstD = static_cast<NamedDecl*>(
5402 getDerived().TransformDecl(Old->getNameLoc(),
5403 *I));
John McCall84d87672009-12-10 09:41:52 +00005404 if (!InstD) {
5405 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5406 // This can happen because of dependent hiding.
5407 if (isa<UsingShadowDecl>(*I))
5408 continue;
5409 else
5410 return SemaRef.ExprError();
5411 }
John McCalle66edc12009-11-24 19:00:30 +00005412
5413 // Expand using declarations.
5414 if (isa<UsingDecl>(InstD)) {
5415 UsingDecl *UD = cast<UsingDecl>(InstD);
5416 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5417 E = UD->shadow_end(); I != E; ++I)
5418 R.addDecl(*I);
5419 continue;
5420 }
5421
5422 R.addDecl(InstD);
5423 }
5424
5425 // Resolve a kind, but don't do any further analysis. If it's
5426 // ambiguous, the callee needs to deal with it.
5427 R.resolveKind();
5428
5429 // Rebuild the nested-name qualifier, if present.
5430 CXXScopeSpec SS;
5431 NestedNameSpecifier *Qualifier = 0;
5432 if (Old->getQualifier()) {
5433 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005434 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005435 if (!Qualifier)
5436 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005437
John McCalle66edc12009-11-24 19:00:30 +00005438 SS.setScopeRep(Qualifier);
5439 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005440 }
5441
Douglas Gregor9262f472010-04-27 18:19:34 +00005442 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005443 CXXRecordDecl *NamingClass
5444 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5445 Old->getNameLoc(),
5446 Old->getNamingClass()));
5447 if (!NamingClass)
5448 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005449
Douglas Gregorda7be082010-04-27 16:10:10 +00005450 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005451 }
5452
5453 // If we have no template arguments, it's a normal declaration name.
5454 if (!Old->hasExplicitTemplateArgs())
5455 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5456
5457 // If we have template arguments, rebuild them, then rebuild the
5458 // templateid expression.
5459 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5460 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5461 TemplateArgumentLoc Loc;
5462 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5463 return SemaRef.ExprError();
5464 TransArgs.addArgument(Loc);
5465 }
5466
5467 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5468 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005469}
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregora16548e2009-08-11 05:31:07 +00005471template<typename Derived>
5472Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005473TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005475
Douglas Gregora16548e2009-08-11 05:31:07 +00005476 QualType T = getDerived().TransformType(E->getQueriedType());
5477 if (T.isNull())
5478 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005479
Douglas Gregora16548e2009-08-11 05:31:07 +00005480 if (!getDerived().AlwaysRebuild() &&
5481 T == E->getQueriedType())
5482 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005483
Douglas Gregora16548e2009-08-11 05:31:07 +00005484 // FIXME: Bad location information
5485 SourceLocation FakeLParenLoc
5486 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005487
5488 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005489 E->getLocStart(),
5490 /*FIXME:*/FakeLParenLoc,
5491 T,
5492 E->getLocEnd());
5493}
Mike Stump11289f42009-09-09 15:08:12 +00005494
Douglas Gregora16548e2009-08-11 05:31:07 +00005495template<typename Derived>
5496Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005497TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005498 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005499 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005500 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005501 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005502 if (!NNS)
5503 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005504
5505 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005506 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5507 if (!Name)
5508 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005509
John McCalle66edc12009-11-24 19:00:30 +00005510 if (!E->hasExplicitTemplateArgs()) {
5511 if (!getDerived().AlwaysRebuild() &&
5512 NNS == E->getQualifier() &&
5513 Name == E->getDeclName())
5514 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005515
John McCalle66edc12009-11-24 19:00:30 +00005516 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5517 E->getQualifierRange(),
5518 Name, E->getLocation(),
5519 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005520 }
John McCall6b51f282009-11-23 01:53:49 +00005521
5522 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005523 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005524 TemplateArgumentLoc Loc;
5525 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005526 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005527 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005528 }
5529
John McCalle66edc12009-11-24 19:00:30 +00005530 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5531 E->getQualifierRange(),
5532 Name, E->getLocation(),
5533 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005534}
5535
5536template<typename Derived>
5537Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005538TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005539 // CXXConstructExprs are always implicit, so when we have a
5540 // 1-argument construction we just transform that argument.
5541 if (E->getNumArgs() == 1 ||
5542 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5543 return getDerived().TransformExpr(E->getArg(0));
5544
Douglas Gregora16548e2009-08-11 05:31:07 +00005545 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5546
5547 QualType T = getDerived().TransformType(E->getType());
5548 if (T.isNull())
5549 return SemaRef.ExprError();
5550
5551 CXXConstructorDecl *Constructor
5552 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005553 getDerived().TransformDecl(E->getLocStart(),
5554 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005555 if (!Constructor)
5556 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005557
Douglas Gregora16548e2009-08-11 05:31:07 +00005558 bool ArgumentChanged = false;
5559 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005560 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005561 ArgEnd = E->arg_end();
5562 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005563 if (getDerived().DropCallArgument(*Arg)) {
5564 ArgumentChanged = true;
5565 break;
5566 }
5567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5569 if (TransArg.isInvalid())
5570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5573 Args.push_back(TransArg.takeAs<Expr>());
5574 }
5575
5576 if (!getDerived().AlwaysRebuild() &&
5577 T == E->getType() &&
5578 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005579 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005580 // Mark the constructor as referenced.
5581 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005582 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005583 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005584 }
Mike Stump11289f42009-09-09 15:08:12 +00005585
Douglas Gregordb121ba2009-12-14 16:27:04 +00005586 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5587 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 move_arg(Args));
5589}
Mike Stump11289f42009-09-09 15:08:12 +00005590
Douglas Gregora16548e2009-08-11 05:31:07 +00005591/// \brief Transform a C++ temporary-binding expression.
5592///
Douglas Gregor363b1512009-12-24 18:51:59 +00005593/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5594/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005595template<typename Derived>
5596Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005597TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005598 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005599}
Mike Stump11289f42009-09-09 15:08:12 +00005600
Anders Carlssonba6c4372010-01-29 02:39:32 +00005601/// \brief Transform a C++ reference-binding expression.
5602///
5603/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5604/// transform the subexpression and return that.
5605template<typename Derived>
5606Sema::OwningExprResult
5607TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5608 return getDerived().TransformExpr(E->getSubExpr());
5609}
5610
Mike Stump11289f42009-09-09 15:08:12 +00005611/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005612/// be destroyed after the expression is evaluated.
5613///
Douglas Gregor363b1512009-12-24 18:51:59 +00005614/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5615/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005616template<typename Derived>
5617Sema::OwningExprResult
5618TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005619 CXXExprWithTemporaries *E) {
5620 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005621}
Mike Stump11289f42009-09-09 15:08:12 +00005622
Douglas Gregora16548e2009-08-11 05:31:07 +00005623template<typename Derived>
5624Sema::OwningExprResult
5625TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005626 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005627 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5628 QualType T = getDerived().TransformType(E->getType());
5629 if (T.isNull())
5630 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005631
Douglas Gregora16548e2009-08-11 05:31:07 +00005632 CXXConstructorDecl *Constructor
5633 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005634 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005635 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 if (!Constructor)
5637 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005638
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 bool ArgumentChanged = false;
5640 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5641 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005642 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005643 ArgEnd = E->arg_end();
5644 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005645 if (getDerived().DropCallArgument(*Arg)) {
5646 ArgumentChanged = true;
5647 break;
5648 }
5649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5651 if (TransArg.isInvalid())
5652 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005653
Douglas Gregora16548e2009-08-11 05:31:07 +00005654 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5655 Args.push_back((Expr *)TransArg.release());
5656 }
Mike Stump11289f42009-09-09 15:08:12 +00005657
Douglas Gregora16548e2009-08-11 05:31:07 +00005658 if (!getDerived().AlwaysRebuild() &&
5659 T == E->getType() &&
5660 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005661 !ArgumentChanged) {
5662 // FIXME: Instantiation-specific
5663 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005664 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005665 }
Mike Stump11289f42009-09-09 15:08:12 +00005666
Douglas Gregora16548e2009-08-11 05:31:07 +00005667 // FIXME: Bogus location information
5668 SourceLocation CommaLoc;
5669 if (Args.size() > 1) {
5670 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005671 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005672 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5673 }
5674 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5675 T,
5676 /*FIXME:*/E->getTypeBeginLoc(),
5677 move_arg(Args),
5678 &CommaLoc,
5679 E->getLocEnd());
5680}
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregora16548e2009-08-11 05:31:07 +00005682template<typename Derived>
5683Sema::OwningExprResult
5684TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005685 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005686 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5687 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5688 if (T.isNull())
5689 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregora16548e2009-08-11 05:31:07 +00005691 bool ArgumentChanged = false;
5692 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5693 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5694 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5695 ArgEnd = E->arg_end();
5696 Arg != ArgEnd; ++Arg) {
5697 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5698 if (TransArg.isInvalid())
5699 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005700
Douglas Gregora16548e2009-08-11 05:31:07 +00005701 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5702 FakeCommaLocs.push_back(
5703 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5704 Args.push_back(TransArg.takeAs<Expr>());
5705 }
Mike Stump11289f42009-09-09 15:08:12 +00005706
Douglas Gregora16548e2009-08-11 05:31:07 +00005707 if (!getDerived().AlwaysRebuild() &&
5708 T == E->getTypeAsWritten() &&
5709 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005710 return SemaRef.Owned(E->Retain());
5711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 // FIXME: we're faking the locations of the commas
5713 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5714 T,
5715 E->getLParenLoc(),
5716 move_arg(Args),
5717 FakeCommaLocs.data(),
5718 E->getRParenLoc());
5719}
Mike Stump11289f42009-09-09 15:08:12 +00005720
Douglas Gregora16548e2009-08-11 05:31:07 +00005721template<typename Derived>
5722Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005723TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005724 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005725 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005726 OwningExprResult Base(SemaRef, (Expr*) 0);
5727 Expr *OldBase;
5728 QualType BaseType;
5729 QualType ObjectType;
5730 if (!E->isImplicitAccess()) {
5731 OldBase = E->getBase();
5732 Base = getDerived().TransformExpr(OldBase);
5733 if (Base.isInvalid())
5734 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005735
John McCall2d74de92009-12-01 22:10:20 +00005736 // Start the member reference and compute the object's type.
5737 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005738 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005739 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5740 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005741 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005742 ObjectTy,
5743 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005744 if (Base.isInvalid())
5745 return SemaRef.ExprError();
5746
5747 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5748 BaseType = ((Expr*) Base.get())->getType();
5749 } else {
5750 OldBase = 0;
5751 BaseType = getDerived().TransformType(E->getBaseType());
5752 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5753 }
Mike Stump11289f42009-09-09 15:08:12 +00005754
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005755 // Transform the first part of the nested-name-specifier that qualifies
5756 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005757 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005758 = getDerived().TransformFirstQualifierInScope(
5759 E->getFirstQualifierFoundInScope(),
5760 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005761
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005762 NestedNameSpecifier *Qualifier = 0;
5763 if (E->getQualifier()) {
5764 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5765 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005766 ObjectType,
5767 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005768 if (!Qualifier)
5769 return SemaRef.ExprError();
5770 }
Mike Stump11289f42009-09-09 15:08:12 +00005771
5772 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005773 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005774 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005775 if (!Name)
5776 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005777
John McCall2d74de92009-12-01 22:10:20 +00005778 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005779 // This is a reference to a member without an explicitly-specified
5780 // template argument list. Optimize for this common case.
5781 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005782 Base.get() == OldBase &&
5783 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005784 Qualifier == E->getQualifier() &&
5785 Name == E->getMember() &&
5786 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005787 return SemaRef.Owned(E->Retain());
5788
John McCall8cd78132009-11-19 22:55:06 +00005789 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005790 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005791 E->isArrow(),
5792 E->getOperatorLoc(),
5793 Qualifier,
5794 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005795 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005796 Name,
5797 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005798 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005799 }
5800
John McCall6b51f282009-11-23 01:53:49 +00005801 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005802 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005803 TemplateArgumentLoc Loc;
5804 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005805 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005806 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005807 }
Mike Stump11289f42009-09-09 15:08:12 +00005808
John McCall8cd78132009-11-19 22:55:06 +00005809 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005810 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005811 E->isArrow(),
5812 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005813 Qualifier,
5814 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005815 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005816 Name,
5817 E->getMemberLoc(),
5818 &TransArgs);
5819}
5820
5821template<typename Derived>
5822Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005823TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005824 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005825 OwningExprResult Base(SemaRef, (Expr*) 0);
5826 QualType BaseType;
5827 if (!Old->isImplicitAccess()) {
5828 Base = getDerived().TransformExpr(Old->getBase());
5829 if (Base.isInvalid())
5830 return SemaRef.ExprError();
5831 BaseType = ((Expr*) Base.get())->getType();
5832 } else {
5833 BaseType = getDerived().TransformType(Old->getBaseType());
5834 }
John McCall10eae182009-11-30 22:42:35 +00005835
5836 NestedNameSpecifier *Qualifier = 0;
5837 if (Old->getQualifier()) {
5838 Qualifier
5839 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005840 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005841 if (Qualifier == 0)
5842 return SemaRef.ExprError();
5843 }
5844
5845 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5846 Sema::LookupOrdinaryName);
5847
5848 // Transform all the decls.
5849 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5850 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005851 NamedDecl *InstD = static_cast<NamedDecl*>(
5852 getDerived().TransformDecl(Old->getMemberLoc(),
5853 *I));
John McCall84d87672009-12-10 09:41:52 +00005854 if (!InstD) {
5855 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5856 // This can happen because of dependent hiding.
5857 if (isa<UsingShadowDecl>(*I))
5858 continue;
5859 else
5860 return SemaRef.ExprError();
5861 }
John McCall10eae182009-11-30 22:42:35 +00005862
5863 // Expand using declarations.
5864 if (isa<UsingDecl>(InstD)) {
5865 UsingDecl *UD = cast<UsingDecl>(InstD);
5866 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5867 E = UD->shadow_end(); I != E; ++I)
5868 R.addDecl(*I);
5869 continue;
5870 }
5871
5872 R.addDecl(InstD);
5873 }
5874
5875 R.resolveKind();
5876
Douglas Gregor9262f472010-04-27 18:19:34 +00005877 // Determine the naming class.
5878 if (!Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005879 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005880 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005881 Old->getMemberLoc(),
5882 Old->getNamingClass()));
5883 if (!NamingClass)
5884 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005885
Douglas Gregorda7be082010-04-27 16:10:10 +00005886 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005887 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005888
John McCall10eae182009-11-30 22:42:35 +00005889 TemplateArgumentListInfo TransArgs;
5890 if (Old->hasExplicitTemplateArgs()) {
5891 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5892 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5893 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5894 TemplateArgumentLoc Loc;
5895 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5896 Loc))
5897 return SemaRef.ExprError();
5898 TransArgs.addArgument(Loc);
5899 }
5900 }
John McCall38836f02010-01-15 08:34:02 +00005901
5902 // FIXME: to do this check properly, we will need to preserve the
5903 // first-qualifier-in-scope here, just in case we had a dependent
5904 // base (and therefore couldn't do the check) and a
5905 // nested-name-qualifier (and therefore could do the lookup).
5906 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005907
John McCall10eae182009-11-30 22:42:35 +00005908 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005909 BaseType,
John McCall10eae182009-11-30 22:42:35 +00005910 Old->getOperatorLoc(),
5911 Old->isArrow(),
5912 Qualifier,
5913 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00005914 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005915 R,
5916 (Old->hasExplicitTemplateArgs()
5917 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005918}
5919
5920template<typename Derived>
5921Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005923 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005924}
5925
Mike Stump11289f42009-09-09 15:08:12 +00005926template<typename Derived>
5927Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005928TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00005929 TypeSourceInfo *EncodedTypeInfo
5930 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
5931 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005932 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005933
Douglas Gregora16548e2009-08-11 05:31:07 +00005934 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00005935 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00005936 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005937
5938 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00005939 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 E->getRParenLoc());
5941}
Mike Stump11289f42009-09-09 15:08:12 +00005942
Douglas Gregora16548e2009-08-11 05:31:07 +00005943template<typename Derived>
5944Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005945TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005946 // Transform arguments.
5947 bool ArgChanged = false;
5948 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5949 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
5950 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
5951 if (Arg.isInvalid())
5952 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005953
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005954 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
5955 Args.push_back(Arg.takeAs<Expr>());
5956 }
5957
5958 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
5959 // Class message: transform the receiver type.
5960 TypeSourceInfo *ReceiverTypeInfo
5961 = getDerived().TransformType(E->getClassReceiverTypeInfo());
5962 if (!ReceiverTypeInfo)
5963 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005964
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005965 // If nothing changed, just retain the existing message send.
5966 if (!getDerived().AlwaysRebuild() &&
5967 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
5968 return SemaRef.Owned(E->Retain());
5969
5970 // Build a new class message send.
5971 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
5972 E->getSelector(),
5973 E->getMethodDecl(),
5974 E->getLeftLoc(),
5975 move_arg(Args),
5976 E->getRightLoc());
5977 }
5978
5979 // Instance message: transform the receiver
5980 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
5981 "Only class and instance messages may be instantiated");
5982 OwningExprResult Receiver
5983 = getDerived().TransformExpr(E->getInstanceReceiver());
5984 if (Receiver.isInvalid())
5985 return SemaRef.ExprError();
5986
5987 // If nothing changed, just retain the existing message send.
5988 if (!getDerived().AlwaysRebuild() &&
5989 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
5990 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005991
Douglas Gregorc298ffc2010-04-22 16:44:27 +00005992 // Build a new instance message send.
5993 return getDerived().RebuildObjCMessageExpr(move(Receiver),
5994 E->getSelector(),
5995 E->getMethodDecl(),
5996 E->getLeftLoc(),
5997 move_arg(Args),
5998 E->getRightLoc());
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>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006004 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006005}
6006
Mike Stump11289f42009-09-09 15:08:12 +00006007template<typename Derived>
6008Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006010 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006011}
6012
Mike Stump11289f42009-09-09 15:08:12 +00006013template<typename Derived>
6014Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006015TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006016 // Transform the base expression.
6017 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6018 if (Base.isInvalid())
6019 return SemaRef.ExprError();
6020
6021 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006022
Douglas Gregord51d90d2010-04-26 20:11:03 +00006023 // If nothing changed, just retain the existing expression.
6024 if (!getDerived().AlwaysRebuild() &&
6025 Base.get() == E->getBase())
6026 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006027
Douglas Gregord51d90d2010-04-26 20:11:03 +00006028 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6029 E->getLocation(),
6030 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006031}
6032
Mike Stump11289f42009-09-09 15:08:12 +00006033template<typename Derived>
6034Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006035TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006036 // Transform the base expression.
6037 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6038 if (Base.isInvalid())
6039 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006040
Douglas Gregor9faee212010-04-26 20:47:02 +00006041 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006042
Douglas Gregor9faee212010-04-26 20:47:02 +00006043 // If nothing changed, just retain the existing expression.
6044 if (!getDerived().AlwaysRebuild() &&
6045 Base.get() == E->getBase())
6046 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006047
Douglas Gregor9faee212010-04-26 20:47:02 +00006048 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6049 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006050}
6051
Mike Stump11289f42009-09-09 15:08:12 +00006052template<typename Derived>
6053Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006054TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006055 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006056 // If this implicit setter/getter refers to class methods, it cannot have any
6057 // dependent parts. Just retain the existing declaration.
6058 if (E->getInterfaceDecl())
6059 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006060
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006061 // Transform the base expression.
6062 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6063 if (Base.isInvalid())
6064 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006065
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006066 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006067
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006068 // If nothing changed, just retain the existing expression.
6069 if (!getDerived().AlwaysRebuild() &&
6070 Base.get() == E->getBase())
6071 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006072
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006073 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6074 E->getGetterMethod(),
6075 E->getType(),
6076 E->getSetterMethod(),
6077 E->getLocation(),
6078 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006079
Douglas Gregora16548e2009-08-11 05:31:07 +00006080}
6081
Mike Stump11289f42009-09-09 15:08:12 +00006082template<typename Derived>
6083Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006084TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006085 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006086 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006087}
6088
Mike Stump11289f42009-09-09 15:08:12 +00006089template<typename Derived>
6090Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006091TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006092 // Transform the base expression.
6093 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6094 if (Base.isInvalid())
6095 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006096
Douglas Gregord51d90d2010-04-26 20:11:03 +00006097 // If nothing changed, just retain the existing expression.
6098 if (!getDerived().AlwaysRebuild() &&
6099 Base.get() == E->getBase())
6100 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006101
Douglas Gregord51d90d2010-04-26 20:11:03 +00006102 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6103 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006104}
6105
Mike Stump11289f42009-09-09 15:08:12 +00006106template<typename Derived>
6107Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006108TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006109 bool ArgumentChanged = false;
6110 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6111 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6112 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6113 if (SubExpr.isInvalid())
6114 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006115
Douglas Gregora16548e2009-08-11 05:31:07 +00006116 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6117 SubExprs.push_back(SubExpr.takeAs<Expr>());
6118 }
Mike Stump11289f42009-09-09 15:08:12 +00006119
Douglas Gregora16548e2009-08-11 05:31:07 +00006120 if (!getDerived().AlwaysRebuild() &&
6121 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006122 return SemaRef.Owned(E->Retain());
6123
Douglas Gregora16548e2009-08-11 05:31:07 +00006124 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6125 move_arg(SubExprs),
6126 E->getRParenLoc());
6127}
6128
Mike Stump11289f42009-09-09 15:08:12 +00006129template<typename Derived>
6130Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006131TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006132 // FIXME: Implement this!
6133 assert(false && "Cannot transform block expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006134 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006135}
6136
Mike Stump11289f42009-09-09 15:08:12 +00006137template<typename Derived>
6138Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006139TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006140 // FIXME: Implement this!
6141 assert(false && "Cannot transform block-related expressions yet");
Mike Stump11289f42009-09-09 15:08:12 +00006142 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006143}
Mike Stump11289f42009-09-09 15:08:12 +00006144
Douglas Gregora16548e2009-08-11 05:31:07 +00006145//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006146// Type reconstruction
6147//===----------------------------------------------------------------------===//
6148
Mike Stump11289f42009-09-09 15:08:12 +00006149template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006150QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6151 SourceLocation Star) {
6152 return SemaRef.BuildPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006153 getDerived().getBaseEntity());
6154}
6155
Mike Stump11289f42009-09-09 15:08:12 +00006156template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006157QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6158 SourceLocation Star) {
6159 return SemaRef.BuildBlockPointerType(PointeeType, Qualifiers(), Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006160 getDerived().getBaseEntity());
6161}
6162
Mike Stump11289f42009-09-09 15:08:12 +00006163template<typename Derived>
6164QualType
John McCall70dd5f62009-10-30 00:06:24 +00006165TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6166 bool WrittenAsLValue,
6167 SourceLocation Sigil) {
6168 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, Qualifiers(),
6169 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006170}
6171
6172template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006173QualType
John McCall70dd5f62009-10-30 00:06:24 +00006174TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6175 QualType ClassType,
6176 SourceLocation Sigil) {
John McCall8ccfcb52009-09-24 19:53:00 +00006177 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Qualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00006178 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006179}
6180
6181template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006182QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006183TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6184 ArrayType::ArraySizeModifier SizeMod,
6185 const llvm::APInt *Size,
6186 Expr *SizeExpr,
6187 unsigned IndexTypeQuals,
6188 SourceRange BracketsRange) {
6189 if (SizeExpr || !Size)
6190 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6191 IndexTypeQuals, BracketsRange,
6192 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006193
6194 QualType Types[] = {
6195 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6196 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6197 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006198 };
6199 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6200 QualType SizeType;
6201 for (unsigned I = 0; I != NumTypes; ++I)
6202 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6203 SizeType = Types[I];
6204 break;
6205 }
Mike Stump11289f42009-09-09 15:08:12 +00006206
Douglas Gregord6ff3322009-08-04 16:50:30 +00006207 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006208 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006209 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006210 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006211}
Mike Stump11289f42009-09-09 15:08:12 +00006212
Douglas Gregord6ff3322009-08-04 16:50:30 +00006213template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006214QualType
6215TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006216 ArrayType::ArraySizeModifier SizeMod,
6217 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006218 unsigned IndexTypeQuals,
6219 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006220 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006221 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006222}
6223
6224template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006225QualType
Mike Stump11289f42009-09-09 15:08:12 +00006226TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006227 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006228 unsigned IndexTypeQuals,
6229 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006230 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006231 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006232}
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregord6ff3322009-08-04 16:50:30 +00006234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006235QualType
6236TreeTransform<Derived>::RebuildVariableArrayType(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>
Mike Stump11289f42009-09-09 15:08:12 +00006247QualType
6248TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006249 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006250 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006251 unsigned IndexTypeQuals,
6252 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006253 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006254 SizeExpr.takeAs<Expr>(),
6255 IndexTypeQuals, BracketsRange);
6256}
6257
6258template<typename Derived>
6259QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
John Thompson22334602010-02-05 00:12:22 +00006260 unsigned NumElements,
6261 bool IsAltiVec, bool IsPixel) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006262 // FIXME: semantic checking!
John Thompson22334602010-02-05 00:12:22 +00006263 return SemaRef.Context.getVectorType(ElementType, NumElements,
6264 IsAltiVec, IsPixel);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregord6ff3322009-08-04 16:50:30 +00006267template<typename Derived>
6268QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6269 unsigned NumElements,
6270 SourceLocation AttributeLoc) {
6271 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6272 NumElements, true);
6273 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006274 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006275 AttributeLoc);
6276 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6277 AttributeLoc);
6278}
Mike Stump11289f42009-09-09 15:08:12 +00006279
Douglas Gregord6ff3322009-08-04 16:50:30 +00006280template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006281QualType
6282TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006283 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006284 SourceLocation AttributeLoc) {
6285 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6286}
Mike Stump11289f42009-09-09 15:08:12 +00006287
Douglas Gregord6ff3322009-08-04 16:50:30 +00006288template<typename Derived>
6289QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006290 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006291 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006292 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006293 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006294 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006295 Quals,
6296 getDerived().getBaseLocation(),
6297 getDerived().getBaseEntity());
6298}
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregord6ff3322009-08-04 16:50:30 +00006300template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006301QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6302 return SemaRef.Context.getFunctionNoProtoType(T);
6303}
6304
6305template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006306QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6307 assert(D && "no decl found");
6308 if (D->isInvalidDecl()) return QualType();
6309
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006310 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006311 TypeDecl *Ty;
6312 if (isa<UsingDecl>(D)) {
6313 UsingDecl *Using = cast<UsingDecl>(D);
6314 assert(Using->isTypeName() &&
6315 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6316
6317 // A valid resolved using typename decl points to exactly one type decl.
6318 assert(++Using->shadow_begin() == Using->shadow_end());
6319 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006320
John McCallb96ec562009-12-04 22:46:56 +00006321 } else {
6322 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6323 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6324 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6325 }
6326
6327 return SemaRef.Context.getTypeDeclType(Ty);
6328}
6329
6330template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006331QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006332 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6333}
6334
6335template<typename Derived>
6336QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6337 return SemaRef.Context.getTypeOfType(Underlying);
6338}
6339
6340template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006341QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006342 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6343}
6344
6345template<typename Derived>
6346QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006347 TemplateName Template,
6348 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006349 const TemplateArgumentListInfo &TemplateArgs) {
6350 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006351}
Mike Stump11289f42009-09-09 15:08:12 +00006352
Douglas Gregor1135c352009-08-06 05:28:30 +00006353template<typename Derived>
6354NestedNameSpecifier *
6355TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6356 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006357 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006358 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006359 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006360 CXXScopeSpec SS;
6361 // FIXME: The source location information is all wrong.
6362 SS.setRange(Range);
6363 SS.setScopeRep(Prefix);
6364 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006365 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006366 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006367 ObjectType,
6368 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006369 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006370}
6371
6372template<typename Derived>
6373NestedNameSpecifier *
6374TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6375 SourceRange Range,
6376 NamespaceDecl *NS) {
6377 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6378}
6379
6380template<typename Derived>
6381NestedNameSpecifier *
6382TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6383 SourceRange Range,
6384 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006385 QualType T) {
6386 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006387 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006388 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006389 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6390 T.getTypePtr());
6391 }
Mike Stump11289f42009-09-09 15:08:12 +00006392
Douglas Gregor1135c352009-08-06 05:28:30 +00006393 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6394 return 0;
6395}
Mike Stump11289f42009-09-09 15:08:12 +00006396
Douglas Gregor71dc5092009-08-06 06:41:21 +00006397template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006398TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006399TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6400 bool TemplateKW,
6401 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006402 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006403 Template);
6404}
6405
6406template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006407TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006408TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006409 const IdentifierInfo &II,
6410 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006411 CXXScopeSpec SS;
6412 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006413 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006414 UnqualifiedId Name;
6415 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregor308047d2009-09-09 00:23:06 +00006416 return getSema().ActOnDependentTemplateName(
6417 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006418 SS,
Douglas Gregor3cf81312009-11-03 23:16:33 +00006419 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006420 ObjectType.getAsOpaquePtr(),
6421 /*EnteringContext=*/false)
Douglas Gregor308047d2009-09-09 00:23:06 +00006422 .template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006423}
Mike Stump11289f42009-09-09 15:08:12 +00006424
Douglas Gregora16548e2009-08-11 05:31:07 +00006425template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006426TemplateName
6427TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6428 OverloadedOperatorKind Operator,
6429 QualType ObjectType) {
6430 CXXScopeSpec SS;
6431 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6432 SS.setScopeRep(Qualifier);
6433 UnqualifiedId Name;
6434 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6435 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6436 Operator, SymbolLocations);
6437 return getSema().ActOnDependentTemplateName(
6438 /*FIXME:*/getDerived().getBaseLocation(),
6439 SS,
6440 Name,
Douglas Gregorade9bcd2009-11-20 23:39:24 +00006441 ObjectType.getAsOpaquePtr(),
6442 /*EnteringContext=*/false)
Douglas Gregor71395fa2009-11-04 00:56:37 +00006443 .template getAsVal<TemplateName>();
6444}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006445
Douglas Gregor71395fa2009-11-04 00:56:37 +00006446template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006447Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006448TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6449 SourceLocation OpLoc,
6450 ExprArg Callee,
6451 ExprArg First,
6452 ExprArg Second) {
6453 Expr *FirstExpr = (Expr *)First.get();
6454 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006455 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006456 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006457
Douglas Gregora16548e2009-08-11 05:31:07 +00006458 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006459 if (Op == OO_Subscript) {
6460 if (!FirstExpr->getType()->isOverloadableType() &&
6461 !SecondExpr->getType()->isOverloadableType())
6462 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006463 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006464 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006465 } else if (Op == OO_Arrow) {
6466 // -> is never a builtin operation.
6467 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006468 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006469 if (!FirstExpr->getType()->isOverloadableType()) {
6470 // The argument is not of overloadable type, so try to create a
6471 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006472 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006473 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006474
Douglas Gregora16548e2009-08-11 05:31:07 +00006475 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6476 }
6477 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006478 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006479 !SecondExpr->getType()->isOverloadableType()) {
6480 // Neither of the arguments is an overloadable type, so try to
6481 // create a built-in binary operation.
6482 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006483 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006484 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6485 if (Result.isInvalid())
6486 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488 First.release();
6489 Second.release();
6490 return move(Result);
6491 }
6492 }
Mike Stump11289f42009-09-09 15:08:12 +00006493
6494 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006495 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006496 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006497
John McCalld14a8642009-11-21 08:51:07 +00006498 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6499 assert(ULE->requiresADL());
6500
6501 // FIXME: Do we have to check
6502 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006503 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006504 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006505 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006506 }
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregora16548e2009-08-11 05:31:07 +00006508 // Add any functions found via argument-dependent lookup.
6509 Expr *Args[2] = { FirstExpr, SecondExpr };
6510 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006511
Douglas Gregora16548e2009-08-11 05:31:07 +00006512 // Create the overloaded operator invocation for unary operators.
6513 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006514 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006515 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6516 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6517 }
Mike Stump11289f42009-09-09 15:08:12 +00006518
Sebastian Redladba46e2009-10-29 20:17:01 +00006519 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006520 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6521 OpLoc,
6522 move(First),
6523 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006524
Douglas Gregora16548e2009-08-11 05:31:07 +00006525 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006526 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006527 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006528 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006529 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6530 if (Result.isInvalid())
6531 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006532
Douglas Gregora16548e2009-08-11 05:31:07 +00006533 First.release();
6534 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006535 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006536}
Mike Stump11289f42009-09-09 15:08:12 +00006537
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006538template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006539Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006540TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6541 SourceLocation OperatorLoc,
6542 bool isArrow,
6543 NestedNameSpecifier *Qualifier,
6544 SourceRange QualifierRange,
6545 TypeSourceInfo *ScopeType,
6546 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006547 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006548 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006549 CXXScopeSpec SS;
6550 if (Qualifier) {
6551 SS.setRange(QualifierRange);
6552 SS.setScopeRep(Qualifier);
6553 }
6554
6555 Expr *BaseE = (Expr *)Base.get();
6556 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006557 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006558 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006559 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006560 !BaseType->getAs<PointerType>()->getPointeeType()
6561 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006562 // This pseudo-destructor expression is still a pseudo-destructor.
6563 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6564 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006565 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006566 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006567 /*FIXME?*/true);
6568 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006569
Douglas Gregor678f90d2010-02-25 01:56:36 +00006570 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006571 DeclarationName Name
6572 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6573 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006574
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006575 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006576
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006577 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6578 OperatorLoc, isArrow,
6579 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006580 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006581 /*TemplateArgs*/ 0);
6582}
6583
Douglas Gregord6ff3322009-08-04 16:50:30 +00006584} // end namespace clang
6585
6586#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H