blob: f3ad6c8b4b7cab05d5ffb532125802884b727003 [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 Huntabb2ac82010-05-18 06:22:21 +0000347#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000348#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,
Chris Lattner37141f42010-06-23 06:00:24 +0000445 VectorType::AltiVecSpecific AltiVecSpec);
Mike Stump11289f42009-09-09 15:08:12 +0000446
Douglas Gregord6ff3322009-08-04 16:50:30 +0000447 /// \brief Build a new extended vector type given the element type and
448 /// number of elements.
449 ///
450 /// By default, performs semantic analysis when building the vector type.
451 /// Subclasses may override this routine to provide different behavior.
452 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
453 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000454
455 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000456 /// given the element type and number of elements.
457 ///
458 /// By default, performs semantic analysis when building the vector type.
459 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000460 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +0000461 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000462 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000463
Douglas Gregord6ff3322009-08-04 16:50:30 +0000464 /// \brief Build a new function type.
465 ///
466 /// By default, performs semantic analysis when building the function type.
467 /// Subclasses may override this routine to provide different behavior.
468 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000469 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000470 unsigned NumParamTypes,
471 bool Variadic, unsigned Quals);
Mike Stump11289f42009-09-09 15:08:12 +0000472
John McCall550e0c22009-10-21 00:40:46 +0000473 /// \brief Build a new unprototyped function type.
474 QualType RebuildFunctionNoProtoType(QualType ResultType);
475
John McCallb96ec562009-12-04 22:46:56 +0000476 /// \brief Rebuild an unresolved typename type, given the decl that
477 /// the UnresolvedUsingTypenameDecl was transformed to.
478 QualType RebuildUnresolvedUsingType(Decl *D);
479
Douglas Gregord6ff3322009-08-04 16:50:30 +0000480 /// \brief Build a new typedef type.
481 QualType RebuildTypedefType(TypedefDecl *Typedef) {
482 return SemaRef.Context.getTypeDeclType(Typedef);
483 }
484
485 /// \brief Build a new class/struct/union type.
486 QualType RebuildRecordType(RecordDecl *Record) {
487 return SemaRef.Context.getTypeDeclType(Record);
488 }
489
490 /// \brief Build a new Enum type.
491 QualType RebuildEnumType(EnumDecl *Enum) {
492 return SemaRef.Context.getTypeDeclType(Enum);
493 }
John McCallfcc33b02009-09-05 00:15:47 +0000494
Mike Stump11289f42009-09-09 15:08:12 +0000495 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000496 ///
497 /// By default, performs semantic analysis when building the typeof type.
498 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000499 QualType RebuildTypeOfExprType(ExprArg Underlying);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000500
Mike Stump11289f42009-09-09 15:08:12 +0000501 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000502 ///
503 /// By default, builds a new TypeOfType with the given underlying type.
504 QualType RebuildTypeOfType(QualType Underlying);
505
Mike Stump11289f42009-09-09 15:08:12 +0000506 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000507 ///
508 /// By default, performs semantic analysis when building the decltype type.
509 /// Subclasses may override this routine to provide different behavior.
Douglas Gregora16548e2009-08-11 05:31:07 +0000510 QualType RebuildDecltypeType(ExprArg Underlying);
Mike Stump11289f42009-09-09 15:08:12 +0000511
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512 /// \brief Build a new template specialization type.
513 ///
514 /// By default, performs semantic analysis when building the template
515 /// specialization type. Subclasses may override this routine to provide
516 /// different behavior.
517 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000518 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000519 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregord6ff3322009-08-04 16:50:30 +0000521 /// \brief Build a new qualified name type.
522 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000523 /// By default, builds a new ElaboratedType type from the keyword,
524 /// the nested-name-specifier and the named type.
525 /// Subclasses may override this routine to provide different behavior.
526 QualType RebuildElaboratedType(ElaboratedTypeKeyword Keyword,
527 NestedNameSpecifier *NNS, QualType Named) {
528 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000529 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000530
531 /// \brief Build a new typename type that refers to a template-id.
532 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000533 /// By default, builds a new DependentNameType type from the
534 /// nested-name-specifier and the given type. Subclasses may override
535 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000536 QualType RebuildDependentTemplateSpecializationType(
537 ElaboratedTypeKeyword Keyword,
538 NestedNameSpecifier *NNS,
539 const IdentifierInfo *Name,
540 SourceLocation NameLoc,
541 const TemplateArgumentListInfo &Args) {
542 // Rebuild the template name.
543 // TODO: avoid TemplateName abstraction
544 TemplateName InstName =
545 getDerived().RebuildTemplateName(NNS, *Name, QualType());
546
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000547 if (InstName.isNull())
548 return QualType();
549
John McCallc392f372010-06-11 00:33:02 +0000550 // If it's still dependent, make a dependent specialization.
551 if (InstName.getAsDependentTemplateName())
552 return SemaRef.Context.getDependentTemplateSpecializationType(
553 Keyword, NNS, Name, Args);
554
555 // Otherwise, make an elaborated type wrapping a non-dependent
556 // specialization.
557 QualType T =
558 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
559 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000560
561 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Mike Stump11289f42009-09-09 15:08:12 +0000562 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563
564 /// \brief Build a new typename type that refers to an identifier.
565 ///
566 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000567 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000568 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000569 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000570 NestedNameSpecifier *NNS,
571 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000572 SourceLocation KeywordLoc,
573 SourceRange NNSRange,
574 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000575 CXXScopeSpec SS;
576 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000577 SS.setRange(NNSRange);
578
Douglas Gregore677daf2010-03-31 22:19:08 +0000579 if (NNS->isDependent()) {
580 // If the name is still dependent, just build a new dependent name type.
581 if (!SemaRef.computeDeclContext(SS))
582 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
583 }
584
Abramo Bagnara6150c882010-05-11 21:36:43 +0000585 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000586 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
587 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000588
589 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
590
Abramo Bagnarad7548482010-05-19 21:37:53 +0000591 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000592 // into a non-dependent elaborated-type-specifier. Find the tag we're
593 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000594 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000595 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
596 if (!DC)
597 return QualType();
598
John McCallbf8c5192010-05-27 06:40:31 +0000599 if (SemaRef.RequireCompleteDeclContext(SS, DC))
600 return QualType();
601
Douglas Gregore677daf2010-03-31 22:19:08 +0000602 TagDecl *Tag = 0;
603 SemaRef.LookupQualifiedName(Result, DC);
604 switch (Result.getResultKind()) {
605 case LookupResult::NotFound:
606 case LookupResult::NotFoundInCurrentInstantiation:
607 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000608
Douglas Gregore677daf2010-03-31 22:19:08 +0000609 case LookupResult::Found:
610 Tag = Result.getAsSingle<TagDecl>();
611 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000612
Douglas Gregore677daf2010-03-31 22:19:08 +0000613 case LookupResult::FoundOverloaded:
614 case LookupResult::FoundUnresolvedValue:
615 llvm_unreachable("Tag lookup cannot find non-tags");
616 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000617
Douglas Gregore677daf2010-03-31 22:19:08 +0000618 case LookupResult::Ambiguous:
619 // Let the LookupResult structure handle ambiguities.
620 return QualType();
621 }
622
623 if (!Tag) {
Douglas Gregorf5af3582010-03-31 23:17:41 +0000624 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000625 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000626 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000627 return QualType();
628 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000629
Abramo Bagnarad7548482010-05-19 21:37:53 +0000630 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
631 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000632 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
633 return QualType();
634 }
635
636 // Build the elaborated-type-specifier type.
637 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000638 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000639 }
Mike Stump11289f42009-09-09 15:08:12 +0000640
Douglas Gregor1135c352009-08-06 05:28:30 +0000641 /// \brief Build a new nested-name-specifier given the prefix and an
642 /// identifier that names the next step in the nested-name-specifier.
643 ///
644 /// By default, performs semantic analysis when building the new
645 /// nested-name-specifier. Subclasses may override this routine to provide
646 /// different behavior.
647 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
648 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000649 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000650 QualType ObjectType,
651 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000652
653 /// \brief Build a new nested-name-specifier given the prefix and the
654 /// namespace named in the next step in the nested-name-specifier.
655 ///
656 /// By default, performs semantic analysis when building the new
657 /// nested-name-specifier. Subclasses may override this routine to provide
658 /// different behavior.
659 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
660 SourceRange Range,
661 NamespaceDecl *NS);
662
663 /// \brief Build a new nested-name-specifier given the prefix and the
664 /// type named in the next step in the nested-name-specifier.
665 ///
666 /// By default, performs semantic analysis when building the new
667 /// nested-name-specifier. Subclasses may override this routine to provide
668 /// different behavior.
669 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
670 SourceRange Range,
671 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000672 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000673
674 /// \brief Build a new template name given a nested name specifier, a flag
675 /// indicating whether the "template" keyword was provided, and the template
676 /// that the template name refers to.
677 ///
678 /// By default, builds the new template name directly. Subclasses may override
679 /// this routine to provide different behavior.
680 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
681 bool TemplateKW,
682 TemplateDecl *Template);
683
Douglas Gregor71dc5092009-08-06 06:41:21 +0000684 /// \brief Build a new template name given a nested name specifier and the
685 /// name that is referred to as a template.
686 ///
687 /// By default, performs semantic analysis to determine whether the name can
688 /// be resolved to a specific template, then builds the appropriate kind of
689 /// template name. Subclasses may override this routine to provide different
690 /// behavior.
691 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +0000692 const IdentifierInfo &II,
693 QualType ObjectType);
Mike Stump11289f42009-09-09 15:08:12 +0000694
Douglas Gregor71395fa2009-11-04 00:56:37 +0000695 /// \brief Build a new template name given a nested name specifier and the
696 /// overloaded operator name that is referred to as a template.
697 ///
698 /// By default, performs semantic analysis to determine whether the name can
699 /// be resolved to a specific template, then builds the appropriate kind of
700 /// template name. Subclasses may override this routine to provide different
701 /// behavior.
702 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
703 OverloadedOperatorKind Operator,
704 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000705
Douglas Gregorebe10102009-08-20 07:17:43 +0000706 /// \brief Build a new compound statement.
707 ///
708 /// By default, performs semantic analysis to build the new statement.
709 /// Subclasses may override this routine to provide different behavior.
710 OwningStmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
711 MultiStmtArg Statements,
712 SourceLocation RBraceLoc,
713 bool IsStmtExpr) {
714 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, move(Statements),
715 IsStmtExpr);
716 }
717
718 /// \brief Build a new case statement.
719 ///
720 /// By default, performs semantic analysis to build the new statement.
721 /// Subclasses may override this routine to provide different behavior.
722 OwningStmtResult RebuildCaseStmt(SourceLocation CaseLoc,
723 ExprArg LHS,
724 SourceLocation EllipsisLoc,
725 ExprArg RHS,
726 SourceLocation ColonLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000727 return getSema().ActOnCaseStmt(CaseLoc, move(LHS), EllipsisLoc, move(RHS),
Douglas Gregorebe10102009-08-20 07:17:43 +0000728 ColonLoc);
729 }
Mike Stump11289f42009-09-09 15:08:12 +0000730
Douglas Gregorebe10102009-08-20 07:17:43 +0000731 /// \brief Attach the body to a new case statement.
732 ///
733 /// By default, performs semantic analysis to build the new statement.
734 /// Subclasses may override this routine to provide different behavior.
735 OwningStmtResult RebuildCaseStmtBody(StmtArg S, StmtArg Body) {
736 getSema().ActOnCaseStmtBody(S.get(), move(Body));
737 return move(S);
738 }
Mike Stump11289f42009-09-09 15:08:12 +0000739
Douglas Gregorebe10102009-08-20 07:17:43 +0000740 /// \brief Build a new default statement.
741 ///
742 /// By default, performs semantic analysis to build the new statement.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 OwningStmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000745 SourceLocation ColonLoc,
746 StmtArg SubStmt) {
Mike Stump11289f42009-09-09 15:08:12 +0000747 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, move(SubStmt),
Douglas Gregorebe10102009-08-20 07:17:43 +0000748 /*CurScope=*/0);
749 }
Mike Stump11289f42009-09-09 15:08:12 +0000750
Douglas Gregorebe10102009-08-20 07:17:43 +0000751 /// \brief Build a new label statement.
752 ///
753 /// By default, performs semantic analysis to build the new statement.
754 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000755 OwningStmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000756 IdentifierInfo *Id,
757 SourceLocation ColonLoc,
758 StmtArg SubStmt) {
759 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, move(SubStmt));
760 }
Mike Stump11289f42009-09-09 15:08:12 +0000761
Douglas Gregorebe10102009-08-20 07:17:43 +0000762 /// \brief Build a new "if" statement.
763 ///
764 /// By default, performs semantic analysis to build the new statement.
765 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000766 OwningStmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000767 VarDecl *CondVar, StmtArg Then,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000768 SourceLocation ElseLoc, StmtArg Else) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000769 return getSema().ActOnIfStmt(IfLoc, Cond, DeclPtrTy::make(CondVar),
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000770 move(Then), ElseLoc, move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +0000771 }
Mike Stump11289f42009-09-09 15:08:12 +0000772
Douglas Gregorebe10102009-08-20 07:17:43 +0000773 /// \brief Start building a new switch statement.
774 ///
775 /// By default, performs semantic analysis to build the new statement.
776 /// Subclasses may override this routine to provide different behavior.
Douglas Gregore60e41a2010-05-06 17:25:47 +0000777 OwningStmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
778 Sema::ExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000779 VarDecl *CondVar) {
Douglas Gregore60e41a2010-05-06 17:25:47 +0000780 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, move(Cond),
781 DeclPtrTy::make(CondVar));
Douglas Gregorebe10102009-08-20 07:17:43 +0000782 }
Mike Stump11289f42009-09-09 15:08:12 +0000783
Douglas Gregorebe10102009-08-20 07:17:43 +0000784 /// \brief Attach the body to the switch statement.
785 ///
786 /// By default, performs semantic analysis to build the new statement.
787 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000788 OwningStmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000789 StmtArg Switch, StmtArg Body) {
790 return getSema().ActOnFinishSwitchStmt(SwitchLoc, move(Switch),
791 move(Body));
792 }
793
794 /// \brief Build a new while statement.
795 ///
796 /// By default, performs semantic analysis to build the new statement.
797 /// Subclasses may override this routine to provide different behavior.
798 OwningStmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000799 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000800 VarDecl *CondVar,
Douglas Gregorebe10102009-08-20 07:17:43 +0000801 StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000802 return getSema().ActOnWhileStmt(WhileLoc, Cond,
Douglas Gregore60e41a2010-05-06 17:25:47 +0000803 DeclPtrTy::make(CondVar), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000804 }
Mike Stump11289f42009-09-09 15:08:12 +0000805
Douglas Gregorebe10102009-08-20 07:17:43 +0000806 /// \brief Build a new do-while statement.
807 ///
808 /// By default, performs semantic analysis to build the new statement.
809 /// Subclasses may override this routine to provide different behavior.
810 OwningStmtResult RebuildDoStmt(SourceLocation DoLoc, StmtArg Body,
811 SourceLocation WhileLoc,
812 SourceLocation LParenLoc,
813 ExprArg Cond,
814 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +0000815 return getSema().ActOnDoStmt(DoLoc, move(Body), WhileLoc, LParenLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000816 move(Cond), RParenLoc);
817 }
818
819 /// \brief Build a new for statement.
820 ///
821 /// By default, performs semantic analysis to build the new statement.
822 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000823 OwningStmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000824 SourceLocation LParenLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000825 StmtArg Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000826 VarDecl *CondVar, Sema::FullExprArg Inc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000827 SourceLocation RParenLoc, StmtArg Body) {
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000828 return getSema().ActOnForStmt(ForLoc, LParenLoc, move(Init), Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000829 DeclPtrTy::make(CondVar),
830 Inc, RParenLoc, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +0000831 }
Mike Stump11289f42009-09-09 15:08:12 +0000832
Douglas Gregorebe10102009-08-20 07:17:43 +0000833 /// \brief Build a new goto statement.
834 ///
835 /// By default, performs semantic analysis to build the new statement.
836 /// Subclasses may override this routine to provide different behavior.
837 OwningStmtResult RebuildGotoStmt(SourceLocation GotoLoc,
838 SourceLocation LabelLoc,
839 LabelStmt *Label) {
840 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
841 }
842
843 /// \brief Build a new indirect goto statement.
844 ///
845 /// By default, performs semantic analysis to build the new statement.
846 /// Subclasses may override this routine to provide different behavior.
847 OwningStmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
848 SourceLocation StarLoc,
849 ExprArg Target) {
850 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, move(Target));
851 }
Mike Stump11289f42009-09-09 15:08:12 +0000852
Douglas Gregorebe10102009-08-20 07:17:43 +0000853 /// \brief Build a new return statement.
854 ///
855 /// By default, performs semantic analysis to build the new statement.
856 /// Subclasses may override this routine to provide different behavior.
857 OwningStmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
858 ExprArg Result) {
Mike Stump11289f42009-09-09 15:08:12 +0000859
Douglas Gregorebe10102009-08-20 07:17:43 +0000860 return getSema().ActOnReturnStmt(ReturnLoc, move(Result));
861 }
Mike Stump11289f42009-09-09 15:08:12 +0000862
Douglas Gregorebe10102009-08-20 07:17:43 +0000863 /// \brief Build a new declaration statement.
864 ///
865 /// By default, performs semantic analysis to build the new statement.
866 /// Subclasses may override this routine to provide different behavior.
867 OwningStmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +0000868 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000869 SourceLocation EndLoc) {
870 return getSema().Owned(
871 new (getSema().Context) DeclStmt(
872 DeclGroupRef::Create(getSema().Context,
873 Decls, NumDecls),
874 StartLoc, EndLoc));
875 }
Mike Stump11289f42009-09-09 15:08:12 +0000876
Anders Carlssonaaeef072010-01-24 05:50:09 +0000877 /// \brief Build a new inline asm statement.
878 ///
879 /// By default, performs semantic analysis to build the new statement.
880 /// Subclasses may override this routine to provide different behavior.
881 OwningStmtResult RebuildAsmStmt(SourceLocation AsmLoc,
882 bool IsSimple,
883 bool IsVolatile,
884 unsigned NumOutputs,
885 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +0000886 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000887 MultiExprArg Constraints,
888 MultiExprArg Exprs,
889 ExprArg AsmString,
890 MultiExprArg Clobbers,
891 SourceLocation RParenLoc,
892 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000893 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +0000894 NumInputs, Names, move(Constraints),
895 move(Exprs), move(AsmString), move(Clobbers),
896 RParenLoc, MSAsm);
897 }
Douglas Gregor306de2f2010-04-22 23:59:56 +0000898
899 /// \brief Build a new Objective-C @try statement.
900 ///
901 /// By default, performs semantic analysis to build the new statement.
902 /// Subclasses may override this routine to provide different behavior.
903 OwningStmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
904 StmtArg TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +0000905 MultiStmtArg CatchStmts,
Douglas Gregor306de2f2010-04-22 23:59:56 +0000906 StmtArg Finally) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000907 return getSema().ActOnObjCAtTryStmt(AtLoc, move(TryBody), move(CatchStmts),
Douglas Gregor306de2f2010-04-22 23:59:56 +0000908 move(Finally));
909 }
910
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000911 /// \brief Rebuild an Objective-C exception declaration.
912 ///
913 /// By default, performs semantic analysis to build the new declaration.
914 /// Subclasses may override this routine to provide different behavior.
915 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
916 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +0000917 return getSema().BuildObjCExceptionDecl(TInfo, T,
918 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000919 ExceptionDecl->getLocation());
920 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000921
Douglas Gregorf4e837f2010-04-26 17:57:08 +0000922 /// \brief Build a new Objective-C @catch statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
926 OwningStmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
927 SourceLocation RParenLoc,
928 VarDecl *Var,
929 StmtArg Body) {
930 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
931 Sema::DeclPtrTy::make(Var),
932 move(Body));
933 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000934
Douglas Gregor306de2f2010-04-22 23:59:56 +0000935 /// \brief Build a new Objective-C @finally statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
939 OwningStmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
940 StmtArg Body) {
941 return getSema().ActOnObjCAtFinallyStmt(AtLoc, move(Body));
942 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000943
Douglas Gregor6148de72010-04-22 22:01:21 +0000944 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +0000945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
948 OwningStmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
949 ExprArg Operand) {
950 return getSema().BuildObjCAtThrowStmt(AtLoc, move(Operand));
951 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000952
Douglas Gregor6148de72010-04-22 22:01:21 +0000953 /// \brief Build a new Objective-C @synchronized statement.
954 ///
Douglas Gregor6148de72010-04-22 22:01:21 +0000955 /// By default, performs semantic analysis to build the new statement.
956 /// Subclasses may override this routine to provide different behavior.
957 OwningStmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
958 ExprArg Object,
959 StmtArg Body) {
960 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, move(Object),
961 move(Body));
962 }
Douglas Gregorf68a5082010-04-22 23:10:45 +0000963
964 /// \brief Build a new Objective-C fast enumeration statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
968 OwningStmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
969 SourceLocation LParenLoc,
970 StmtArg Element,
971 ExprArg Collection,
972 SourceLocation RParenLoc,
973 StmtArg Body) {
974 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
Alexis Hunta8136cc2010-05-05 15:23:54 +0000975 move(Element),
Douglas Gregorf68a5082010-04-22 23:10:45 +0000976 move(Collection),
977 RParenLoc,
978 move(Body));
979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000980
Douglas Gregorebe10102009-08-20 07:17:43 +0000981 /// \brief Build a new C++ exception declaration.
982 ///
983 /// By default, performs semantic analysis to build the new decaration.
984 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000985 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, QualType T,
John McCallbcd03502009-12-07 02:54:59 +0000986 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 IdentifierInfo *Name,
988 SourceLocation Loc,
989 SourceRange TypeRange) {
Mike Stump11289f42009-09-09 15:08:12 +0000990 return getSema().BuildExceptionDeclaration(0, T, Declarator, Name, Loc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 TypeRange);
992 }
993
994 /// \brief Build a new C++ catch statement.
995 ///
996 /// By default, performs semantic analysis to build the new statement.
997 /// Subclasses may override this routine to provide different behavior.
998 OwningStmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
999 VarDecl *ExceptionDecl,
1000 StmtArg Handler) {
1001 return getSema().Owned(
Mike Stump11289f42009-09-09 15:08:12 +00001002 new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 Handler.takeAs<Stmt>()));
1004 }
Mike Stump11289f42009-09-09 15:08:12 +00001005
Douglas Gregorebe10102009-08-20 07:17:43 +00001006 /// \brief Build a new C++ try statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
1010 OwningStmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
1011 StmtArg TryBlock,
1012 MultiStmtArg Handlers) {
1013 return getSema().ActOnCXXTryBlock(TryLoc, move(TryBlock), move(Handlers));
1014 }
Mike Stump11289f42009-09-09 15:08:12 +00001015
Douglas Gregora16548e2009-08-11 05:31:07 +00001016 /// \brief Build a new expression that references a declaration.
1017 ///
1018 /// By default, performs semantic analysis to build the new expression.
1019 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001020 OwningExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
1021 LookupResult &R,
1022 bool RequiresADL) {
1023 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1024 }
1025
1026
1027 /// \brief Build a new expression that references a declaration.
1028 ///
1029 /// By default, performs semantic analysis to build the new expression.
1030 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001031 OwningExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
1032 SourceRange QualifierRange,
John McCallce546572009-12-08 09:08:17 +00001033 ValueDecl *VD, SourceLocation Loc,
1034 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001035 CXXScopeSpec SS;
1036 SS.setScopeRep(Qualifier);
1037 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001038
1039 // FIXME: loses template args.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001040
John McCallce546572009-12-08 09:08:17 +00001041 return getSema().BuildDeclarationNameExpr(SS, Loc, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001042 }
Mike Stump11289f42009-09-09 15:08:12 +00001043
Douglas Gregora16548e2009-08-11 05:31:07 +00001044 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001045 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001046 /// By default, performs semantic analysis to build the new expression.
1047 /// Subclasses may override this routine to provide different behavior.
1048 OwningExprResult RebuildParenExpr(ExprArg SubExpr, SourceLocation LParen,
1049 SourceLocation RParen) {
1050 return getSema().ActOnParenExpr(LParen, RParen, move(SubExpr));
1051 }
1052
Douglas Gregorad8a3362009-09-04 17:36:40 +00001053 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001054 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001055 /// By default, performs semantic analysis to build the new expression.
1056 /// Subclasses may override this routine to provide different behavior.
1057 OwningExprResult RebuildCXXPseudoDestructorExpr(ExprArg Base,
1058 SourceLocation OperatorLoc,
1059 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001060 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001061 SourceRange QualifierRange,
1062 TypeSourceInfo *ScopeType,
1063 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001064 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001065 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001066
Douglas Gregora16548e2009-08-11 05:31:07 +00001067 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001068 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001069 /// By default, performs semantic analysis to build the new expression.
1070 /// Subclasses may override this routine to provide different behavior.
1071 OwningExprResult RebuildUnaryOperator(SourceLocation OpLoc,
1072 UnaryOperator::Opcode Opc,
1073 ExprArg SubExpr) {
Douglas Gregor5287f092009-11-05 00:51:44 +00001074 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001075 }
Mike Stump11289f42009-09-09 15:08:12 +00001076
Douglas Gregor882211c2010-04-28 22:16:22 +00001077 /// \brief Build a new builtin offsetof expression.
1078 ///
1079 /// By default, performs semantic analysis to build the new expression.
1080 /// Subclasses may override this routine to provide different behavior.
1081 OwningExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
1082 TypeSourceInfo *Type,
1083 Action::OffsetOfComponent *Components,
1084 unsigned NumComponents,
1085 SourceLocation RParenLoc) {
1086 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1087 NumComponents, RParenLoc);
1088 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001089
Douglas Gregora16548e2009-08-11 05:31:07 +00001090 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001091 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001092 /// By default, performs semantic analysis to build the new expression.
1093 /// Subclasses may override this routine to provide different behavior.
John McCallbcd03502009-12-07 02:54:59 +00001094 OwningExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001095 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001096 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001097 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001098 }
1099
Mike Stump11289f42009-09-09 15:08:12 +00001100 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001101 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001102 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001103 /// By default, performs semantic analysis to build the new expression.
1104 /// Subclasses may override this routine to provide different behavior.
1105 OwningExprResult RebuildSizeOfAlignOf(ExprArg SubExpr, SourceLocation OpLoc,
1106 bool isSizeOf, SourceRange R) {
Mike Stump11289f42009-09-09 15:08:12 +00001107 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001108 = getSema().CreateSizeOfAlignOfExpr((Expr *)SubExpr.get(),
1109 OpLoc, isSizeOf, R);
1110 if (Result.isInvalid())
1111 return getSema().ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001112
Douglas Gregora16548e2009-08-11 05:31:07 +00001113 SubExpr.release();
1114 return move(Result);
1115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Douglas Gregora16548e2009-08-11 05:31:07 +00001117 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001118 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001119 /// By default, performs semantic analysis to build the new expression.
1120 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001121 OwningExprResult RebuildArraySubscriptExpr(ExprArg LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001122 SourceLocation LBracketLoc,
1123 ExprArg RHS,
1124 SourceLocation RBracketLoc) {
1125 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, move(LHS),
Mike Stump11289f42009-09-09 15:08:12 +00001126 LBracketLoc, move(RHS),
Douglas Gregora16548e2009-08-11 05:31:07 +00001127 RBracketLoc);
1128 }
1129
1130 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001131 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001132 /// By default, performs semantic analysis to build the new expression.
1133 /// Subclasses may override this routine to provide different behavior.
1134 OwningExprResult RebuildCallExpr(ExprArg Callee, SourceLocation LParenLoc,
1135 MultiExprArg Args,
1136 SourceLocation *CommaLocs,
1137 SourceLocation RParenLoc) {
1138 return getSema().ActOnCallExpr(/*Scope=*/0, move(Callee), LParenLoc,
1139 move(Args), CommaLocs, RParenLoc);
1140 }
1141
1142 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001143 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001144 /// By default, performs semantic analysis to build the new expression.
1145 /// Subclasses may override this routine to provide different behavior.
1146 OwningExprResult RebuildMemberExpr(ExprArg Base, SourceLocation OpLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001147 bool isArrow,
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001148 NestedNameSpecifier *Qualifier,
1149 SourceRange QualifierRange,
1150 SourceLocation MemberLoc,
Eli Friedman2cfcef62009-12-04 06:40:45 +00001151 ValueDecl *Member,
John McCall16df1e52010-03-30 21:47:33 +00001152 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001153 const TemplateArgumentListInfo *ExplicitTemplateArgs,
Douglas Gregorb184f0d2009-11-04 23:20:05 +00001154 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001155 if (!Member->getDeclName()) {
1156 // We have a reference to an unnamed field.
1157 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
Mike Stump11289f42009-09-09 15:08:12 +00001158
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001159 Expr *BaseExpr = Base.takeAs<Expr>();
John McCall16df1e52010-03-30 21:47:33 +00001160 if (getSema().PerformObjectMemberConversion(BaseExpr, Qualifier,
1161 FoundDecl, Member))
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001162 return getSema().ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001163
Mike Stump11289f42009-09-09 15:08:12 +00001164 MemberExpr *ME =
Douglas Gregor8e8eaa12009-12-24 20:02:50 +00001165 new (getSema().Context) MemberExpr(BaseExpr, isArrow,
Anders Carlsson5da84842009-09-01 04:26:58 +00001166 Member, MemberLoc,
1167 cast<FieldDecl>(Member)->getType());
1168 return getSema().Owned(ME);
1169 }
Mike Stump11289f42009-09-09 15:08:12 +00001170
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001171 CXXScopeSpec SS;
1172 if (Qualifier) {
1173 SS.setRange(QualifierRange);
1174 SS.setScopeRep(Qualifier);
1175 }
1176
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001177 Expr *BaseExpr = Base.takeAs<Expr>();
1178 getSema().DefaultFunctionArrayConversion(BaseExpr);
1179 QualType BaseType = BaseExpr->getType();
John McCall2d74de92009-12-01 22:10:20 +00001180
John McCall16df1e52010-03-30 21:47:33 +00001181 // FIXME: this involves duplicating earlier analysis in a lot of
1182 // cases; we should avoid this when possible.
John McCall38836f02010-01-15 08:34:02 +00001183 LookupResult R(getSema(), Member->getDeclName(), MemberLoc,
1184 Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001185 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001186 R.resolveKind();
1187
Douglas Gregoref4a2a22010-06-22 02:41:05 +00001188 return getSema().BuildMemberReferenceExpr(getSema().Owned(BaseExpr),
1189 BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001190 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001191 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregora16548e2009-08-11 05:31:07 +00001194 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001195 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001196 /// By default, performs semantic analysis to build the new expression.
1197 /// Subclasses may override this routine to provide different behavior.
1198 OwningExprResult RebuildBinaryOperator(SourceLocation OpLoc,
1199 BinaryOperator::Opcode Opc,
1200 ExprArg LHS, ExprArg RHS) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001201 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc,
Douglas Gregor5287f092009-11-05 00:51:44 +00001202 LHS.takeAs<Expr>(), RHS.takeAs<Expr>());
Douglas Gregora16548e2009-08-11 05:31:07 +00001203 }
1204
1205 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001206 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001207 /// By default, performs semantic analysis to build the new expression.
1208 /// Subclasses may override this routine to provide different behavior.
1209 OwningExprResult RebuildConditionalOperator(ExprArg Cond,
1210 SourceLocation QuestionLoc,
1211 ExprArg LHS,
1212 SourceLocation ColonLoc,
1213 ExprArg RHS) {
Mike Stump11289f42009-09-09 15:08:12 +00001214 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, move(Cond),
Douglas Gregora16548e2009-08-11 05:31:07 +00001215 move(LHS), move(RHS));
1216 }
1217
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001219 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// By default, performs semantic analysis to build the new expression.
1221 /// Subclasses may override this routine to provide different behavior.
John McCall97513962010-01-15 18:39:57 +00001222 OwningExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
1223 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001224 SourceLocation RParenLoc,
1225 ExprArg SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001226 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
1227 move(SubExpr));
Douglas Gregora16548e2009-08-11 05:31:07 +00001228 }
Mike Stump11289f42009-09-09 15:08:12 +00001229
Douglas Gregora16548e2009-08-11 05:31:07 +00001230 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001231 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001232 /// By default, performs semantic analysis to build the new expression.
1233 /// Subclasses may override this routine to provide different behavior.
1234 OwningExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001235 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001236 SourceLocation RParenLoc,
1237 ExprArg Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001238 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
1239 move(Init));
Douglas Gregora16548e2009-08-11 05:31:07 +00001240 }
Mike Stump11289f42009-09-09 15:08:12 +00001241
Douglas Gregora16548e2009-08-11 05:31:07 +00001242 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001243 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001244 /// By default, performs semantic analysis to build the new expression.
1245 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001246 OwningExprResult RebuildExtVectorElementExpr(ExprArg Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001247 SourceLocation OpLoc,
1248 SourceLocation AccessorLoc,
1249 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001250
John McCall10eae182009-11-30 22:42:35 +00001251 CXXScopeSpec SS;
John McCall2d74de92009-12-01 22:10:20 +00001252 QualType BaseType = ((Expr*) Base.get())->getType();
1253 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
John McCall10eae182009-11-30 22:42:35 +00001254 OpLoc, /*IsArrow*/ false,
1255 SS, /*FirstQualifierInScope*/ 0,
Douglas Gregor30d60cb2009-11-03 19:44:04 +00001256 DeclarationName(&Accessor),
John McCall10eae182009-11-30 22:42:35 +00001257 AccessorLoc,
1258 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001259 }
Mike Stump11289f42009-09-09 15:08:12 +00001260
Douglas Gregora16548e2009-08-11 05:31:07 +00001261 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001262 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001263 /// By default, performs semantic analysis to build the new expression.
1264 /// Subclasses may override this routine to provide different behavior.
1265 OwningExprResult RebuildInitList(SourceLocation LBraceLoc,
1266 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001267 SourceLocation RBraceLoc,
1268 QualType ResultTy) {
1269 OwningExprResult Result
1270 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1271 if (Result.isInvalid() || ResultTy->isDependentType())
1272 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001273
Douglas Gregord3d93062009-11-09 17:16:50 +00001274 // Patch in the result type we were given, which may have been computed
1275 // when the initial InitListExpr was built.
1276 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1277 ILE->setType(ResultTy);
1278 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 }
Mike Stump11289f42009-09-09 15:08:12 +00001280
Douglas Gregora16548e2009-08-11 05:31:07 +00001281 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001282 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
1285 OwningExprResult RebuildDesignatedInitExpr(Designation &Desig,
1286 MultiExprArg ArrayExprs,
1287 SourceLocation EqualOrColonLoc,
1288 bool GNUSyntax,
1289 ExprArg Init) {
1290 OwningExprResult Result
1291 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
1292 move(Init));
1293 if (Result.isInvalid())
1294 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 ArrayExprs.release();
1297 return move(Result);
1298 }
Mike Stump11289f42009-09-09 15:08:12 +00001299
Douglas Gregora16548e2009-08-11 05:31:07 +00001300 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001301 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001302 /// By default, builds the implicit value initialization without performing
1303 /// any semantic analysis. Subclasses may override this routine to provide
1304 /// different behavior.
1305 OwningExprResult RebuildImplicitValueInitExpr(QualType T) {
1306 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1307 }
Mike Stump11289f42009-09-09 15:08:12 +00001308
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001310 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001311 /// By default, performs semantic analysis to build the new expression.
1312 /// Subclasses may override this routine to provide different behavior.
1313 OwningExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, ExprArg SubExpr,
1314 QualType T, SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001315 return getSema().ActOnVAArg(BuiltinLoc, move(SubExpr), T.getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001316 RParenLoc);
1317 }
1318
1319 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001320 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001321 /// By default, performs semantic analysis to build the new expression.
1322 /// Subclasses may override this routine to provide different behavior.
1323 OwningExprResult RebuildParenListExpr(SourceLocation LParenLoc,
1324 MultiExprArg SubExprs,
1325 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001326 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001327 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001328 }
Mike Stump11289f42009-09-09 15:08:12 +00001329
Douglas Gregora16548e2009-08-11 05:31:07 +00001330 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001331 ///
1332 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001333 /// rather than attempting to map the label statement itself.
1334 /// Subclasses may override this routine to provide different behavior.
1335 OwningExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
1336 SourceLocation LabelLoc,
1337 LabelStmt *Label) {
1338 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1339 }
Mike Stump11289f42009-09-09 15:08:12 +00001340
Douglas Gregora16548e2009-08-11 05:31:07 +00001341 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001342 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// By default, performs semantic analysis to build the new expression.
1344 /// Subclasses may override this routine to provide different behavior.
1345 OwningExprResult RebuildStmtExpr(SourceLocation LParenLoc,
1346 StmtArg SubStmt,
1347 SourceLocation RParenLoc) {
1348 return getSema().ActOnStmtExpr(LParenLoc, move(SubStmt), RParenLoc);
1349 }
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregora16548e2009-08-11 05:31:07 +00001351 /// \brief Build a new __builtin_types_compatible_p expression.
1352 ///
1353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
1355 OwningExprResult RebuildTypesCompatibleExpr(SourceLocation BuiltinLoc,
1356 QualType T1, QualType T2,
1357 SourceLocation RParenLoc) {
1358 return getSema().ActOnTypesCompatibleExpr(BuiltinLoc,
1359 T1.getAsOpaquePtr(),
1360 T2.getAsOpaquePtr(),
1361 RParenLoc);
1362 }
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 /// \brief Build a new __builtin_choose_expr expression.
1365 ///
1366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
1368 OwningExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
1369 ExprArg Cond, ExprArg LHS, ExprArg RHS,
1370 SourceLocation RParenLoc) {
1371 return SemaRef.ActOnChooseExpr(BuiltinLoc,
1372 move(Cond), move(LHS), move(RHS),
1373 RParenLoc);
1374 }
Mike Stump11289f42009-09-09 15:08:12 +00001375
Douglas Gregora16548e2009-08-11 05:31:07 +00001376 /// \brief Build a new overloaded operator call expression.
1377 ///
1378 /// By default, performs semantic analysis to build the new expression.
1379 /// The semantic analysis provides the behavior of template instantiation,
1380 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001381 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001382 /// argument-dependent lookup, etc. Subclasses may override this routine to
1383 /// provide different behavior.
1384 OwningExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
1385 SourceLocation OpLoc,
1386 ExprArg Callee,
1387 ExprArg First,
1388 ExprArg Second);
Mike Stump11289f42009-09-09 15:08:12 +00001389
1390 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001391 /// reinterpret_cast.
1392 ///
1393 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001394 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001395 /// Subclasses may override this routine to provide different behavior.
1396 OwningExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
1397 Stmt::StmtClass Class,
1398 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001399 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001400 SourceLocation RAngleLoc,
1401 SourceLocation LParenLoc,
1402 ExprArg SubExpr,
1403 SourceLocation RParenLoc) {
1404 switch (Class) {
1405 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001406 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001407 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001408 move(SubExpr), RParenLoc);
1409
1410 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001411 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001412 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001413 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001416 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001417 RAngleLoc, LParenLoc,
1418 move(SubExpr),
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001422 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001423 RAngleLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001424 move(SubExpr), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001425
Douglas Gregora16548e2009-08-11 05:31:07 +00001426 default:
1427 assert(false && "Invalid C++ named cast");
1428 break;
1429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
Douglas Gregora16548e2009-08-11 05:31:07 +00001431 return getSema().ExprError();
1432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new C++ static_cast expression.
1435 ///
1436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
1438 OwningExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
1439 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001440 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001441 SourceLocation RAngleLoc,
1442 SourceLocation LParenLoc,
1443 ExprArg SubExpr,
1444 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001445 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
1446 TInfo, move(SubExpr),
1447 SourceRange(LAngleLoc, RAngleLoc),
1448 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001449 }
1450
1451 /// \brief Build a new C++ dynamic_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 RebuildCXXDynamicCastExpr(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_dynamic_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++ reinterpret_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 RebuildCXXReinterpretCastExpr(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_reinterpret_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++ const_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 RebuildCXXConstCastExpr(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_const_cast,
1497 TInfo, move(SubExpr),
1498 SourceRange(LAngleLoc, RAngleLoc),
1499 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001500 }
Mike Stump11289f42009-09-09 15:08:12 +00001501
Douglas Gregora16548e2009-08-11 05:31:07 +00001502 /// \brief Build a new C++ functional-style 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 RebuildCXXFunctionalCastExpr(SourceRange TypeRange,
John McCall97513962010-01-15 18:39:57 +00001507 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 SourceLocation LParenLoc,
1509 ExprArg SubExpr,
1510 SourceLocation RParenLoc) {
Chris Lattnerdca19592009-08-24 05:19:01 +00001511 void *Sub = SubExpr.takeAs<Expr>();
Douglas Gregora16548e2009-08-11 05:31:07 +00001512 return getSema().ActOnCXXTypeConstructExpr(TypeRange,
John McCall97513962010-01-15 18:39:57 +00001513 TInfo->getType().getAsOpaquePtr(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001514 LParenLoc,
Chris Lattnerdca19592009-08-24 05:19:01 +00001515 Sema::MultiExprArg(getSema(), &Sub, 1),
Mike Stump11289f42009-09-09 15:08:12 +00001516 /*CommaLocs=*/0,
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 RParenLoc);
1518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Douglas Gregora16548e2009-08-11 05:31:07 +00001520 /// \brief Build a new C++ typeid(type) expression.
1521 ///
1522 /// By default, performs semantic analysis to build the new expression.
1523 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001524 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1525 SourceLocation TypeidLoc,
1526 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001528 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001529 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001530 }
Mike Stump11289f42009-09-09 15:08:12 +00001531
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 /// \brief Build a new C++ typeid(expr) expression.
1533 ///
1534 /// By default, performs semantic analysis to build the new expression.
1535 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9da64192010-04-26 22:37:10 +00001536 OwningExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
1537 SourceLocation TypeidLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 ExprArg Operand,
1539 SourceLocation RParenLoc) {
Douglas Gregor9da64192010-04-26 22:37:10 +00001540 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, move(Operand),
1541 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001542 }
1543
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// \brief Build a new C++ "this" expression.
1545 ///
1546 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001547 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001549 OwningExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorb15af892010-01-07 23:12:05 +00001550 QualType ThisType,
1551 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001552 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001553 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1554 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
1556
1557 /// \brief Build a new C++ throw expression.
1558 ///
1559 /// By default, performs semantic analysis to build the new expression.
1560 /// Subclasses may override this routine to provide different behavior.
1561 OwningExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, ExprArg Sub) {
1562 return getSema().ActOnCXXThrow(ThrowLoc, move(Sub));
1563 }
1564
1565 /// \brief Build a new C++ default-argument expression.
1566 ///
1567 /// By default, builds a new default-argument expression, which does not
1568 /// require any semantic analysis. Subclasses may override this routine to
1569 /// provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001570 OwningExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001571 ParmVarDecl *Param) {
1572 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1573 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001574 }
1575
1576 /// \brief Build a new C++ zero-initialization expression.
1577 ///
1578 /// By default, performs semantic analysis to build the new expression.
1579 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor747eb782010-07-08 06:14:04 +00001580 OwningExprResult RebuildCXXScalarValueInitExpr(SourceLocation TypeStartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 SourceLocation LParenLoc,
1582 QualType T,
1583 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001584 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeStartLoc),
1585 T.getAsOpaquePtr(), LParenLoc,
1586 MultiExprArg(getSema(), 0, 0),
Douglas Gregora16548e2009-08-11 05:31:07 +00001587 0, RParenLoc);
1588 }
Mike Stump11289f42009-09-09 15:08:12 +00001589
Douglas Gregora16548e2009-08-11 05:31:07 +00001590 /// \brief Build a new C++ "new" expression.
1591 ///
1592 /// By default, performs semantic analysis to build the new expression.
1593 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +00001594 OwningExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 bool UseGlobal,
1596 SourceLocation PlacementLParen,
1597 MultiExprArg PlacementArgs,
1598 SourceLocation PlacementRParen,
Mike Stump11289f42009-09-09 15:08:12 +00001599 bool ParenTypeId,
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 QualType AllocType,
1601 SourceLocation TypeLoc,
1602 SourceRange TypeRange,
1603 ExprArg ArraySize,
1604 SourceLocation ConstructorLParen,
1605 MultiExprArg ConstructorArgs,
1606 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001607 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 PlacementLParen,
1609 move(PlacementArgs),
1610 PlacementRParen,
1611 ParenTypeId,
1612 AllocType,
1613 TypeLoc,
1614 TypeRange,
1615 move(ArraySize),
1616 ConstructorLParen,
1617 move(ConstructorArgs),
1618 ConstructorRParen);
1619 }
Mike Stump11289f42009-09-09 15:08:12 +00001620
Douglas Gregora16548e2009-08-11 05:31:07 +00001621 /// \brief Build a new C++ "delete" expression.
1622 ///
1623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
1625 OwningExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
1626 bool IsGlobalDelete,
1627 bool IsArrayForm,
1628 ExprArg Operand) {
1629 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
1630 move(Operand));
1631 }
Mike Stump11289f42009-09-09 15:08:12 +00001632
Douglas Gregora16548e2009-08-11 05:31:07 +00001633 /// \brief Build a new unary type trait expression.
1634 ///
1635 /// By default, performs semantic analysis to build the new expression.
1636 /// Subclasses may override this routine to provide different behavior.
1637 OwningExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
1638 SourceLocation StartLoc,
1639 SourceLocation LParenLoc,
1640 QualType T,
1641 SourceLocation RParenLoc) {
Mike Stump11289f42009-09-09 15:08:12 +00001642 return getSema().ActOnUnaryTypeTrait(Trait, StartLoc, LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001643 T.getAsOpaquePtr(), RParenLoc);
1644 }
1645
Mike Stump11289f42009-09-09 15:08:12 +00001646 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001651 OwningExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 SourceRange QualifierRange,
1653 DeclarationName Name,
1654 SourceLocation Location,
John McCalle66edc12009-11-24 19:00:30 +00001655 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001656 CXXScopeSpec SS;
1657 SS.setRange(QualifierRange);
1658 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001659
1660 if (TemplateArgs)
1661 return getSema().BuildQualifiedTemplateIdExpr(SS, Name, Location,
1662 *TemplateArgs);
1663
1664 return getSema().BuildQualifiedDeclarationNameExpr(SS, Name, Location);
Douglas Gregora16548e2009-08-11 05:31:07 +00001665 }
1666
1667 /// \brief Build a new template-id expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCalle66edc12009-11-24 19:00:30 +00001671 OwningExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
1672 LookupResult &R,
1673 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001674 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001675 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001676 }
1677
1678 /// \brief Build a new object-construction expression.
1679 ///
1680 /// By default, performs semantic analysis to build the new expression.
1681 /// Subclasses may override this routine to provide different behavior.
1682 OwningExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001683 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 CXXConstructorDecl *Constructor,
1685 bool IsElidable,
1686 MultiExprArg Args) {
Douglas Gregordb121ba2009-12-14 16:27:04 +00001687 ASTOwningVector<&ActionBase::DeleteExpr> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001688 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001689 ConvertedArgs))
1690 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001691
Douglas Gregordb121ba2009-12-14 16:27:04 +00001692 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
1693 move_arg(ConvertedArgs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001694 }
1695
1696 /// \brief Build a new object-construction expression.
1697 ///
1698 /// By default, performs semantic analysis to build the new expression.
1699 /// Subclasses may override this routine to provide different behavior.
1700 OwningExprResult RebuildCXXTemporaryObjectExpr(SourceLocation TypeBeginLoc,
1701 QualType T,
1702 SourceLocation LParenLoc,
1703 MultiExprArg Args,
1704 SourceLocation *Commas,
1705 SourceLocation RParenLoc) {
1706 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc),
1707 T.getAsOpaquePtr(),
1708 LParenLoc,
1709 move(Args),
1710 Commas,
1711 RParenLoc);
1712 }
1713
1714 /// \brief Build a new object-construction expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
1718 OwningExprResult RebuildCXXUnresolvedConstructExpr(SourceLocation TypeBeginLoc,
1719 QualType T,
1720 SourceLocation LParenLoc,
1721 MultiExprArg Args,
1722 SourceLocation *Commas,
1723 SourceLocation RParenLoc) {
1724 return getSema().ActOnCXXTypeConstructExpr(SourceRange(TypeBeginLoc,
1725 /*FIXME*/LParenLoc),
1726 T.getAsOpaquePtr(),
1727 LParenLoc,
1728 move(Args),
1729 Commas,
1730 RParenLoc);
1731 }
Mike Stump11289f42009-09-09 15:08:12 +00001732
Douglas Gregora16548e2009-08-11 05:31:07 +00001733 /// \brief Build a new member reference expression.
1734 ///
1735 /// By default, performs semantic analysis to build the new expression.
1736 /// Subclasses may override this routine to provide different behavior.
John McCall8cd78132009-11-19 22:55:06 +00001737 OwningExprResult RebuildCXXDependentScopeMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001738 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001739 bool IsArrow,
1740 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001741 NestedNameSpecifier *Qualifier,
1742 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001743 NamedDecl *FirstQualifierInScope,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 DeclarationName Name,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00001745 SourceLocation MemberLoc,
John McCall10eae182009-11-30 22:42:35 +00001746 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001748 SS.setRange(QualifierRange);
1749 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001750
John McCall2d74de92009-12-01 22:10:20 +00001751 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1752 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001753 SS, FirstQualifierInScope,
1754 Name, MemberLoc, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001755 }
1756
John McCall10eae182009-11-30 22:42:35 +00001757 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001758 ///
1759 /// By default, performs semantic analysis to build the new expression.
1760 /// Subclasses may override this routine to provide different behavior.
John McCall10eae182009-11-30 22:42:35 +00001761 OwningExprResult RebuildUnresolvedMemberExpr(ExprArg BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001762 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001763 SourceLocation OperatorLoc,
1764 bool IsArrow,
1765 NestedNameSpecifier *Qualifier,
1766 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001767 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001768 LookupResult &R,
1769 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001770 CXXScopeSpec SS;
1771 SS.setRange(QualifierRange);
1772 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001773
John McCall2d74de92009-12-01 22:10:20 +00001774 return SemaRef.BuildMemberReferenceExpr(move(BaseE), BaseType,
1775 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001776 SS, FirstQualifierInScope,
1777 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001778 }
Mike Stump11289f42009-09-09 15:08:12 +00001779
Douglas Gregora16548e2009-08-11 05:31:07 +00001780 /// \brief Build a new Objective-C @encode expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 OwningExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001785 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001787 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001789 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001790
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001791 /// \brief Build a new Objective-C class message.
1792 OwningExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
1793 Selector Sel,
1794 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001795 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001796 MultiExprArg Args,
1797 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001798 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1799 ReceiverTypeInfo->getType(),
1800 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001801 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001802 move(Args));
1803 }
1804
1805 /// \brief Build a new Objective-C instance message.
1806 OwningExprResult RebuildObjCMessageExpr(ExprArg Receiver,
1807 Selector Sel,
1808 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001809 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001810 MultiExprArg Args,
1811 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001812 QualType ReceiverType = static_cast<Expr *>(Receiver.get())->getType();
1813 return SemaRef.BuildInstanceMessage(move(Receiver),
1814 ReceiverType,
1815 /*SuperLoc=*/SourceLocation(),
Douglas Gregorb5186b12010-04-22 17:01:48 +00001816 Sel, Method, LBracLoc, RBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001817 move(Args));
1818 }
1819
Douglas Gregord51d90d2010-04-26 20:11:03 +00001820 /// \brief Build a new Objective-C ivar reference expression.
1821 ///
1822 /// By default, performs semantic analysis to build the new expression.
1823 /// Subclasses may override this routine to provide different behavior.
1824 OwningExprResult RebuildObjCIvarRefExpr(ExprArg BaseArg, ObjCIvarDecl *Ivar,
1825 SourceLocation IvarLoc,
1826 bool IsArrow, bool IsFreeIvar) {
1827 // FIXME: We lose track of the IsFreeIvar bit.
1828 CXXScopeSpec SS;
1829 Expr *Base = BaseArg.takeAs<Expr>();
1830 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
1831 Sema::LookupMemberName);
1832 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1833 /*FIME:*/IvarLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001834 SS, DeclPtrTy(),
1835 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001836 if (Result.isInvalid())
1837 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001838
Douglas Gregord51d90d2010-04-26 20:11:03 +00001839 if (Result.get())
1840 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001841
1842 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001843 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001844 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001845 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001846 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001847 /*TemplateArgs=*/0);
1848 }
Douglas Gregor9faee212010-04-26 20:47:02 +00001849
1850 /// \brief Build a new Objective-C property reference expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001854 OwningExprResult RebuildObjCPropertyRefExpr(ExprArg BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00001855 ObjCPropertyDecl *Property,
1856 SourceLocation PropertyLoc) {
1857 CXXScopeSpec SS;
1858 Expr *Base = BaseArg.takeAs<Expr>();
1859 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
1860 Sema::LookupMemberName);
1861 bool IsArrow = false;
1862 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1863 /*FIME:*/PropertyLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001864 SS, DeclPtrTy(),
1865 false);
Douglas Gregor9faee212010-04-26 20:47:02 +00001866 if (Result.isInvalid())
1867 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001868
Douglas Gregor9faee212010-04-26 20:47:02 +00001869 if (Result.get())
1870 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001871
1872 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregor9faee212010-04-26 20:47:02 +00001873 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001874 /*FIXME:*/PropertyLoc, IsArrow,
1875 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00001876 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001877 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00001878 /*TemplateArgs=*/0);
1879 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001880
1881 /// \brief Build a new Objective-C implicit setter/getter reference
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001882 /// expression.
1883 ///
1884 /// By default, performs semantic analysis to build the new expression.
Alexis Hunta8136cc2010-05-05 15:23:54 +00001885 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00001886 OwningExprResult RebuildObjCImplicitSetterGetterRefExpr(
1887 ObjCMethodDecl *Getter,
1888 QualType T,
1889 ObjCMethodDecl *Setter,
1890 SourceLocation NameLoc,
1891 ExprArg Base) {
1892 // Since these expressions can only be value-dependent, we do not need to
1893 // perform semantic analysis again.
1894 return getSema().Owned(
1895 new (getSema().Context) ObjCImplicitSetterGetterRefExpr(Getter, T,
1896 Setter,
1897 NameLoc,
1898 Base.takeAs<Expr>()));
1899 }
1900
Douglas Gregord51d90d2010-04-26 20:11:03 +00001901 /// \brief Build a new Objective-C "isa" expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 OwningExprResult RebuildObjCIsaExpr(ExprArg BaseArg, SourceLocation IsaLoc,
1906 bool IsArrow) {
1907 CXXScopeSpec SS;
1908 Expr *Base = BaseArg.takeAs<Expr>();
1909 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
1910 Sema::LookupMemberName);
1911 OwningExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
1912 /*FIME:*/IsaLoc,
John McCalle9cccd82010-06-16 08:42:20 +00001913 SS, DeclPtrTy(),
1914 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00001915 if (Result.isInvalid())
1916 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001917
Douglas Gregord51d90d2010-04-26 20:11:03 +00001918 if (Result.get())
1919 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001920
1921 return getSema().BuildMemberReferenceExpr(getSema().Owned(Base),
Douglas Gregord51d90d2010-04-26 20:11:03 +00001922 Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00001923 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001924 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001925 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00001926 /*TemplateArgs=*/0);
1927 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001928
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 /// \brief Build a new shuffle vector expression.
1930 ///
1931 /// By default, performs semantic analysis to build the new expression.
1932 /// Subclasses may override this routine to provide different behavior.
1933 OwningExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
1934 MultiExprArg SubExprs,
1935 SourceLocation RParenLoc) {
1936 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00001937 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 = SemaRef.Context.Idents.get("__builtin_shufflevector");
1939 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
1940 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
1941 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00001942
Douglas Gregora16548e2009-08-11 05:31:07 +00001943 // Build a reference to the __builtin_shufflevector builtin
1944 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00001945 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
Douglas Gregored6c7442009-11-23 11:41:28 +00001947 BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001948 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00001949
1950 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 unsigned NumSubExprs = SubExprs.size();
1952 Expr **Subs = (Expr **)SubExprs.release();
1953 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
1954 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00001955 Builtin->getCallResultType(),
Douglas Gregora16548e2009-08-11 05:31:07 +00001956 RParenLoc);
1957 OwningExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00001958
Douglas Gregora16548e2009-08-11 05:31:07 +00001959 // Type-check the __builtin_shufflevector expression.
1960 OwningExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
1961 if (Result.isInvalid())
1962 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001963
Douglas Gregora16548e2009-08-11 05:31:07 +00001964 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00001965 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00001967};
Douglas Gregora16548e2009-08-11 05:31:07 +00001968
Douglas Gregorebe10102009-08-20 07:17:43 +00001969template<typename Derived>
1970Sema::OwningStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
1971 if (!S)
1972 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00001973
Douglas Gregorebe10102009-08-20 07:17:43 +00001974 switch (S->getStmtClass()) {
1975 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00001976
Douglas Gregorebe10102009-08-20 07:17:43 +00001977 // Transform individual statement nodes
1978#define STMT(Node, Parent) \
1979 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
1980#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00001981#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00001982
Douglas Gregorebe10102009-08-20 07:17:43 +00001983 // Transform expressions by calling TransformExpr.
1984#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00001985#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00001986#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00001987#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00001988 {
1989 Sema::OwningExprResult E = getDerived().TransformExpr(cast<Expr>(S));
1990 if (E.isInvalid())
1991 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00001992
Anders Carlssonafb2dad2009-12-16 02:09:40 +00001993 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E));
Douglas Gregorebe10102009-08-20 07:17:43 +00001994 }
Mike Stump11289f42009-09-09 15:08:12 +00001995 }
1996
Douglas Gregorebe10102009-08-20 07:17:43 +00001997 return SemaRef.Owned(S->Retain());
1998}
Mike Stump11289f42009-09-09 15:08:12 +00001999
2000
Douglas Gregore922c772009-08-04 22:27:00 +00002001template<typename Derived>
John McCall47f29ea2009-12-08 09:21:05 +00002002Sema::OwningExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 if (!E)
2004 return SemaRef.Owned(E);
2005
2006 switch (E->getStmtClass()) {
2007 case Stmt::NoStmtClass: break;
2008#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002009#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002010#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002011 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002012#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002013 }
2014
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 return SemaRef.Owned(E->Retain());
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002016}
2017
2018template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002019NestedNameSpecifier *
2020TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002021 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002022 QualType ObjectType,
2023 NamedDecl *FirstQualifierInScope) {
Douglas Gregor96ee7892009-08-31 21:41:48 +00002024 if (!NNS)
2025 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002026
Douglas Gregorebe10102009-08-20 07:17:43 +00002027 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002028 NestedNameSpecifier *Prefix = NNS->getPrefix();
2029 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002030 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002031 ObjectType,
2032 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002033 if (!Prefix)
2034 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002035
2036 // Clear out the object type and the first qualifier in scope; they only
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002037 // apply to the first element in the nested-name-specifier.
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002038 ObjectType = QualType();
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002039 FirstQualifierInScope = 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002040 }
Mike Stump11289f42009-09-09 15:08:12 +00002041
Douglas Gregor1135c352009-08-06 05:28:30 +00002042 switch (NNS->getKind()) {
2043 case NestedNameSpecifier::Identifier:
Mike Stump11289f42009-09-09 15:08:12 +00002044 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002045 "Identifier nested-name-specifier with no prefix or object type");
2046 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2047 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002048 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002049
2050 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002051 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002052 ObjectType,
2053 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002054
Douglas Gregor1135c352009-08-06 05:28:30 +00002055 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002056 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002057 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002058 getDerived().TransformDecl(Range.getBegin(),
2059 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002060 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002061 Prefix == NNS->getPrefix() &&
2062 NS == NNS->getAsNamespace())
2063 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002064
Douglas Gregor1135c352009-08-06 05:28:30 +00002065 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregor1135c352009-08-06 05:28:30 +00002068 case NestedNameSpecifier::Global:
2069 // There is no meaningful transformation that one could perform on the
2070 // global scope.
2071 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002072
Douglas Gregor1135c352009-08-06 05:28:30 +00002073 case NestedNameSpecifier::TypeSpecWithTemplate:
2074 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002075 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
Douglas Gregorfe17d252010-02-16 19:09:40 +00002076 QualType T = getDerived().TransformType(QualType(NNS->getAsType(), 0),
2077 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002078 if (T.isNull())
2079 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002080
Douglas Gregor1135c352009-08-06 05:28:30 +00002081 if (!getDerived().AlwaysRebuild() &&
2082 Prefix == NNS->getPrefix() &&
2083 T == QualType(NNS->getAsType(), 0))
2084 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002085
2086 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2087 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002088 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002089 }
2090 }
Mike Stump11289f42009-09-09 15:08:12 +00002091
Douglas Gregor1135c352009-08-06 05:28:30 +00002092 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002093 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002094}
2095
2096template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002097DeclarationName
Douglas Gregorf816bd72009-09-03 22:13:48 +00002098TreeTransform<Derived>::TransformDeclarationName(DeclarationName Name,
Douglas Gregorc59e5612009-10-19 22:04:39 +00002099 SourceLocation Loc,
2100 QualType ObjectType) {
Douglas Gregorf816bd72009-09-03 22:13:48 +00002101 if (!Name)
2102 return Name;
2103
2104 switch (Name.getNameKind()) {
2105 case DeclarationName::Identifier:
2106 case DeclarationName::ObjCZeroArgSelector:
2107 case DeclarationName::ObjCOneArgSelector:
2108 case DeclarationName::ObjCMultiArgSelector:
2109 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002110 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002111 case DeclarationName::CXXUsingDirective:
2112 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002113
Douglas Gregorf816bd72009-09-03 22:13:48 +00002114 case DeclarationName::CXXConstructorName:
2115 case DeclarationName::CXXDestructorName:
2116 case DeclarationName::CXXConversionFunctionName: {
2117 TemporaryBase Rebase(*this, Loc, Name);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002118 QualType T = getDerived().TransformType(Name.getCXXNameType(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002119 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00002120 if (T.isNull())
2121 return DeclarationName();
Mike Stump11289f42009-09-09 15:08:12 +00002122
Douglas Gregorf816bd72009-09-03 22:13:48 +00002123 return SemaRef.Context.DeclarationNames.getCXXSpecialName(
Mike Stump11289f42009-09-09 15:08:12 +00002124 Name.getNameKind(),
Douglas Gregorf816bd72009-09-03 22:13:48 +00002125 SemaRef.Context.getCanonicalType(T));
Douglas Gregorf816bd72009-09-03 22:13:48 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127 }
2128
Douglas Gregorf816bd72009-09-03 22:13:48 +00002129 return DeclarationName();
2130}
2131
2132template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002133TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002134TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
2135 QualType ObjectType) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002136 SourceLocation Loc = getDerived().getBaseLocation();
2137
Douglas Gregor71dc5092009-08-06 06:41:21 +00002138 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002139 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002140 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002141 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2142 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002143 if (!NNS)
2144 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002145
Douglas Gregor71dc5092009-08-06 06:41:21 +00002146 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002147 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002148 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002149 if (!TransTemplate)
2150 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002151
Douglas Gregor71dc5092009-08-06 06:41:21 +00002152 if (!getDerived().AlwaysRebuild() &&
2153 NNS == QTN->getQualifier() &&
2154 TransTemplate == Template)
2155 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002156
Douglas Gregor71dc5092009-08-06 06:41:21 +00002157 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2158 TransTemplate);
2159 }
Mike Stump11289f42009-09-09 15:08:12 +00002160
John McCalle66edc12009-11-24 19:00:30 +00002161 // These should be getting filtered out before they make it into the AST.
2162 assert(false && "overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002163 }
Mike Stump11289f42009-09-09 15:08:12 +00002164
Douglas Gregor71dc5092009-08-06 06:41:21 +00002165 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002166 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002167 = getDerived().TransformNestedNameSpecifier(DTN->getQualifier(),
Douglas Gregorfe17d252010-02-16 19:09:40 +00002168 /*FIXME:*/SourceRange(getDerived().getBaseLocation()),
2169 ObjectType);
Douglas Gregor308047d2009-09-09 00:23:06 +00002170 if (!NNS && DTN->getQualifier())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002171 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002172
Douglas Gregor71dc5092009-08-06 06:41:21 +00002173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002174 NNS == DTN->getQualifier() &&
2175 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002176 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002177
Douglas Gregor71395fa2009-11-04 00:56:37 +00002178 if (DTN->isIdentifier())
Alexis Hunta8136cc2010-05-05 15:23:54 +00002179 return getDerived().RebuildTemplateName(NNS, *DTN->getIdentifier(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002180 ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002181
2182 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002183 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002184 }
Mike Stump11289f42009-09-09 15:08:12 +00002185
Douglas Gregor71dc5092009-08-06 06:41:21 +00002186 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002187 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002188 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002189 if (!TransTemplate)
2190 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002191
Douglas Gregor71dc5092009-08-06 06:41:21 +00002192 if (!getDerived().AlwaysRebuild() &&
2193 TransTemplate == Template)
2194 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002195
Douglas Gregor71dc5092009-08-06 06:41:21 +00002196 return TemplateName(TransTemplate);
2197 }
Mike Stump11289f42009-09-09 15:08:12 +00002198
John McCalle66edc12009-11-24 19:00:30 +00002199 // These should be getting filtered out before they reach the AST.
2200 assert(false && "overloaded function decl survived to here");
2201 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002202}
2203
2204template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002205void TreeTransform<Derived>::InventTemplateArgumentLoc(
2206 const TemplateArgument &Arg,
2207 TemplateArgumentLoc &Output) {
2208 SourceLocation Loc = getDerived().getBaseLocation();
2209 switch (Arg.getKind()) {
2210 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002211 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002212 break;
2213
2214 case TemplateArgument::Type:
2215 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002216 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002217
John McCall0ad16662009-10-29 08:12:44 +00002218 break;
2219
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002220 case TemplateArgument::Template:
2221 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2222 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002223
John McCall0ad16662009-10-29 08:12:44 +00002224 case TemplateArgument::Expression:
2225 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2226 break;
2227
2228 case TemplateArgument::Declaration:
2229 case TemplateArgument::Integral:
2230 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002231 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002232 break;
2233 }
2234}
2235
2236template<typename Derived>
2237bool TreeTransform<Derived>::TransformTemplateArgument(
2238 const TemplateArgumentLoc &Input,
2239 TemplateArgumentLoc &Output) {
2240 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002241 switch (Arg.getKind()) {
2242 case TemplateArgument::Null:
2243 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002244 Output = Input;
2245 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002246
Douglas Gregore922c772009-08-04 22:27:00 +00002247 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002248 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002249 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002250 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002251
2252 DI = getDerived().TransformType(DI);
2253 if (!DI) return true;
2254
2255 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2256 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002257 }
Mike Stump11289f42009-09-09 15:08:12 +00002258
Douglas Gregore922c772009-08-04 22:27:00 +00002259 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002260 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002261 DeclarationName Name;
2262 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2263 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002264 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002265 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002266 if (!D) return true;
2267
John McCall0d07eb32009-10-29 18:45:58 +00002268 Expr *SourceExpr = Input.getSourceDeclExpression();
2269 if (SourceExpr) {
2270 EnterExpressionEvaluationContext Unevaluated(getSema(),
2271 Action::Unevaluated);
2272 Sema::OwningExprResult E = getDerived().TransformExpr(SourceExpr);
2273 if (E.isInvalid())
2274 SourceExpr = NULL;
2275 else {
2276 SourceExpr = E.takeAs<Expr>();
2277 SourceExpr->Retain();
2278 }
2279 }
2280
2281 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002282 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002283 }
Mike Stump11289f42009-09-09 15:08:12 +00002284
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002285 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002286 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002287 TemplateName Template
2288 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2289 if (Template.isNull())
2290 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002291
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002292 Output = TemplateArgumentLoc(TemplateArgument(Template),
2293 Input.getTemplateQualifierRange(),
2294 Input.getTemplateNameLoc());
2295 return false;
2296 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002297
Douglas Gregore922c772009-08-04 22:27:00 +00002298 case TemplateArgument::Expression: {
2299 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002300 EnterExpressionEvaluationContext Unevaluated(getSema(),
Douglas Gregore922c772009-08-04 22:27:00 +00002301 Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002302
John McCall0ad16662009-10-29 08:12:44 +00002303 Expr *InputExpr = Input.getSourceExpression();
2304 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2305
2306 Sema::OwningExprResult E
2307 = getDerived().TransformExpr(InputExpr);
2308 if (E.isInvalid()) return true;
2309
2310 Expr *ETaken = E.takeAs<Expr>();
John McCall0d07eb32009-10-29 18:45:58 +00002311 ETaken->Retain();
John McCall0ad16662009-10-29 08:12:44 +00002312 Output = TemplateArgumentLoc(TemplateArgument(ETaken), ETaken);
2313 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002314 }
Mike Stump11289f42009-09-09 15:08:12 +00002315
Douglas Gregore922c772009-08-04 22:27:00 +00002316 case TemplateArgument::Pack: {
2317 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2318 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002319 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002320 AEnd = Arg.pack_end();
2321 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002322
John McCall0ad16662009-10-29 08:12:44 +00002323 // FIXME: preserve source information here when we start
2324 // caring about parameter packs.
2325
John McCall0d07eb32009-10-29 18:45:58 +00002326 TemplateArgumentLoc InputArg;
2327 TemplateArgumentLoc OutputArg;
2328 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2329 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002330 return true;
2331
John McCall0d07eb32009-10-29 18:45:58 +00002332 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002333 }
2334 TemplateArgument Result;
Mike Stump11289f42009-09-09 15:08:12 +00002335 Result.setArgumentPack(TransformedArgs.data(), TransformedArgs.size(),
Douglas Gregore922c772009-08-04 22:27:00 +00002336 true);
John McCall0d07eb32009-10-29 18:45:58 +00002337 Output = TemplateArgumentLoc(Result, Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002338 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002339 }
2340 }
Mike Stump11289f42009-09-09 15:08:12 +00002341
Douglas Gregore922c772009-08-04 22:27:00 +00002342 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002343 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002344}
2345
Douglas Gregord6ff3322009-08-04 16:50:30 +00002346//===----------------------------------------------------------------------===//
2347// Type transformation
2348//===----------------------------------------------------------------------===//
2349
2350template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00002351QualType TreeTransform<Derived>::TransformType(QualType T,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002352 QualType ObjectType) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002353 if (getDerived().AlreadyTransformed(T))
2354 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002355
John McCall550e0c22009-10-21 00:40:46 +00002356 // Temporary workaround. All of these transformations should
2357 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002358 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002359 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002360
Douglas Gregorfe17d252010-02-16 19:09:40 +00002361 TypeSourceInfo *NewDI = getDerived().TransformType(DI, ObjectType);
John McCall8ccfcb52009-09-24 19:53:00 +00002362
John McCall550e0c22009-10-21 00:40:46 +00002363 if (!NewDI)
2364 return QualType();
2365
2366 return NewDI->getType();
2367}
2368
2369template<typename Derived>
Douglas Gregorfe17d252010-02-16 19:09:40 +00002370TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI,
2371 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002372 if (getDerived().AlreadyTransformed(DI->getType()))
2373 return DI;
2374
2375 TypeLocBuilder TLB;
2376
2377 TypeLoc TL = DI->getTypeLoc();
2378 TLB.reserve(TL.getFullDataSize());
2379
Douglas Gregorfe17d252010-02-16 19:09:40 +00002380 QualType Result = getDerived().TransformType(TLB, TL, ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002381 if (Result.isNull())
2382 return 0;
2383
John McCallbcd03502009-12-07 02:54:59 +00002384 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002385}
2386
2387template<typename Derived>
2388QualType
Douglas Gregorfe17d252010-02-16 19:09:40 +00002389TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T,
2390 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002391 switch (T.getTypeLocClass()) {
2392#define ABSTRACT_TYPELOC(CLASS, PARENT)
2393#define TYPELOC(CLASS, PARENT) \
2394 case TypeLoc::CLASS: \
Douglas Gregorfe17d252010-02-16 19:09:40 +00002395 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T), \
2396 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002397#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002400 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002401 return QualType();
2402}
2403
2404/// FIXME: By default, this routine adds type qualifiers only to types
2405/// that can have qualifiers, and silently suppresses those qualifiers
2406/// that are not permitted (e.g., qualifiers on reference or function
2407/// types). This is the right thing for template instantiation, but
2408/// probably not for other clients.
2409template<typename Derived>
2410QualType
2411TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002412 QualifiedTypeLoc T,
2413 QualType ObjectType) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002414 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002415
Douglas Gregorfe17d252010-02-16 19:09:40 +00002416 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc(),
2417 ObjectType);
John McCall550e0c22009-10-21 00:40:46 +00002418 if (Result.isNull())
2419 return QualType();
2420
2421 // Silently suppress qualifiers if the result type can't be qualified.
2422 // FIXME: this is the right thing for template instantiation, but
2423 // probably not for other clients.
2424 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002425 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002426
John McCallcb0f89a2010-06-05 06:41:15 +00002427 if (!Quals.empty()) {
2428 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2429 TLB.push<QualifiedTypeLoc>(Result);
2430 // No location information to preserve.
2431 }
John McCall550e0c22009-10-21 00:40:46 +00002432
2433 return Result;
2434}
2435
2436template <class TyLoc> static inline
2437QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
2438 TyLoc NewT = TLB.push<TyLoc>(T.getType());
2439 NewT.setNameLoc(T.getNameLoc());
2440 return T.getType();
2441}
2442
John McCall550e0c22009-10-21 00:40:46 +00002443template<typename Derived>
2444QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002445 BuiltinTypeLoc T,
2446 QualType ObjectType) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00002447 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
2448 NewT.setBuiltinLoc(T.getBuiltinLoc());
2449 if (T.needsExtraLocalData())
2450 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
2451 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002452}
Mike Stump11289f42009-09-09 15:08:12 +00002453
Douglas Gregord6ff3322009-08-04 16:50:30 +00002454template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002455QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002456 ComplexTypeLoc T,
2457 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002458 // FIXME: recurse?
2459 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002460}
Mike Stump11289f42009-09-09 15:08:12 +00002461
Douglas Gregord6ff3322009-08-04 16:50:30 +00002462template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002463QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002464 PointerTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002465 QualType ObjectType) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002466 QualType PointeeType
2467 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002468 if (PointeeType.isNull())
2469 return QualType();
2470
2471 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00002472 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002473 // A dependent pointer type 'T *' has is being transformed such
2474 // that an Objective-C class type is being replaced for 'T'. The
2475 // resulting pointer type is an ObjCObjectPointerType, not a
2476 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00002477 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002478
John McCall8b07ec22010-05-15 11:32:37 +00002479 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
2480 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002481 return Result;
2482 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002483
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002484 if (getDerived().AlwaysRebuild() ||
2485 PointeeType != TL.getPointeeLoc().getType()) {
2486 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
2487 if (Result.isNull())
2488 return QualType();
2489 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002490
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002491 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
2492 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002493 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002494}
Mike Stump11289f42009-09-09 15:08:12 +00002495
2496template<typename Derived>
2497QualType
John McCall550e0c22009-10-21 00:40:46 +00002498TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002499 BlockPointerTypeLoc TL,
2500 QualType ObjectType) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00002501 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00002502 = getDerived().TransformType(TLB, TL.getPointeeLoc());
2503 if (PointeeType.isNull())
2504 return QualType();
2505
2506 QualType Result = TL.getType();
2507 if (getDerived().AlwaysRebuild() ||
2508 PointeeType != TL.getPointeeLoc().getType()) {
2509 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00002510 TL.getSigilLoc());
2511 if (Result.isNull())
2512 return QualType();
2513 }
2514
Douglas Gregor049211a2010-04-22 16:50:51 +00002515 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00002516 NewT.setSigilLoc(TL.getSigilLoc());
2517 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002518}
2519
John McCall70dd5f62009-10-30 00:06:24 +00002520/// Transforms a reference type. Note that somewhat paradoxically we
2521/// don't care whether the type itself is an l-value type or an r-value
2522/// type; we only care if the type was *written* as an l-value type
2523/// or an r-value type.
2524template<typename Derived>
2525QualType
2526TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002527 ReferenceTypeLoc TL,
2528 QualType ObjectType) {
John McCall70dd5f62009-10-30 00:06:24 +00002529 const ReferenceType *T = TL.getTypePtr();
2530
2531 // Note that this works with the pointee-as-written.
2532 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
2533 if (PointeeType.isNull())
2534 return QualType();
2535
2536 QualType Result = TL.getType();
2537 if (getDerived().AlwaysRebuild() ||
2538 PointeeType != T->getPointeeTypeAsWritten()) {
2539 Result = getDerived().RebuildReferenceType(PointeeType,
2540 T->isSpelledAsLValue(),
2541 TL.getSigilLoc());
2542 if (Result.isNull())
2543 return QualType();
2544 }
2545
2546 // r-value references can be rebuilt as l-value references.
2547 ReferenceTypeLoc NewTL;
2548 if (isa<LValueReferenceType>(Result))
2549 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
2550 else
2551 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
2552 NewTL.setSigilLoc(TL.getSigilLoc());
2553
2554 return Result;
2555}
2556
Mike Stump11289f42009-09-09 15:08:12 +00002557template<typename Derived>
2558QualType
John McCall550e0c22009-10-21 00:40:46 +00002559TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002560 LValueReferenceTypeLoc TL,
2561 QualType ObjectType) {
2562 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002563}
2564
Mike Stump11289f42009-09-09 15:08:12 +00002565template<typename Derived>
2566QualType
John McCall550e0c22009-10-21 00:40:46 +00002567TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002568 RValueReferenceTypeLoc TL,
2569 QualType ObjectType) {
2570 return TransformReferenceType(TLB, TL, ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002571}
Mike Stump11289f42009-09-09 15:08:12 +00002572
Douglas Gregord6ff3322009-08-04 16:50:30 +00002573template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002574QualType
John McCall550e0c22009-10-21 00:40:46 +00002575TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002576 MemberPointerTypeLoc TL,
2577 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002578 MemberPointerType *T = TL.getTypePtr();
2579
2580 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002581 if (PointeeType.isNull())
2582 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002583
John McCall550e0c22009-10-21 00:40:46 +00002584 // TODO: preserve source information for this.
2585 QualType ClassType
2586 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00002587 if (ClassType.isNull())
2588 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002589
John McCall550e0c22009-10-21 00:40:46 +00002590 QualType Result = TL.getType();
2591 if (getDerived().AlwaysRebuild() ||
2592 PointeeType != T->getPointeeType() ||
2593 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00002594 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
2595 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00002596 if (Result.isNull())
2597 return QualType();
2598 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00002599
John McCall550e0c22009-10-21 00:40:46 +00002600 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
2601 NewTL.setSigilLoc(TL.getSigilLoc());
2602
2603 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002604}
2605
Mike Stump11289f42009-09-09 15:08:12 +00002606template<typename Derived>
2607QualType
John McCall550e0c22009-10-21 00:40:46 +00002608TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002609 ConstantArrayTypeLoc TL,
2610 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002611 ConstantArrayType *T = TL.getTypePtr();
2612 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002613 if (ElementType.isNull())
2614 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002615
John McCall550e0c22009-10-21 00:40:46 +00002616 QualType Result = TL.getType();
2617 if (getDerived().AlwaysRebuild() ||
2618 ElementType != T->getElementType()) {
2619 Result = getDerived().RebuildConstantArrayType(ElementType,
2620 T->getSizeModifier(),
2621 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00002622 T->getIndexTypeCVRQualifiers(),
2623 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002624 if (Result.isNull())
2625 return QualType();
2626 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002627
John McCall550e0c22009-10-21 00:40:46 +00002628 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
2629 NewTL.setLBracketLoc(TL.getLBracketLoc());
2630 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002631
John McCall550e0c22009-10-21 00:40:46 +00002632 Expr *Size = TL.getSizeExpr();
2633 if (Size) {
2634 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2635 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
2636 }
2637 NewTL.setSizeExpr(Size);
2638
2639 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002640}
Mike Stump11289f42009-09-09 15:08:12 +00002641
Douglas Gregord6ff3322009-08-04 16:50:30 +00002642template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002643QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00002644 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002645 IncompleteArrayTypeLoc TL,
2646 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002647 IncompleteArrayType *T = TL.getTypePtr();
2648 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00002649 if (ElementType.isNull())
2650 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002651
John McCall550e0c22009-10-21 00:40:46 +00002652 QualType Result = TL.getType();
2653 if (getDerived().AlwaysRebuild() ||
2654 ElementType != T->getElementType()) {
2655 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002656 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00002657 T->getIndexTypeCVRQualifiers(),
2658 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002659 if (Result.isNull())
2660 return QualType();
2661 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002662
John McCall550e0c22009-10-21 00:40:46 +00002663 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
2664 NewTL.setLBracketLoc(TL.getLBracketLoc());
2665 NewTL.setRBracketLoc(TL.getRBracketLoc());
2666 NewTL.setSizeExpr(0);
2667
2668 return Result;
2669}
2670
2671template<typename Derived>
2672QualType
2673TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002674 VariableArrayTypeLoc TL,
2675 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002676 VariableArrayType *T = TL.getTypePtr();
2677 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2678 if (ElementType.isNull())
2679 return QualType();
2680
2681 // Array bounds are not potentially evaluated contexts
2682 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2683
2684 Sema::OwningExprResult SizeResult
2685 = getDerived().TransformExpr(T->getSizeExpr());
2686 if (SizeResult.isInvalid())
2687 return QualType();
2688
2689 Expr *Size = static_cast<Expr*>(SizeResult.get());
2690
2691 QualType Result = TL.getType();
2692 if (getDerived().AlwaysRebuild() ||
2693 ElementType != T->getElementType() ||
2694 Size != T->getSizeExpr()) {
2695 Result = getDerived().RebuildVariableArrayType(ElementType,
2696 T->getSizeModifier(),
2697 move(SizeResult),
2698 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002699 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002700 if (Result.isNull())
2701 return QualType();
2702 }
2703 else SizeResult.take();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002704
John McCall550e0c22009-10-21 00:40:46 +00002705 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
2706 NewTL.setLBracketLoc(TL.getLBracketLoc());
2707 NewTL.setRBracketLoc(TL.getRBracketLoc());
2708 NewTL.setSizeExpr(Size);
2709
2710 return Result;
2711}
2712
2713template<typename Derived>
2714QualType
2715TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002716 DependentSizedArrayTypeLoc TL,
2717 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002718 DependentSizedArrayType *T = TL.getTypePtr();
2719 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
2720 if (ElementType.isNull())
2721 return QualType();
2722
2723 // Array bounds are not potentially evaluated contexts
2724 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2725
2726 Sema::OwningExprResult SizeResult
2727 = getDerived().TransformExpr(T->getSizeExpr());
2728 if (SizeResult.isInvalid())
2729 return QualType();
2730
2731 Expr *Size = static_cast<Expr*>(SizeResult.get());
2732
2733 QualType Result = TL.getType();
2734 if (getDerived().AlwaysRebuild() ||
2735 ElementType != T->getElementType() ||
2736 Size != T->getSizeExpr()) {
2737 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
2738 T->getSizeModifier(),
2739 move(SizeResult),
2740 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00002741 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00002742 if (Result.isNull())
2743 return QualType();
2744 }
2745 else SizeResult.take();
2746
2747 // We might have any sort of array type now, but fortunately they
2748 // all have the same location layout.
2749 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
2750 NewTL.setLBracketLoc(TL.getLBracketLoc());
2751 NewTL.setRBracketLoc(TL.getRBracketLoc());
2752 NewTL.setSizeExpr(Size);
2753
2754 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002755}
Mike Stump11289f42009-09-09 15:08:12 +00002756
2757template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00002758QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00002759 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002760 DependentSizedExtVectorTypeLoc TL,
2761 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002762 DependentSizedExtVectorType *T = TL.getTypePtr();
2763
2764 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00002765 QualType ElementType = getDerived().TransformType(T->getElementType());
2766 if (ElementType.isNull())
2767 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002768
Douglas Gregore922c772009-08-04 22:27:00 +00002769 // Vector sizes are not potentially evaluated contexts
2770 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
2771
Douglas Gregord6ff3322009-08-04 16:50:30 +00002772 Sema::OwningExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
2773 if (Size.isInvalid())
2774 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00002775
John McCall550e0c22009-10-21 00:40:46 +00002776 QualType Result = TL.getType();
2777 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00002778 ElementType != T->getElementType() ||
2779 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00002780 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00002781 move(Size),
2782 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00002783 if (Result.isNull())
2784 return QualType();
2785 }
2786 else Size.take();
2787
2788 // Result might be dependent or not.
2789 if (isa<DependentSizedExtVectorType>(Result)) {
2790 DependentSizedExtVectorTypeLoc NewTL
2791 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
2792 NewTL.setNameLoc(TL.getNameLoc());
2793 } else {
2794 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2795 NewTL.setNameLoc(TL.getNameLoc());
2796 }
2797
2798 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002799}
Mike Stump11289f42009-09-09 15:08:12 +00002800
2801template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002802QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002803 VectorTypeLoc TL,
2804 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002805 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00002806 QualType ElementType = getDerived().TransformType(T->getElementType());
2807 if (ElementType.isNull())
2808 return QualType();
2809
John McCall550e0c22009-10-21 00:40:46 +00002810 QualType Result = TL.getType();
2811 if (getDerived().AlwaysRebuild() ||
2812 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00002813 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Chris Lattner37141f42010-06-23 06:00:24 +00002814 T->getAltiVecSpecific());
John McCall550e0c22009-10-21 00:40:46 +00002815 if (Result.isNull())
2816 return QualType();
2817 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002818
John McCall550e0c22009-10-21 00:40:46 +00002819 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
2820 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00002821
John McCall550e0c22009-10-21 00:40:46 +00002822 return Result;
2823}
2824
2825template<typename Derived>
2826QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002827 ExtVectorTypeLoc TL,
2828 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002829 VectorType *T = TL.getTypePtr();
2830 QualType ElementType = getDerived().TransformType(T->getElementType());
2831 if (ElementType.isNull())
2832 return QualType();
2833
2834 QualType Result = TL.getType();
2835 if (getDerived().AlwaysRebuild() ||
2836 ElementType != T->getElementType()) {
2837 Result = getDerived().RebuildExtVectorType(ElementType,
2838 T->getNumElements(),
2839 /*FIXME*/ SourceLocation());
2840 if (Result.isNull())
2841 return QualType();
2842 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002843
John McCall550e0c22009-10-21 00:40:46 +00002844 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
2845 NewTL.setNameLoc(TL.getNameLoc());
2846
2847 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002848}
Mike Stump11289f42009-09-09 15:08:12 +00002849
2850template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00002851ParmVarDecl *
2852TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
2853 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
2854 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
2855 if (!NewDI)
2856 return 0;
2857
2858 if (NewDI == OldDI)
2859 return OldParm;
2860 else
2861 return ParmVarDecl::Create(SemaRef.Context,
2862 OldParm->getDeclContext(),
2863 OldParm->getLocation(),
2864 OldParm->getIdentifier(),
2865 NewDI->getType(),
2866 NewDI,
2867 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00002868 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00002869 /* DefArg */ NULL);
2870}
2871
2872template<typename Derived>
2873bool TreeTransform<Derived>::
2874 TransformFunctionTypeParams(FunctionProtoTypeLoc TL,
2875 llvm::SmallVectorImpl<QualType> &PTypes,
2876 llvm::SmallVectorImpl<ParmVarDecl*> &PVars) {
2877 FunctionProtoType *T = TL.getTypePtr();
2878
2879 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
2880 ParmVarDecl *OldParm = TL.getArg(i);
2881
2882 QualType NewType;
2883 ParmVarDecl *NewParm;
2884
2885 if (OldParm) {
John McCall58f10c32010-03-11 09:03:00 +00002886 NewParm = getDerived().TransformFunctionTypeParam(OldParm);
2887 if (!NewParm)
2888 return true;
2889 NewType = NewParm->getType();
2890
2891 // Deal with the possibility that we don't have a parameter
2892 // declaration for this parameter.
2893 } else {
2894 NewParm = 0;
2895
2896 QualType OldType = T->getArgType(i);
2897 NewType = getDerived().TransformType(OldType);
2898 if (NewType.isNull())
2899 return true;
2900 }
2901
2902 PTypes.push_back(NewType);
2903 PVars.push_back(NewParm);
2904 }
2905
2906 return false;
2907}
2908
2909template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002910QualType
John McCall550e0c22009-10-21 00:40:46 +00002911TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002912 FunctionProtoTypeLoc TL,
2913 QualType ObjectType) {
Douglas Gregor14cf7522010-04-30 18:55:50 +00002914 // Transform the parameters. We do this first for the benefit of template
2915 // instantiations, so that the ParmVarDecls get/ placed into the template
2916 // instantiation scope before we transform the function type.
Douglas Gregord6ff3322009-08-04 16:50:30 +00002917 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00002918 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall58f10c32010-03-11 09:03:00 +00002919 if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls))
2920 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002921
Douglas Gregor14cf7522010-04-30 18:55:50 +00002922 FunctionProtoType *T = TL.getTypePtr();
2923 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2924 if (ResultType.isNull())
2925 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002926
John McCall550e0c22009-10-21 00:40:46 +00002927 QualType Result = TL.getType();
2928 if (getDerived().AlwaysRebuild() ||
2929 ResultType != T->getResultType() ||
2930 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
2931 Result = getDerived().RebuildFunctionProtoType(ResultType,
2932 ParamTypes.data(),
2933 ParamTypes.size(),
2934 T->isVariadic(),
2935 T->getTypeQuals());
2936 if (Result.isNull())
2937 return QualType();
2938 }
Mike Stump11289f42009-09-09 15:08:12 +00002939
John McCall550e0c22009-10-21 00:40:46 +00002940 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
2941 NewTL.setLParenLoc(TL.getLParenLoc());
2942 NewTL.setRParenLoc(TL.getRParenLoc());
2943 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
2944 NewTL.setArg(i, ParamDecls[i]);
2945
2946 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002947}
Mike Stump11289f42009-09-09 15:08:12 +00002948
Douglas Gregord6ff3322009-08-04 16:50:30 +00002949template<typename Derived>
2950QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00002951 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002952 FunctionNoProtoTypeLoc TL,
2953 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002954 FunctionNoProtoType *T = TL.getTypePtr();
2955 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
2956 if (ResultType.isNull())
2957 return QualType();
2958
2959 QualType Result = TL.getType();
2960 if (getDerived().AlwaysRebuild() ||
2961 ResultType != T->getResultType())
2962 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
2963
2964 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
2965 NewTL.setLParenLoc(TL.getLParenLoc());
2966 NewTL.setRParenLoc(TL.getRParenLoc());
2967
2968 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00002969}
Mike Stump11289f42009-09-09 15:08:12 +00002970
John McCallb96ec562009-12-04 22:46:56 +00002971template<typename Derived> QualType
2972TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002973 UnresolvedUsingTypeLoc TL,
2974 QualType ObjectType) {
John McCallb96ec562009-12-04 22:46:56 +00002975 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002976 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00002977 if (!D)
2978 return QualType();
2979
2980 QualType Result = TL.getType();
2981 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
2982 Result = getDerived().RebuildUnresolvedUsingType(D);
2983 if (Result.isNull())
2984 return QualType();
2985 }
2986
2987 // We might get an arbitrary type spec type back. We should at
2988 // least always get a type spec type, though.
2989 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
2990 NewTL.setNameLoc(TL.getNameLoc());
2991
2992 return Result;
2993}
2994
Douglas Gregord6ff3322009-08-04 16:50:30 +00002995template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00002996QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00002997 TypedefTypeLoc TL,
2998 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00002999 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003000 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003001 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3002 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003003 if (!Typedef)
3004 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003005
John McCall550e0c22009-10-21 00:40:46 +00003006 QualType Result = TL.getType();
3007 if (getDerived().AlwaysRebuild() ||
3008 Typedef != T->getDecl()) {
3009 Result = getDerived().RebuildTypedefType(Typedef);
3010 if (Result.isNull())
3011 return QualType();
3012 }
Mike Stump11289f42009-09-09 15:08:12 +00003013
John McCall550e0c22009-10-21 00:40:46 +00003014 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3015 NewTL.setNameLoc(TL.getNameLoc());
3016
3017 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003018}
Mike Stump11289f42009-09-09 15:08:12 +00003019
Douglas Gregord6ff3322009-08-04 16:50:30 +00003020template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003021QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003022 TypeOfExprTypeLoc TL,
3023 QualType ObjectType) {
Douglas Gregore922c772009-08-04 22:27:00 +00003024 // typeof expressions are not potentially evaluated contexts
3025 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003026
John McCalle8595032010-01-13 20:03:27 +00003027 Sema::OwningExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003028 if (E.isInvalid())
3029 return QualType();
3030
John McCall550e0c22009-10-21 00:40:46 +00003031 QualType Result = TL.getType();
3032 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003033 E.get() != TL.getUnderlyingExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003034 Result = getDerived().RebuildTypeOfExprType(move(E));
3035 if (Result.isNull())
3036 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003037 }
John McCall550e0c22009-10-21 00:40:46 +00003038 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003039
John McCall550e0c22009-10-21 00:40:46 +00003040 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003041 NewTL.setTypeofLoc(TL.getTypeofLoc());
3042 NewTL.setLParenLoc(TL.getLParenLoc());
3043 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003044
3045 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003046}
Mike Stump11289f42009-09-09 15:08:12 +00003047
3048template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003049QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003050 TypeOfTypeLoc TL,
3051 QualType ObjectType) {
John McCalle8595032010-01-13 20:03:27 +00003052 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3053 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3054 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003055 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003056
John McCall550e0c22009-10-21 00:40:46 +00003057 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003058 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3059 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003060 if (Result.isNull())
3061 return QualType();
3062 }
Mike Stump11289f42009-09-09 15:08:12 +00003063
John McCall550e0c22009-10-21 00:40:46 +00003064 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003065 NewTL.setTypeofLoc(TL.getTypeofLoc());
3066 NewTL.setLParenLoc(TL.getLParenLoc());
3067 NewTL.setRParenLoc(TL.getRParenLoc());
3068 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003069
3070 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003071}
Mike Stump11289f42009-09-09 15:08:12 +00003072
3073template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003074QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003075 DecltypeTypeLoc TL,
3076 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003077 DecltypeType *T = TL.getTypePtr();
3078
Douglas Gregore922c772009-08-04 22:27:00 +00003079 // decltype expressions are not potentially evaluated contexts
3080 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003081
Douglas Gregord6ff3322009-08-04 16:50:30 +00003082 Sema::OwningExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
3083 if (E.isInvalid())
3084 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003085
John McCall550e0c22009-10-21 00:40:46 +00003086 QualType Result = TL.getType();
3087 if (getDerived().AlwaysRebuild() ||
3088 E.get() != T->getUnderlyingExpr()) {
3089 Result = getDerived().RebuildDecltypeType(move(E));
3090 if (Result.isNull())
3091 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003092 }
John McCall550e0c22009-10-21 00:40:46 +00003093 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003094
John McCall550e0c22009-10-21 00:40:46 +00003095 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3096 NewTL.setNameLoc(TL.getNameLoc());
3097
3098 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003099}
3100
3101template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003102QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003103 RecordTypeLoc TL,
3104 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003105 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003106 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003107 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3108 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003109 if (!Record)
3110 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 QualType Result = TL.getType();
3113 if (getDerived().AlwaysRebuild() ||
3114 Record != T->getDecl()) {
3115 Result = getDerived().RebuildRecordType(Record);
3116 if (Result.isNull())
3117 return QualType();
3118 }
Mike Stump11289f42009-09-09 15:08:12 +00003119
John McCall550e0c22009-10-21 00:40:46 +00003120 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3121 NewTL.setNameLoc(TL.getNameLoc());
3122
3123 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003124}
Mike Stump11289f42009-09-09 15:08:12 +00003125
3126template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003127QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003128 EnumTypeLoc TL,
3129 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003130 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003131 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003132 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3133 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003134 if (!Enum)
3135 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003136
John McCall550e0c22009-10-21 00:40:46 +00003137 QualType Result = TL.getType();
3138 if (getDerived().AlwaysRebuild() ||
3139 Enum != T->getDecl()) {
3140 Result = getDerived().RebuildEnumType(Enum);
3141 if (Result.isNull())
3142 return QualType();
3143 }
Mike Stump11289f42009-09-09 15:08:12 +00003144
John McCall550e0c22009-10-21 00:40:46 +00003145 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3146 NewTL.setNameLoc(TL.getNameLoc());
3147
3148 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003149}
John McCallfcc33b02009-09-05 00:15:47 +00003150
John McCalle78aac42010-03-10 03:28:59 +00003151template<typename Derived>
3152QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3153 TypeLocBuilder &TLB,
3154 InjectedClassNameTypeLoc TL,
3155 QualType ObjectType) {
3156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3157 TL.getTypePtr()->getDecl());
3158 if (!D) return QualType();
3159
3160 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3161 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3162 return T;
3163}
3164
Mike Stump11289f42009-09-09 15:08:12 +00003165
Douglas Gregord6ff3322009-08-04 16:50:30 +00003166template<typename Derived>
3167QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003168 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003169 TemplateTypeParmTypeLoc TL,
3170 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003171 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003172}
3173
Mike Stump11289f42009-09-09 15:08:12 +00003174template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003175QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003176 TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003177 SubstTemplateTypeParmTypeLoc TL,
3178 QualType ObjectType) {
John McCall550e0c22009-10-21 00:40:46 +00003179 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003180}
3181
3182template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003183QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3184 const TemplateSpecializationType *TST,
3185 QualType ObjectType) {
3186 // FIXME: this entire method is a temporary workaround; callers
3187 // should be rewritten to provide real type locs.
John McCall550e0c22009-10-21 00:40:46 +00003188
John McCall0ad16662009-10-29 08:12:44 +00003189 // Fake up a TemplateSpecializationTypeLoc.
3190 TypeLocBuilder TLB;
3191 TemplateSpecializationTypeLoc TL
3192 = TLB.push<TemplateSpecializationTypeLoc>(QualType(TST, 0));
3193
John McCall0d07eb32009-10-29 18:45:58 +00003194 SourceLocation BaseLoc = getDerived().getBaseLocation();
3195
3196 TL.setTemplateNameLoc(BaseLoc);
3197 TL.setLAngleLoc(BaseLoc);
3198 TL.setRAngleLoc(BaseLoc);
John McCall0ad16662009-10-29 08:12:44 +00003199 for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) {
3200 const TemplateArgument &TA = TST->getArg(i);
3201 TemplateArgumentLoc TAL;
3202 getDerived().InventTemplateArgumentLoc(TA, TAL);
3203 TL.setArgLocInfo(i, TAL.getLocInfo());
3204 }
3205
3206 TypeLocBuilder IgnoredTLB;
3207 return TransformTemplateSpecializationType(IgnoredTLB, TL, ObjectType);
Douglas Gregorc59e5612009-10-19 22:04:39 +00003208}
Alexis Hunta8136cc2010-05-05 15:23:54 +00003209
Douglas Gregorc59e5612009-10-19 22:04:39 +00003210template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003211QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003212 TypeLocBuilder &TLB,
3213 TemplateSpecializationTypeLoc TL,
3214 QualType ObjectType) {
3215 const TemplateSpecializationType *T = TL.getTypePtr();
3216
Mike Stump11289f42009-09-09 15:08:12 +00003217 TemplateName Template
Douglas Gregorc59e5612009-10-19 22:04:39 +00003218 = getDerived().TransformTemplateName(T->getTemplateName(), ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003219 if (Template.isNull())
3220 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003221
John McCall6b51f282009-11-23 01:53:49 +00003222 TemplateArgumentListInfo NewTemplateArgs;
3223 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3224 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3225
3226 for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
3227 TemplateArgumentLoc Loc;
3228 if (getDerived().TransformTemplateArgument(TL.getArgLoc(i), Loc))
Douglas Gregord6ff3322009-08-04 16:50:30 +00003229 return QualType();
John McCall6b51f282009-11-23 01:53:49 +00003230 NewTemplateArgs.addArgument(Loc);
3231 }
Mike Stump11289f42009-09-09 15:08:12 +00003232
John McCall0ad16662009-10-29 08:12:44 +00003233 // FIXME: maybe don't rebuild if all the template arguments are the same.
3234
3235 QualType Result =
3236 getDerived().RebuildTemplateSpecializationType(Template,
3237 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00003238 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00003239
3240 if (!Result.isNull()) {
3241 TemplateSpecializationTypeLoc NewTL
3242 = TLB.push<TemplateSpecializationTypeLoc>(Result);
3243 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
3244 NewTL.setLAngleLoc(TL.getLAngleLoc());
3245 NewTL.setRAngleLoc(TL.getRAngleLoc());
3246 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
3247 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003248 }
Mike Stump11289f42009-09-09 15:08:12 +00003249
John McCall0ad16662009-10-29 08:12:44 +00003250 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003251}
Mike Stump11289f42009-09-09 15:08:12 +00003252
3253template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003254QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00003255TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
3256 ElaboratedTypeLoc TL,
3257 QualType ObjectType) {
3258 ElaboratedType *T = TL.getTypePtr();
3259
3260 NestedNameSpecifier *NNS = 0;
3261 // NOTE: the qualifier in an ElaboratedType is optional.
3262 if (T->getQualifier() != 0) {
3263 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
Abramo Bagnarad7548482010-05-19 21:37:53 +00003264 TL.getQualifierRange(),
Abramo Bagnara6150c882010-05-11 21:36:43 +00003265 ObjectType);
3266 if (!NNS)
3267 return QualType();
3268 }
Mike Stump11289f42009-09-09 15:08:12 +00003269
Abramo Bagnarad7548482010-05-19 21:37:53 +00003270 QualType NamedT;
3271 // FIXME: this test is meant to workaround a problem (failing assertion)
3272 // occurring if directly executing the code in the else branch.
3273 if (isa<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc())) {
3274 TemplateSpecializationTypeLoc OldNamedTL
3275 = cast<TemplateSpecializationTypeLoc>(TL.getNamedTypeLoc());
3276 const TemplateSpecializationType* OldTST
Jim Grosbachdb061512010-05-19 23:53:08 +00003277 = OldNamedTL.getType()->template getAs<TemplateSpecializationType>();
Abramo Bagnarad7548482010-05-19 21:37:53 +00003278 NamedT = TransformTemplateSpecializationType(OldTST, ObjectType);
3279 if (NamedT.isNull())
3280 return QualType();
3281 TemplateSpecializationTypeLoc NewNamedTL
3282 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3283 NewNamedTL.copy(OldNamedTL);
3284 }
3285 else {
3286 NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
3287 if (NamedT.isNull())
3288 return QualType();
3289 }
Daniel Dunbar4707cef2010-05-14 16:34:09 +00003290
John McCall550e0c22009-10-21 00:40:46 +00003291 QualType Result = TL.getType();
3292 if (getDerived().AlwaysRebuild() ||
3293 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00003294 NamedT != T->getNamedType()) {
3295 Result = getDerived().RebuildElaboratedType(T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00003296 if (Result.isNull())
3297 return QualType();
3298 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003299
Abramo Bagnara6150c882010-05-11 21:36:43 +00003300 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00003301 NewTL.setKeywordLoc(TL.getKeywordLoc());
3302 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00003303
3304 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003305}
Mike Stump11289f42009-09-09 15:08:12 +00003306
3307template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003308QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
3309 DependentNameTypeLoc TL,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003310 QualType ObjectType) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00003311 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00003312
Douglas Gregord6ff3322009-08-04 16:50:30 +00003313 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00003314 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3315 TL.getQualifierRange(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00003316 ObjectType);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003317 if (!NNS)
3318 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003319
John McCallc392f372010-06-11 00:33:02 +00003320 QualType Result
3321 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
3322 T->getIdentifier(),
3323 TL.getKeywordLoc(),
3324 TL.getQualifierRange(),
3325 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003326 if (Result.isNull())
3327 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003328
Abramo Bagnarad7548482010-05-19 21:37:53 +00003329 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
3330 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00003331 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
3332
Abramo Bagnarad7548482010-05-19 21:37:53 +00003333 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3334 NewTL.setKeywordLoc(TL.getKeywordLoc());
3335 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00003336 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00003337 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
3338 NewTL.setKeywordLoc(TL.getKeywordLoc());
3339 NewTL.setQualifierRange(TL.getQualifierRange());
3340 NewTL.setNameLoc(TL.getNameLoc());
3341 }
John McCall550e0c22009-10-21 00:40:46 +00003342 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003343}
Mike Stump11289f42009-09-09 15:08:12 +00003344
Douglas Gregord6ff3322009-08-04 16:50:30 +00003345template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00003346QualType TreeTransform<Derived>::
3347 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
3348 DependentTemplateSpecializationTypeLoc TL,
3349 QualType ObjectType) {
3350 DependentTemplateSpecializationType *T = TL.getTypePtr();
3351
3352 NestedNameSpecifier *NNS
3353 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
3354 TL.getQualifierRange(),
3355 ObjectType);
3356 if (!NNS)
3357 return QualType();
3358
3359 TemplateArgumentListInfo NewTemplateArgs;
3360 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3361 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
3362
3363 for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) {
3364 TemplateArgumentLoc Loc;
3365 if (getDerived().TransformTemplateArgument(TL.getArgLoc(I), Loc))
3366 return QualType();
3367 NewTemplateArgs.addArgument(Loc);
3368 }
3369
3370 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
3371 T->getKeyword(),
3372 NNS,
3373 T->getIdentifier(),
3374 TL.getNameLoc(),
3375 NewTemplateArgs);
3376 if (Result.isNull())
3377 return QualType();
3378
3379 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
3380 QualType NamedT = ElabT->getNamedType();
3381
3382 // Copy information relevant to the template specialization.
3383 TemplateSpecializationTypeLoc NamedTL
3384 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
3385 NamedTL.setLAngleLoc(TL.getLAngleLoc());
3386 NamedTL.setRAngleLoc(TL.getRAngleLoc());
3387 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
3388 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
3389
3390 // Copy information relevant to the elaborated type.
3391 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
3392 NewTL.setKeywordLoc(TL.getKeywordLoc());
3393 NewTL.setQualifierRange(TL.getQualifierRange());
3394 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00003395 TypeLoc NewTL(Result, TL.getOpaqueData());
3396 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00003397 }
3398 return Result;
3399}
3400
3401template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003402QualType
3403TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003404 ObjCInterfaceTypeLoc TL,
3405 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003406 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003407 TLB.pushFullCopy(TL);
3408 return TL.getType();
3409}
3410
3411template<typename Derived>
3412QualType
3413TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
3414 ObjCObjectTypeLoc TL,
3415 QualType ObjectType) {
3416 // ObjCObjectType is never dependent.
3417 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003418 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003419}
Mike Stump11289f42009-09-09 15:08:12 +00003420
3421template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003422QualType
3423TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
Douglas Gregorfe17d252010-02-16 19:09:40 +00003424 ObjCObjectPointerTypeLoc TL,
3425 QualType ObjectType) {
Douglas Gregor21515a92010-04-22 17:28:13 +00003426 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00003427 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00003428 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00003429}
3430
Douglas Gregord6ff3322009-08-04 16:50:30 +00003431//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00003432// Statement transformation
3433//===----------------------------------------------------------------------===//
3434template<typename Derived>
3435Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003436TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
3437 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003438}
3439
3440template<typename Derived>
3441Sema::OwningStmtResult
3442TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
3443 return getDerived().TransformCompoundStmt(S, false);
3444}
3445
3446template<typename Derived>
3447Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003448TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00003449 bool IsStmtExpr) {
3450 bool SubStmtChanged = false;
3451 ASTOwningVector<&ActionBase::DeleteStmt> Statements(getSema());
3452 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
3453 B != BEnd; ++B) {
3454 OwningStmtResult Result = getDerived().TransformStmt(*B);
3455 if (Result.isInvalid())
3456 return getSema().StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003457
Douglas Gregorebe10102009-08-20 07:17:43 +00003458 SubStmtChanged = SubStmtChanged || Result.get() != *B;
3459 Statements.push_back(Result.takeAs<Stmt>());
3460 }
Mike Stump11289f42009-09-09 15:08:12 +00003461
Douglas Gregorebe10102009-08-20 07:17:43 +00003462 if (!getDerived().AlwaysRebuild() &&
3463 !SubStmtChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003464 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003465
3466 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
3467 move_arg(Statements),
3468 S->getRBracLoc(),
3469 IsStmtExpr);
3470}
Mike Stump11289f42009-09-09 15:08:12 +00003471
Douglas Gregorebe10102009-08-20 07:17:43 +00003472template<typename Derived>
3473Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003474TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
Eli Friedman06577382009-11-19 03:14:00 +00003475 OwningExprResult LHS(SemaRef), RHS(SemaRef);
3476 {
3477 // The case value expressions are not potentially evaluated.
3478 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003479
Eli Friedman06577382009-11-19 03:14:00 +00003480 // Transform the left-hand case value.
3481 LHS = getDerived().TransformExpr(S->getLHS());
3482 if (LHS.isInvalid())
3483 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003484
Eli Friedman06577382009-11-19 03:14:00 +00003485 // Transform the right-hand case value (for the GNU case-range extension).
3486 RHS = getDerived().TransformExpr(S->getRHS());
3487 if (RHS.isInvalid())
3488 return SemaRef.StmtError();
3489 }
Mike Stump11289f42009-09-09 15:08:12 +00003490
Douglas Gregorebe10102009-08-20 07:17:43 +00003491 // Build the case statement.
3492 // Case statements are always rebuilt so that they will attached to their
3493 // transformed switch statement.
3494 OwningStmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
3495 move(LHS),
3496 S->getEllipsisLoc(),
3497 move(RHS),
3498 S->getColonLoc());
3499 if (Case.isInvalid())
3500 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003501
Douglas Gregorebe10102009-08-20 07:17:43 +00003502 // Transform the statement following the case
3503 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3504 if (SubStmt.isInvalid())
3505 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003506
Douglas Gregorebe10102009-08-20 07:17:43 +00003507 // Attach the body to the case statement
3508 return getDerived().RebuildCaseStmtBody(move(Case), move(SubStmt));
3509}
3510
3511template<typename Derived>
3512Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003513TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003514 // Transform the statement following the default case
3515 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3516 if (SubStmt.isInvalid())
3517 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003518
Douglas Gregorebe10102009-08-20 07:17:43 +00003519 // Default statements are always rebuilt
3520 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
3521 move(SubStmt));
3522}
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregorebe10102009-08-20 07:17:43 +00003524template<typename Derived>
3525Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003526TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003527 OwningStmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
3528 if (SubStmt.isInvalid())
3529 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003530
Douglas Gregorebe10102009-08-20 07:17:43 +00003531 // FIXME: Pass the real colon location in.
3532 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
3533 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
3534 move(SubStmt));
3535}
Mike Stump11289f42009-09-09 15:08:12 +00003536
Douglas Gregorebe10102009-08-20 07:17:43 +00003537template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003538Sema::OwningStmtResult
3539TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003540 // Transform the condition
Douglas Gregor633caca2009-11-23 23:44:04 +00003541 OwningExprResult Cond(SemaRef);
3542 VarDecl *ConditionVar = 0;
3543 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003544 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00003545 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003546 getDerived().TransformDefinition(
3547 S->getConditionVariable()->getLocation(),
3548 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00003549 if (!ConditionVar)
3550 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003551 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00003552 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003553
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003554 if (Cond.isInvalid())
3555 return SemaRef.StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003556
3557 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00003558 if (S->getCond()) {
3559 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3560 S->getIfLoc(),
3561 move(Cond));
3562 if (CondE.isInvalid())
3563 return getSema().StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003564
Douglas Gregor6d319c62010-05-08 23:34:38 +00003565 Cond = move(CondE);
3566 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003567 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003568
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003569 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3570 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3571 return SemaRef.StmtError();
3572
Douglas Gregorebe10102009-08-20 07:17:43 +00003573 // Transform the "then" branch.
3574 OwningStmtResult Then = getDerived().TransformStmt(S->getThen());
3575 if (Then.isInvalid())
3576 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003577
Douglas Gregorebe10102009-08-20 07:17:43 +00003578 // Transform the "else" branch.
3579 OwningStmtResult Else = getDerived().TransformStmt(S->getElse());
3580 if (Else.isInvalid())
3581 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003582
Douglas Gregorebe10102009-08-20 07:17:43 +00003583 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003584 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003585 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003586 Then.get() == S->getThen() &&
3587 Else.get() == S->getElse())
Mike Stump11289f42009-09-09 15:08:12 +00003588 return SemaRef.Owned(S->Retain());
3589
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003590 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003591 move(Then),
Mike Stump11289f42009-09-09 15:08:12 +00003592 S->getElseLoc(), move(Else));
Douglas Gregorebe10102009-08-20 07:17:43 +00003593}
3594
3595template<typename Derived>
3596Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003597TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003598 // Transform the condition.
Douglas Gregordcf19622009-11-24 17:07:59 +00003599 OwningExprResult Cond(SemaRef);
3600 VarDecl *ConditionVar = 0;
3601 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003602 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00003603 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003604 getDerived().TransformDefinition(
3605 S->getConditionVariable()->getLocation(),
3606 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00003607 if (!ConditionVar)
3608 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003609 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00003610 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003611
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003612 if (Cond.isInvalid())
3613 return SemaRef.StmtError();
3614 }
Mike Stump11289f42009-09-09 15:08:12 +00003615
Douglas Gregorebe10102009-08-20 07:17:43 +00003616 // Rebuild the switch statement.
Douglas Gregore60e41a2010-05-06 17:25:47 +00003617 OwningStmtResult Switch
3618 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), move(Cond),
3619 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00003620 if (Switch.isInvalid())
3621 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003622
Douglas Gregorebe10102009-08-20 07:17:43 +00003623 // Transform the body of the switch statement.
3624 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3625 if (Body.isInvalid())
3626 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003627
Douglas Gregorebe10102009-08-20 07:17:43 +00003628 // Complete the switch statement.
3629 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), move(Switch),
3630 move(Body));
3631}
Mike Stump11289f42009-09-09 15:08:12 +00003632
Douglas Gregorebe10102009-08-20 07:17:43 +00003633template<typename Derived>
3634Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003635TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003636 // Transform the condition
Douglas Gregor680f8612009-11-24 21:15:44 +00003637 OwningExprResult Cond(SemaRef);
3638 VarDecl *ConditionVar = 0;
3639 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003640 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00003641 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003642 getDerived().TransformDefinition(
3643 S->getConditionVariable()->getLocation(),
3644 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00003645 if (!ConditionVar)
3646 return SemaRef.StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003647 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00003648 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003649
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003650 if (Cond.isInvalid())
3651 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003652
3653 if (S->getCond()) {
3654 // Convert the condition to a boolean value.
3655 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003656 S->getWhileLoc(),
Douglas Gregor6d319c62010-05-08 23:34:38 +00003657 move(Cond));
3658 if (CondE.isInvalid())
3659 return getSema().StmtError();
3660 Cond = move(CondE);
3661 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003662 }
Mike Stump11289f42009-09-09 15:08:12 +00003663
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003664 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3665 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3666 return SemaRef.StmtError();
3667
Douglas Gregorebe10102009-08-20 07:17:43 +00003668 // Transform the body
3669 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3670 if (Body.isInvalid())
3671 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003672
Douglas Gregorebe10102009-08-20 07:17:43 +00003673 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003674 FullCond->get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003675 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003676 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003677 return SemaRef.Owned(S->Retain());
3678
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003679 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
Douglas Gregore60e41a2010-05-06 17:25:47 +00003680 ConditionVar, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003681}
Mike Stump11289f42009-09-09 15:08:12 +00003682
Douglas Gregorebe10102009-08-20 07:17:43 +00003683template<typename Derived>
3684Sema::OwningStmtResult
3685TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003686 // Transform the body
3687 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3688 if (Body.isInvalid())
3689 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003690
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003691 // Transform the condition
3692 OwningExprResult Cond = getDerived().TransformExpr(S->getCond());
3693 if (Cond.isInvalid())
3694 return SemaRef.StmtError();
3695
Douglas Gregorebe10102009-08-20 07:17:43 +00003696 if (!getDerived().AlwaysRebuild() &&
3697 Cond.get() == S->getCond() &&
3698 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003699 return SemaRef.Owned(S->Retain());
3700
Douglas Gregorebe10102009-08-20 07:17:43 +00003701 return getDerived().RebuildDoStmt(S->getDoLoc(), move(Body), S->getWhileLoc(),
3702 /*FIXME:*/S->getWhileLoc(), move(Cond),
3703 S->getRParenLoc());
3704}
Mike Stump11289f42009-09-09 15:08:12 +00003705
Douglas Gregorebe10102009-08-20 07:17:43 +00003706template<typename Derived>
3707Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003708TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003709 // Transform the initialization statement
3710 OwningStmtResult Init = getDerived().TransformStmt(S->getInit());
3711 if (Init.isInvalid())
3712 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003713
Douglas Gregorebe10102009-08-20 07:17:43 +00003714 // Transform the condition
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003715 OwningExprResult Cond(SemaRef);
3716 VarDecl *ConditionVar = 0;
3717 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003718 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003719 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00003720 getDerived().TransformDefinition(
3721 S->getConditionVariable()->getLocation(),
3722 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003723 if (!ConditionVar)
3724 return SemaRef.StmtError();
3725 } else {
3726 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003727
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003728 if (Cond.isInvalid())
3729 return SemaRef.StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00003730
3731 if (S->getCond()) {
3732 // Convert the condition to a boolean value.
3733 OwningExprResult CondE = getSema().ActOnBooleanCondition(0,
3734 S->getForLoc(),
3735 move(Cond));
3736 if (CondE.isInvalid())
3737 return getSema().StmtError();
3738
3739 Cond = move(CondE);
3740 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00003741 }
Mike Stump11289f42009-09-09 15:08:12 +00003742
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003743 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond));
3744 if (!S->getConditionVariable() && S->getCond() && !FullCond->get())
3745 return SemaRef.StmtError();
3746
Douglas Gregorebe10102009-08-20 07:17:43 +00003747 // Transform the increment
3748 OwningExprResult Inc = getDerived().TransformExpr(S->getInc());
3749 if (Inc.isInvalid())
3750 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003751
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003752 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc));
3753 if (S->getInc() && !FullInc->get())
3754 return SemaRef.StmtError();
3755
Douglas Gregorebe10102009-08-20 07:17:43 +00003756 // Transform the body
3757 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
3758 if (Body.isInvalid())
3759 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003760
Douglas Gregorebe10102009-08-20 07:17:43 +00003761 if (!getDerived().AlwaysRebuild() &&
3762 Init.get() == S->getInit() &&
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003763 FullCond->get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00003764 Inc.get() == S->getInc() &&
3765 Body.get() == S->getBody())
Mike Stump11289f42009-09-09 15:08:12 +00003766 return SemaRef.Owned(S->Retain());
3767
Douglas Gregorebe10102009-08-20 07:17:43 +00003768 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
Douglas Gregorff73a9e2010-05-08 22:20:28 +00003769 move(Init), FullCond, ConditionVar,
3770 FullInc, S->getRParenLoc(), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00003771}
3772
3773template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003774Sema::OwningStmtResult
3775TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003776 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00003777 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003778 S->getLabel());
3779}
3780
3781template<typename Derived>
3782Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003783TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003784 OwningExprResult Target = getDerived().TransformExpr(S->getTarget());
3785 if (Target.isInvalid())
3786 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003787
Douglas Gregorebe10102009-08-20 07:17:43 +00003788 if (!getDerived().AlwaysRebuild() &&
3789 Target.get() == S->getTarget())
Mike Stump11289f42009-09-09 15:08:12 +00003790 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003791
3792 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
3793 move(Target));
3794}
3795
3796template<typename Derived>
3797Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003798TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
3799 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003800}
Mike Stump11289f42009-09-09 15:08:12 +00003801
Douglas Gregorebe10102009-08-20 07:17:43 +00003802template<typename Derived>
3803Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003804TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
3805 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003806}
Mike Stump11289f42009-09-09 15:08:12 +00003807
Douglas Gregorebe10102009-08-20 07:17:43 +00003808template<typename Derived>
3809Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003810TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003811 Sema::OwningExprResult Result = getDerived().TransformExpr(S->getRetValue());
3812 if (Result.isInvalid())
3813 return SemaRef.StmtError();
3814
Mike Stump11289f42009-09-09 15:08:12 +00003815 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00003816 // to tell whether the return type of the function has changed.
3817 return getDerived().RebuildReturnStmt(S->getReturnLoc(), move(Result));
3818}
Mike Stump11289f42009-09-09 15:08:12 +00003819
Douglas Gregorebe10102009-08-20 07:17:43 +00003820template<typename Derived>
3821Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003822TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003823 bool DeclChanged = false;
3824 llvm::SmallVector<Decl *, 4> Decls;
3825 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
3826 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00003827 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
3828 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00003829 if (!Transformed)
3830 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00003831
Douglas Gregorebe10102009-08-20 07:17:43 +00003832 if (Transformed != *D)
3833 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00003834
Douglas Gregorebe10102009-08-20 07:17:43 +00003835 Decls.push_back(Transformed);
3836 }
Mike Stump11289f42009-09-09 15:08:12 +00003837
Douglas Gregorebe10102009-08-20 07:17:43 +00003838 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Mike Stump11289f42009-09-09 15:08:12 +00003839 return SemaRef.Owned(S->Retain());
3840
3841 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00003842 S->getStartLoc(), S->getEndLoc());
3843}
Mike Stump11289f42009-09-09 15:08:12 +00003844
Douglas Gregorebe10102009-08-20 07:17:43 +00003845template<typename Derived>
3846Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003847TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00003848 assert(false && "SwitchCase is abstract and cannot be transformed");
Mike Stump11289f42009-09-09 15:08:12 +00003849 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00003850}
3851
3852template<typename Derived>
3853Sema::OwningStmtResult
3854TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003855
Anders Carlssonaaeef072010-01-24 05:50:09 +00003856 ASTOwningVector<&ActionBase::DeleteExpr> Constraints(getSema());
3857 ASTOwningVector<&ActionBase::DeleteExpr> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00003858 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00003859
Anders Carlssonaaeef072010-01-24 05:50:09 +00003860 OwningExprResult AsmString(SemaRef);
3861 ASTOwningVector<&ActionBase::DeleteExpr> Clobbers(getSema());
3862
3863 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003864
Anders Carlssonaaeef072010-01-24 05:50:09 +00003865 // Go through the outputs.
3866 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003867 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003868
Anders Carlssonaaeef072010-01-24 05:50:09 +00003869 // No need to transform the constraint literal.
3870 Constraints.push_back(S->getOutputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003871
Anders Carlssonaaeef072010-01-24 05:50:09 +00003872 // Transform the output expr.
3873 Expr *OutputExpr = S->getOutputExpr(I);
3874 OwningExprResult Result = getDerived().TransformExpr(OutputExpr);
3875 if (Result.isInvalid())
3876 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003877
Anders Carlssonaaeef072010-01-24 05:50:09 +00003878 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003879
Anders Carlssonaaeef072010-01-24 05:50:09 +00003880 Exprs.push_back(Result.takeAs<Expr>());
3881 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003882
Anders Carlssonaaeef072010-01-24 05:50:09 +00003883 // Go through the inputs.
3884 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00003885 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00003886
Anders Carlssonaaeef072010-01-24 05:50:09 +00003887 // No need to transform the constraint literal.
3888 Constraints.push_back(S->getInputConstraintLiteral(I)->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003889
Anders Carlssonaaeef072010-01-24 05:50:09 +00003890 // Transform the input expr.
3891 Expr *InputExpr = S->getInputExpr(I);
3892 OwningExprResult Result = getDerived().TransformExpr(InputExpr);
3893 if (Result.isInvalid())
3894 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003895
Anders Carlssonaaeef072010-01-24 05:50:09 +00003896 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00003897
Anders Carlssonaaeef072010-01-24 05:50:09 +00003898 Exprs.push_back(Result.takeAs<Expr>());
3899 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003900
Anders Carlssonaaeef072010-01-24 05:50:09 +00003901 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
3902 return SemaRef.Owned(S->Retain());
3903
3904 // Go through the clobbers.
3905 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
3906 Clobbers.push_back(S->getClobber(I)->Retain());
3907
3908 // No need to transform the asm string literal.
3909 AsmString = SemaRef.Owned(S->getAsmString());
3910
3911 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
3912 S->isSimple(),
3913 S->isVolatile(),
3914 S->getNumOutputs(),
3915 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00003916 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00003917 move_arg(Constraints),
3918 move_arg(Exprs),
3919 move(AsmString),
3920 move_arg(Clobbers),
3921 S->getRParenLoc(),
3922 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00003923}
3924
3925
3926template<typename Derived>
3927Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003928TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00003929 // Transform the body of the @try.
3930 OwningStmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
3931 if (TryBody.isInvalid())
3932 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003933
Douglas Gregor96c79492010-04-23 22:50:49 +00003934 // Transform the @catch statements (if present).
3935 bool AnyCatchChanged = false;
3936 ASTOwningVector<&ActionBase::DeleteStmt> CatchStmts(SemaRef);
3937 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
3938 OwningStmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00003939 if (Catch.isInvalid())
3940 return SemaRef.StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00003941 if (Catch.get() != S->getCatchStmt(I))
3942 AnyCatchChanged = true;
3943 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00003944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003945
Douglas Gregor306de2f2010-04-22 23:59:56 +00003946 // Transform the @finally statement (if present).
3947 OwningStmtResult Finally(SemaRef);
3948 if (S->getFinallyStmt()) {
3949 Finally = getDerived().TransformStmt(S->getFinallyStmt());
3950 if (Finally.isInvalid())
3951 return SemaRef.StmtError();
3952 }
3953
3954 // If nothing changed, just retain this statement.
3955 if (!getDerived().AlwaysRebuild() &&
3956 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00003957 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00003958 Finally.get() == S->getFinallyStmt())
3959 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003960
Douglas Gregor306de2f2010-04-22 23:59:56 +00003961 // Build a new statement.
3962 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), move(TryBody),
Douglas Gregor96c79492010-04-23 22:50:49 +00003963 move_arg(CatchStmts), move(Finally));
Douglas Gregorebe10102009-08-20 07:17:43 +00003964}
Mike Stump11289f42009-09-09 15:08:12 +00003965
Douglas Gregorebe10102009-08-20 07:17:43 +00003966template<typename Derived>
3967Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00003968TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003969 // Transform the @catch parameter, if there is one.
3970 VarDecl *Var = 0;
3971 if (VarDecl *FromVar = S->getCatchParamDecl()) {
3972 TypeSourceInfo *TSInfo = 0;
3973 if (FromVar->getTypeSourceInfo()) {
3974 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
3975 if (!TSInfo)
3976 return SemaRef.StmtError();
3977 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003978
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003979 QualType T;
3980 if (TSInfo)
3981 T = TSInfo->getType();
3982 else {
3983 T = getDerived().TransformType(FromVar->getType());
3984 if (T.isNull())
Alexis Hunta8136cc2010-05-05 15:23:54 +00003985 return SemaRef.StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003986 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003987
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003988 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
3989 if (!Var)
3990 return SemaRef.StmtError();
3991 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003992
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003993 OwningStmtResult Body = getDerived().TransformStmt(S->getCatchBody());
3994 if (Body.isInvalid())
3995 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00003996
3997 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00003998 S->getRParenLoc(),
3999 Var, move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004000}
Mike Stump11289f42009-09-09 15:08:12 +00004001
Douglas Gregorebe10102009-08-20 07:17:43 +00004002template<typename Derived>
4003Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004004TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004005 // Transform the body.
4006 OwningStmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
4007 if (Body.isInvalid())
4008 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004009
Douglas Gregor306de2f2010-04-22 23:59:56 +00004010 // If nothing changed, just retain this statement.
4011 if (!getDerived().AlwaysRebuild() &&
4012 Body.get() == S->getFinallyBody())
4013 return SemaRef.Owned(S->Retain());
4014
4015 // Build a new statement.
4016 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
4017 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004018}
Mike Stump11289f42009-09-09 15:08:12 +00004019
Douglas Gregorebe10102009-08-20 07:17:43 +00004020template<typename Derived>
4021Sema::OwningStmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004022TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
Douglas Gregor2900c162010-04-22 21:44:01 +00004023 OwningExprResult Operand(SemaRef);
4024 if (S->getThrowExpr()) {
4025 Operand = getDerived().TransformExpr(S->getThrowExpr());
4026 if (Operand.isInvalid())
4027 return getSema().StmtError();
4028 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004029
Douglas Gregor2900c162010-04-22 21:44:01 +00004030 if (!getDerived().AlwaysRebuild() &&
4031 Operand.get() == S->getThrowExpr())
4032 return getSema().Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004033
Douglas Gregor2900c162010-04-22 21:44:01 +00004034 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), move(Operand));
Douglas Gregorebe10102009-08-20 07:17:43 +00004035}
Mike Stump11289f42009-09-09 15:08:12 +00004036
Douglas Gregorebe10102009-08-20 07:17:43 +00004037template<typename Derived>
4038Sema::OwningStmtResult
4039TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004040 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004041 // Transform the object we are locking.
4042 OwningExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
4043 if (Object.isInvalid())
4044 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004045
Douglas Gregor6148de72010-04-22 22:01:21 +00004046 // Transform the body.
4047 OwningStmtResult Body = getDerived().TransformStmt(S->getSynchBody());
4048 if (Body.isInvalid())
4049 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004050
Douglas Gregor6148de72010-04-22 22:01:21 +00004051 // If nothing change, just retain the current statement.
4052 if (!getDerived().AlwaysRebuild() &&
4053 Object.get() == S->getSynchExpr() &&
4054 Body.get() == S->getSynchBody())
4055 return SemaRef.Owned(S->Retain());
4056
4057 // Build a new statement.
4058 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
4059 move(Object), move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004060}
4061
4062template<typename Derived>
4063Sema::OwningStmtResult
4064TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004065 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004066 // Transform the element statement.
4067 OwningStmtResult Element = getDerived().TransformStmt(S->getElement());
4068 if (Element.isInvalid())
4069 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004070
Douglas Gregorf68a5082010-04-22 23:10:45 +00004071 // Transform the collection expression.
4072 OwningExprResult Collection = getDerived().TransformExpr(S->getCollection());
4073 if (Collection.isInvalid())
4074 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004075
Douglas Gregorf68a5082010-04-22 23:10:45 +00004076 // Transform the body.
4077 OwningStmtResult Body = getDerived().TransformStmt(S->getBody());
4078 if (Body.isInvalid())
4079 return SemaRef.StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004080
Douglas Gregorf68a5082010-04-22 23:10:45 +00004081 // If nothing changed, just retain this statement.
4082 if (!getDerived().AlwaysRebuild() &&
4083 Element.get() == S->getElement() &&
4084 Collection.get() == S->getCollection() &&
4085 Body.get() == S->getBody())
4086 return SemaRef.Owned(S->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004087
Douglas Gregorf68a5082010-04-22 23:10:45 +00004088 // Build a new statement.
4089 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4090 /*FIXME:*/S->getForLoc(),
4091 move(Element),
4092 move(Collection),
4093 S->getRParenLoc(),
4094 move(Body));
Douglas Gregorebe10102009-08-20 07:17:43 +00004095}
4096
4097
4098template<typename Derived>
4099Sema::OwningStmtResult
4100TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4101 // Transform the exception declaration, if any.
4102 VarDecl *Var = 0;
4103 if (S->getExceptionDecl()) {
4104 VarDecl *ExceptionDecl = S->getExceptionDecl();
4105 TemporaryBase Rebase(*this, ExceptionDecl->getLocation(),
4106 ExceptionDecl->getDeclName());
4107
4108 QualType T = getDerived().TransformType(ExceptionDecl->getType());
4109 if (T.isNull())
4110 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004111
Douglas Gregorebe10102009-08-20 07:17:43 +00004112 Var = getDerived().RebuildExceptionDecl(ExceptionDecl,
4113 T,
John McCallbcd03502009-12-07 02:54:59 +00004114 ExceptionDecl->getTypeSourceInfo(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004115 ExceptionDecl->getIdentifier(),
4116 ExceptionDecl->getLocation(),
4117 /*FIXME: Inaccurate*/
4118 SourceRange(ExceptionDecl->getLocation()));
4119 if (!Var || Var->isInvalidDecl()) {
4120 if (Var)
4121 Var->Destroy(SemaRef.Context);
4122 return SemaRef.StmtError();
4123 }
4124 }
Mike Stump11289f42009-09-09 15:08:12 +00004125
Douglas Gregorebe10102009-08-20 07:17:43 +00004126 // Transform the actual exception handler.
4127 OwningStmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
4128 if (Handler.isInvalid()) {
4129 if (Var)
4130 Var->Destroy(SemaRef.Context);
4131 return SemaRef.StmtError();
4132 }
Mike Stump11289f42009-09-09 15:08:12 +00004133
Douglas Gregorebe10102009-08-20 07:17:43 +00004134 if (!getDerived().AlwaysRebuild() &&
4135 !Var &&
4136 Handler.get() == S->getHandlerBlock())
Mike Stump11289f42009-09-09 15:08:12 +00004137 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004138
4139 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4140 Var,
4141 move(Handler));
4142}
Mike Stump11289f42009-09-09 15:08:12 +00004143
Douglas Gregorebe10102009-08-20 07:17:43 +00004144template<typename Derived>
4145Sema::OwningStmtResult
4146TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4147 // Transform the try block itself.
Mike Stump11289f42009-09-09 15:08:12 +00004148 OwningStmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00004149 = getDerived().TransformCompoundStmt(S->getTryBlock());
4150 if (TryBlock.isInvalid())
4151 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregorebe10102009-08-20 07:17:43 +00004153 // Transform the handlers.
4154 bool HandlerChanged = false;
4155 ASTOwningVector<&ActionBase::DeleteStmt> Handlers(SemaRef);
4156 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
Mike Stump11289f42009-09-09 15:08:12 +00004157 OwningStmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00004158 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4159 if (Handler.isInvalid())
4160 return SemaRef.StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004161
Douglas Gregorebe10102009-08-20 07:17:43 +00004162 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4163 Handlers.push_back(Handler.takeAs<Stmt>());
4164 }
Mike Stump11289f42009-09-09 15:08:12 +00004165
Douglas Gregorebe10102009-08-20 07:17:43 +00004166 if (!getDerived().AlwaysRebuild() &&
4167 TryBlock.get() == S->getTryBlock() &&
4168 !HandlerChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004169 return SemaRef.Owned(S->Retain());
Douglas Gregorebe10102009-08-20 07:17:43 +00004170
4171 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), move(TryBlock),
Mike Stump11289f42009-09-09 15:08:12 +00004172 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00004173}
Mike Stump11289f42009-09-09 15:08:12 +00004174
Douglas Gregorebe10102009-08-20 07:17:43 +00004175//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00004176// Expression transformation
4177//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00004178template<typename Derived>
4179Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004180TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004181 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004182}
Mike Stump11289f42009-09-09 15:08:12 +00004183
4184template<typename Derived>
4185Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004186TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004187 NestedNameSpecifier *Qualifier = 0;
4188 if (E->getQualifier()) {
4189 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004190 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004191 if (!Qualifier)
4192 return SemaRef.ExprError();
4193 }
John McCallce546572009-12-08 09:08:17 +00004194
4195 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004196 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
4197 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004198 if (!ND)
4199 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004200
Fariborz Jahanian1babe772010-07-09 18:44:02 +00004201 // Set DeclContext if inside a Block.
4202 if (BlockScopeInfo *CurBlock = SemaRef.getCurBlock())
4203 ND->setDeclContext(CurBlock->TheDecl);
4204
Alexis Hunta8136cc2010-05-05 15:23:54 +00004205 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004206 Qualifier == E->getQualifier() &&
4207 ND == E->getDecl() &&
John McCallce546572009-12-08 09:08:17 +00004208 !E->hasExplicitTemplateArgumentList()) {
4209
4210 // Mark it referenced in the new context regardless.
4211 // FIXME: this is a bit instantiation-specific.
4212 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
4213
Mike Stump11289f42009-09-09 15:08:12 +00004214 return SemaRef.Owned(E->Retain());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004215 }
John McCallce546572009-12-08 09:08:17 +00004216
4217 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
4218 if (E->hasExplicitTemplateArgumentList()) {
4219 TemplateArgs = &TransArgs;
4220 TransArgs.setLAngleLoc(E->getLAngleLoc());
4221 TransArgs.setRAngleLoc(E->getRAngleLoc());
4222 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
4223 TemplateArgumentLoc Loc;
4224 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
4225 return SemaRef.ExprError();
4226 TransArgs.addArgument(Loc);
4227 }
4228 }
4229
Douglas Gregor4bd90e52009-10-23 18:54:35 +00004230 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
John McCallce546572009-12-08 09:08:17 +00004231 ND, E->getLocation(), TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00004232}
Mike Stump11289f42009-09-09 15:08:12 +00004233
Douglas Gregora16548e2009-08-11 05:31:07 +00004234template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004235Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004236TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004237 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004238}
Mike Stump11289f42009-09-09 15:08:12 +00004239
Douglas Gregora16548e2009-08-11 05:31:07 +00004240template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004241Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004242TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004243 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004244}
Mike Stump11289f42009-09-09 15:08:12 +00004245
Douglas Gregora16548e2009-08-11 05:31:07 +00004246template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004247Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004248TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004249 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004250}
Mike Stump11289f42009-09-09 15:08:12 +00004251
Douglas Gregora16548e2009-08-11 05:31:07 +00004252template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004253Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004254TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004255 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004256}
Mike Stump11289f42009-09-09 15:08:12 +00004257
Douglas Gregora16548e2009-08-11 05:31:07 +00004258template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004259Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004260TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004261 return SemaRef.Owned(E->Retain());
4262}
4263
4264template<typename Derived>
4265Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004266TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004267 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4268 if (SubExpr.isInvalid())
4269 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004270
Douglas Gregora16548e2009-08-11 05:31:07 +00004271 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004272 return SemaRef.Owned(E->Retain());
4273
4274 return getDerived().RebuildParenExpr(move(SubExpr), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004275 E->getRParen());
4276}
4277
Mike Stump11289f42009-09-09 15:08:12 +00004278template<typename Derived>
4279Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004280TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
4281 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00004282 if (SubExpr.isInvalid())
4283 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004284
Douglas Gregora16548e2009-08-11 05:31:07 +00004285 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004286 return SemaRef.Owned(E->Retain());
4287
Douglas Gregora16548e2009-08-11 05:31:07 +00004288 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
4289 E->getOpcode(),
4290 move(SubExpr));
4291}
Mike Stump11289f42009-09-09 15:08:12 +00004292
Douglas Gregora16548e2009-08-11 05:31:07 +00004293template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004294Sema::OwningExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00004295TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
4296 // Transform the type.
4297 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
4298 if (!Type)
4299 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004300
Douglas Gregor882211c2010-04-28 22:16:22 +00004301 // Transform all of the components into components similar to what the
4302 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00004303 // FIXME: It would be slightly more efficient in the non-dependent case to
4304 // just map FieldDecls, rather than requiring the rebuilder to look for
4305 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00004306 // template code that we don't care.
4307 bool ExprChanged = false;
4308 typedef Action::OffsetOfComponent Component;
4309 typedef OffsetOfExpr::OffsetOfNode Node;
4310 llvm::SmallVector<Component, 4> Components;
4311 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
4312 const Node &ON = E->getComponent(I);
4313 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00004314 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00004315 Comp.LocStart = ON.getRange().getBegin();
4316 Comp.LocEnd = ON.getRange().getEnd();
4317 switch (ON.getKind()) {
4318 case Node::Array: {
4319 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
4320 OwningExprResult Index = getDerived().TransformExpr(FromIndex);
4321 if (Index.isInvalid())
4322 return getSema().ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004323
Douglas Gregor882211c2010-04-28 22:16:22 +00004324 ExprChanged = ExprChanged || Index.get() != FromIndex;
4325 Comp.isBrackets = true;
4326 Comp.U.E = Index.takeAs<Expr>(); // FIXME: leaked
4327 break;
4328 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004329
Douglas Gregor882211c2010-04-28 22:16:22 +00004330 case Node::Field:
4331 case Node::Identifier:
4332 Comp.isBrackets = false;
4333 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00004334 if (!Comp.U.IdentInfo)
4335 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004336
Douglas Gregor882211c2010-04-28 22:16:22 +00004337 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004338
Douglas Gregord1702062010-04-29 00:18:15 +00004339 case Node::Base:
4340 // Will be recomputed during the rebuild.
4341 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00004342 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004343
Douglas Gregor882211c2010-04-28 22:16:22 +00004344 Components.push_back(Comp);
4345 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004346
Douglas Gregor882211c2010-04-28 22:16:22 +00004347 // If nothing changed, retain the existing expression.
4348 if (!getDerived().AlwaysRebuild() &&
4349 Type == E->getTypeSourceInfo() &&
4350 !ExprChanged)
4351 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004352
Douglas Gregor882211c2010-04-28 22:16:22 +00004353 // Build a new offsetof expression.
4354 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
4355 Components.data(), Components.size(),
4356 E->getRParenLoc());
4357}
4358
4359template<typename Derived>
4360Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004361TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004362 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00004363 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00004364
John McCallbcd03502009-12-07 02:54:59 +00004365 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00004366 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004367 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004368
John McCall4c98fd82009-11-04 07:28:41 +00004369 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004370 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004371
John McCall4c98fd82009-11-04 07:28:41 +00004372 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004373 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004374 E->getSourceRange());
4375 }
Mike Stump11289f42009-09-09 15:08:12 +00004376
Douglas Gregora16548e2009-08-11 05:31:07 +00004377 Sema::OwningExprResult SubExpr(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00004378 {
Douglas Gregora16548e2009-08-11 05:31:07 +00004379 // C++0x [expr.sizeof]p1:
4380 // The operand is either an expression, which is an unevaluated operand
4381 // [...]
4382 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004383
Douglas Gregora16548e2009-08-11 05:31:07 +00004384 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
4385 if (SubExpr.isInvalid())
4386 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004387
Douglas Gregora16548e2009-08-11 05:31:07 +00004388 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
4389 return SemaRef.Owned(E->Retain());
4390 }
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregora16548e2009-08-11 05:31:07 +00004392 return getDerived().RebuildSizeOfAlignOf(move(SubExpr), E->getOperatorLoc(),
4393 E->isSizeOf(),
4394 E->getSourceRange());
4395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregora16548e2009-08-11 05:31:07 +00004397template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004398Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004399TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004400 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4401 if (LHS.isInvalid())
4402 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregora16548e2009-08-11 05:31:07 +00004404 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4405 if (RHS.isInvalid())
4406 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004407
4408
Douglas Gregora16548e2009-08-11 05:31:07 +00004409 if (!getDerived().AlwaysRebuild() &&
4410 LHS.get() == E->getLHS() &&
4411 RHS.get() == E->getRHS())
4412 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004413
Douglas Gregora16548e2009-08-11 05:31:07 +00004414 return getDerived().RebuildArraySubscriptExpr(move(LHS),
4415 /*FIXME:*/E->getLHS()->getLocStart(),
4416 move(RHS),
4417 E->getRBracketLoc());
4418}
Mike Stump11289f42009-09-09 15:08:12 +00004419
4420template<typename Derived>
4421Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004422TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004423 // Transform the callee.
4424 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4425 if (Callee.isInvalid())
4426 return SemaRef.ExprError();
4427
4428 // Transform arguments.
4429 bool ArgChanged = false;
4430 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4431 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4432 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
4433 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4434 if (Arg.isInvalid())
4435 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004436
Douglas Gregora16548e2009-08-11 05:31:07 +00004437 // FIXME: Wrong source location information for the ','.
4438 FakeCommaLocs.push_back(
4439 SemaRef.PP.getLocForEndOfToken(E->getArg(I)->getSourceRange().getEnd()));
Mike Stump11289f42009-09-09 15:08:12 +00004440
4441 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
Douglas Gregora16548e2009-08-11 05:31:07 +00004442 Args.push_back(Arg.takeAs<Expr>());
4443 }
Mike Stump11289f42009-09-09 15:08:12 +00004444
Douglas Gregora16548e2009-08-11 05:31:07 +00004445 if (!getDerived().AlwaysRebuild() &&
4446 Callee.get() == E->getCallee() &&
4447 !ArgChanged)
4448 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregora16548e2009-08-11 05:31:07 +00004450 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00004451 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004452 = ((Expr *)Callee.get())->getSourceRange().getBegin();
4453 return getDerived().RebuildCallExpr(move(Callee), FakeLParenLoc,
4454 move_arg(Args),
4455 FakeCommaLocs.data(),
4456 E->getRParenLoc());
4457}
Mike Stump11289f42009-09-09 15:08:12 +00004458
4459template<typename Derived>
4460Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004461TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004462 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4463 if (Base.isInvalid())
4464 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004465
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004466 NestedNameSpecifier *Qualifier = 0;
4467 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00004468 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004469 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00004470 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00004471 if (Qualifier == 0)
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004472 return SemaRef.ExprError();
4473 }
Mike Stump11289f42009-09-09 15:08:12 +00004474
Eli Friedman2cfcef62009-12-04 06:40:45 +00004475 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004476 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
4477 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00004478 if (!Member)
4479 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004480
John McCall16df1e52010-03-30 21:47:33 +00004481 NamedDecl *FoundDecl = E->getFoundDecl();
4482 if (FoundDecl == E->getMemberDecl()) {
4483 FoundDecl = Member;
4484 } else {
4485 FoundDecl = cast_or_null<NamedDecl>(
4486 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
4487 if (!FoundDecl)
4488 return SemaRef.ExprError();
4489 }
4490
Douglas Gregora16548e2009-08-11 05:31:07 +00004491 if (!getDerived().AlwaysRebuild() &&
4492 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004493 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004494 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00004495 FoundDecl == E->getFoundDecl() &&
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004496 !E->hasExplicitTemplateArgumentList()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004497
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004498 // Mark it referenced in the new context regardless.
4499 // FIXME: this is a bit instantiation-specific.
4500 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
Mike Stump11289f42009-09-09 15:08:12 +00004501 return SemaRef.Owned(E->Retain());
Anders Carlsson9c45ad72009-12-22 05:24:09 +00004502 }
Douglas Gregora16548e2009-08-11 05:31:07 +00004503
John McCall6b51f282009-11-23 01:53:49 +00004504 TemplateArgumentListInfo TransArgs;
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004505 if (E->hasExplicitTemplateArgumentList()) {
John McCall6b51f282009-11-23 01:53:49 +00004506 TransArgs.setLAngleLoc(E->getLAngleLoc());
4507 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004508 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00004509 TemplateArgumentLoc Loc;
4510 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004511 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00004512 TransArgs.addArgument(Loc);
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004513 }
4514 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004515
Douglas Gregora16548e2009-08-11 05:31:07 +00004516 // FIXME: Bogus source location for the operator
4517 SourceLocation FakeOperatorLoc
4518 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
4519
John McCall38836f02010-01-15 08:34:02 +00004520 // FIXME: to do this check properly, we will need to preserve the
4521 // first-qualifier-in-scope here, just in case we had a dependent
4522 // base (and therefore couldn't do the check) and a
4523 // nested-name-qualifier (and therefore could do the lookup).
4524 NamedDecl *FirstQualifierInScope = 0;
4525
Douglas Gregora16548e2009-08-11 05:31:07 +00004526 return getDerived().RebuildMemberExpr(move(Base), FakeOperatorLoc,
4527 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00004528 Qualifier,
4529 E->getQualifierRange(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004530 E->getMemberLoc(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00004531 Member,
John McCall16df1e52010-03-30 21:47:33 +00004532 FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00004533 (E->hasExplicitTemplateArgumentList()
4534 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00004535 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00004536}
Mike Stump11289f42009-09-09 15:08:12 +00004537
Douglas Gregora16548e2009-08-11 05:31:07 +00004538template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004539Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004540TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004541 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4542 if (LHS.isInvalid())
4543 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004544
Douglas Gregora16548e2009-08-11 05:31:07 +00004545 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4546 if (RHS.isInvalid())
4547 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004548
Douglas Gregora16548e2009-08-11 05:31:07 +00004549 if (!getDerived().AlwaysRebuild() &&
4550 LHS.get() == E->getLHS() &&
4551 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004552 return SemaRef.Owned(E->Retain());
4553
Douglas Gregora16548e2009-08-11 05:31:07 +00004554 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
4555 move(LHS), move(RHS));
4556}
4557
Mike Stump11289f42009-09-09 15:08:12 +00004558template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00004559Sema::OwningExprResult
4560TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00004561 CompoundAssignOperator *E) {
4562 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00004563}
Mike Stump11289f42009-09-09 15:08:12 +00004564
Douglas Gregora16548e2009-08-11 05:31:07 +00004565template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004566Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004567TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004568 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4569 if (Cond.isInvalid())
4570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004571
Douglas Gregora16548e2009-08-11 05:31:07 +00004572 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4573 if (LHS.isInvalid())
4574 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004575
Douglas Gregora16548e2009-08-11 05:31:07 +00004576 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4577 if (RHS.isInvalid())
4578 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004579
Douglas Gregora16548e2009-08-11 05:31:07 +00004580 if (!getDerived().AlwaysRebuild() &&
4581 Cond.get() == E->getCond() &&
4582 LHS.get() == E->getLHS() &&
4583 RHS.get() == E->getRHS())
4584 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004585
4586 return getDerived().RebuildConditionalOperator(move(Cond),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004587 E->getQuestionLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00004588 move(LHS),
Douglas Gregor7e112b02009-08-26 14:37:04 +00004589 E->getColonLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004590 move(RHS));
4591}
Mike Stump11289f42009-09-09 15:08:12 +00004592
4593template<typename Derived>
4594Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004595TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00004596 // Implicit casts are eliminated during transformation, since they
4597 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00004598 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004599}
Mike Stump11289f42009-09-09 15:08:12 +00004600
Douglas Gregora16548e2009-08-11 05:31:07 +00004601template<typename Derived>
4602Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004603TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00004604 TypeSourceInfo *OldT;
4605 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00004606 {
4607 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00004608 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004609 = SemaRef.PP.getLocForEndOfToken(E->getLParenLoc());
4610 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004611
John McCall97513962010-01-15 18:39:57 +00004612 OldT = E->getTypeInfoAsWritten();
4613 NewT = getDerived().TransformType(OldT);
4614 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00004615 return SemaRef.ExprError();
4616 }
Mike Stump11289f42009-09-09 15:08:12 +00004617
Douglas Gregor6131b442009-12-12 18:16:41 +00004618 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00004619 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00004620 if (SubExpr.isInvalid())
4621 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004622
Douglas Gregora16548e2009-08-11 05:31:07 +00004623 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00004624 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004625 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00004626 return SemaRef.Owned(E->Retain());
4627
John McCall97513962010-01-15 18:39:57 +00004628 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
4629 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004630 E->getRParenLoc(),
4631 move(SubExpr));
4632}
Mike Stump11289f42009-09-09 15:08:12 +00004633
Douglas Gregora16548e2009-08-11 05:31:07 +00004634template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004635Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004636TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00004637 TypeSourceInfo *OldT = E->getTypeSourceInfo();
4638 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
4639 if (!NewT)
4640 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004641
Douglas Gregora16548e2009-08-11 05:31:07 +00004642 OwningExprResult Init = getDerived().TransformExpr(E->getInitializer());
4643 if (Init.isInvalid())
4644 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004645
Douglas Gregora16548e2009-08-11 05:31:07 +00004646 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00004647 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00004648 Init.get() == E->getInitializer())
Mike Stump11289f42009-09-09 15:08:12 +00004649 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004650
John McCall5d7aa7f2010-01-19 22:33:45 +00004651 // Note: the expression type doesn't necessarily match the
4652 // type-as-written, but that's okay, because it should always be
4653 // derivable from the initializer.
4654
John McCalle15bbff2010-01-18 19:35:47 +00004655 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00004656 /*FIXME:*/E->getInitializer()->getLocEnd(),
4657 move(Init));
4658}
Mike Stump11289f42009-09-09 15:08:12 +00004659
Douglas Gregora16548e2009-08-11 05:31:07 +00004660template<typename Derived>
4661Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004662TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004663 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
4664 if (Base.isInvalid())
4665 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregora16548e2009-08-11 05:31:07 +00004667 if (!getDerived().AlwaysRebuild() &&
4668 Base.get() == E->getBase())
Mike Stump11289f42009-09-09 15:08:12 +00004669 return SemaRef.Owned(E->Retain());
4670
Douglas Gregora16548e2009-08-11 05:31:07 +00004671 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00004672 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00004673 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
4674 return getDerived().RebuildExtVectorElementExpr(move(Base), FakeOperatorLoc,
4675 E->getAccessorLoc(),
4676 E->getAccessor());
4677}
Mike Stump11289f42009-09-09 15:08:12 +00004678
Douglas Gregora16548e2009-08-11 05:31:07 +00004679template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004680Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004681TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004682 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00004683
Douglas Gregora16548e2009-08-11 05:31:07 +00004684 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4685 for (unsigned I = 0, N = E->getNumInits(); I != N; ++I) {
4686 OwningExprResult Init = getDerived().TransformExpr(E->getInit(I));
4687 if (Init.isInvalid())
4688 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregora16548e2009-08-11 05:31:07 +00004690 InitChanged = InitChanged || Init.get() != E->getInit(I);
4691 Inits.push_back(Init.takeAs<Expr>());
4692 }
Mike Stump11289f42009-09-09 15:08:12 +00004693
Douglas Gregora16548e2009-08-11 05:31:07 +00004694 if (!getDerived().AlwaysRebuild() && !InitChanged)
Mike Stump11289f42009-09-09 15:08:12 +00004695 return SemaRef.Owned(E->Retain());
4696
Douglas Gregora16548e2009-08-11 05:31:07 +00004697 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00004698 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00004699}
Mike Stump11289f42009-09-09 15:08:12 +00004700
Douglas Gregora16548e2009-08-11 05:31:07 +00004701template<typename Derived>
4702Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004703TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004704 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00004705
Douglas Gregorebe10102009-08-20 07:17:43 +00004706 // transform the initializer value
Douglas Gregora16548e2009-08-11 05:31:07 +00004707 OwningExprResult Init = getDerived().TransformExpr(E->getInit());
4708 if (Init.isInvalid())
4709 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004710
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 // transform the designators.
Douglas Gregora16548e2009-08-11 05:31:07 +00004712 ASTOwningVector<&ActionBase::DeleteExpr, 4> ArrayExprs(SemaRef);
4713 bool ExprChanged = false;
4714 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
4715 DEnd = E->designators_end();
4716 D != DEnd; ++D) {
4717 if (D->isFieldDesignator()) {
4718 Desig.AddDesignator(Designator::getField(D->getFieldName(),
4719 D->getDotLoc(),
4720 D->getFieldLoc()));
4721 continue;
4722 }
Mike Stump11289f42009-09-09 15:08:12 +00004723
Douglas Gregora16548e2009-08-11 05:31:07 +00004724 if (D->isArrayDesignator()) {
4725 OwningExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
4726 if (Index.isInvalid())
4727 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004728
4729 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004730 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004731
Douglas Gregora16548e2009-08-11 05:31:07 +00004732 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
4733 ArrayExprs.push_back(Index.release());
4734 continue;
4735 }
Mike Stump11289f42009-09-09 15:08:12 +00004736
Douglas Gregora16548e2009-08-11 05:31:07 +00004737 assert(D->isArrayRangeDesignator() && "New kind of designator?");
Mike Stump11289f42009-09-09 15:08:12 +00004738 OwningExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00004739 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
4740 if (Start.isInvalid())
4741 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004742
Douglas Gregora16548e2009-08-11 05:31:07 +00004743 OwningExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
4744 if (End.isInvalid())
4745 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004746
4747 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004748 End.get(),
4749 D->getLBracketLoc(),
4750 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00004751
Douglas Gregora16548e2009-08-11 05:31:07 +00004752 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
4753 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00004754
Douglas Gregora16548e2009-08-11 05:31:07 +00004755 ArrayExprs.push_back(Start.release());
4756 ArrayExprs.push_back(End.release());
4757 }
Mike Stump11289f42009-09-09 15:08:12 +00004758
Douglas Gregora16548e2009-08-11 05:31:07 +00004759 if (!getDerived().AlwaysRebuild() &&
4760 Init.get() == E->getInit() &&
4761 !ExprChanged)
4762 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004763
Douglas Gregora16548e2009-08-11 05:31:07 +00004764 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
4765 E->getEqualOrColonLoc(),
4766 E->usesGNUSyntax(), move(Init));
4767}
Mike Stump11289f42009-09-09 15:08:12 +00004768
Douglas Gregora16548e2009-08-11 05:31:07 +00004769template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004770Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00004771TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00004772 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00004773 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004774
Douglas Gregor3da3c062009-10-28 00:29:27 +00004775 // FIXME: Will we ever have proper type location here? Will we actually
4776 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00004777 QualType T = getDerived().TransformType(E->getType());
4778 if (T.isNull())
4779 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004780
Douglas Gregora16548e2009-08-11 05:31:07 +00004781 if (!getDerived().AlwaysRebuild() &&
4782 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00004783 return SemaRef.Owned(E->Retain());
4784
Douglas Gregora16548e2009-08-11 05:31:07 +00004785 return getDerived().RebuildImplicitValueInitExpr(T);
4786}
Mike Stump11289f42009-09-09 15:08:12 +00004787
Douglas Gregora16548e2009-08-11 05:31:07 +00004788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004789Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004790TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004791 // FIXME: Do we want the type as written?
4792 QualType T;
Mike Stump11289f42009-09-09 15:08:12 +00004793
Douglas Gregora16548e2009-08-11 05:31:07 +00004794 {
4795 // FIXME: Source location isn't quite accurate.
4796 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
4797 T = getDerived().TransformType(E->getType());
4798 if (T.isNull())
4799 return SemaRef.ExprError();
4800 }
Mike Stump11289f42009-09-09 15:08:12 +00004801
Douglas Gregora16548e2009-08-11 05:31:07 +00004802 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
4803 if (SubExpr.isInvalid())
4804 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004805
Douglas Gregora16548e2009-08-11 05:31:07 +00004806 if (!getDerived().AlwaysRebuild() &&
4807 T == E->getType() &&
4808 SubExpr.get() == E->getSubExpr())
4809 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004810
Douglas Gregora16548e2009-08-11 05:31:07 +00004811 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), move(SubExpr),
4812 T, E->getRParenLoc());
4813}
4814
4815template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004816Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004817TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004818 bool ArgumentChanged = false;
4819 ASTOwningVector<&ActionBase::DeleteExpr, 4> Inits(SemaRef);
4820 for (unsigned I = 0, N = E->getNumExprs(); I != N; ++I) {
4821 OwningExprResult Init = getDerived().TransformExpr(E->getExpr(I));
4822 if (Init.isInvalid())
4823 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004824
Douglas Gregora16548e2009-08-11 05:31:07 +00004825 ArgumentChanged = ArgumentChanged || Init.get() != E->getExpr(I);
4826 Inits.push_back(Init.takeAs<Expr>());
4827 }
Mike Stump11289f42009-09-09 15:08:12 +00004828
Douglas Gregora16548e2009-08-11 05:31:07 +00004829 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
4830 move_arg(Inits),
4831 E->getRParenLoc());
4832}
Mike Stump11289f42009-09-09 15:08:12 +00004833
Douglas Gregora16548e2009-08-11 05:31:07 +00004834/// \brief Transform an address-of-label expression.
4835///
4836/// By default, the transformation of an address-of-label expression always
4837/// rebuilds the expression, so that the label identifier can be resolved to
4838/// the corresponding label statement by semantic analysis.
4839template<typename Derived>
4840Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004841TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004842 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
4843 E->getLabel());
4844}
Mike Stump11289f42009-09-09 15:08:12 +00004845
4846template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00004847Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004848TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004849 OwningStmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00004850 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
4851 if (SubStmt.isInvalid())
4852 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004853
Douglas Gregora16548e2009-08-11 05:31:07 +00004854 if (!getDerived().AlwaysRebuild() &&
4855 SubStmt.get() == E->getSubStmt())
4856 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00004857
4858 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00004859 move(SubStmt),
4860 E->getRParenLoc());
4861}
Mike Stump11289f42009-09-09 15:08:12 +00004862
Douglas Gregora16548e2009-08-11 05:31:07 +00004863template<typename Derived>
4864Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004865TreeTransform<Derived>::TransformTypesCompatibleExpr(TypesCompatibleExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004866 QualType T1, T2;
4867 {
4868 // FIXME: Source location isn't quite accurate.
4869 TemporaryBase Rebase(*this, E->getBuiltinLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00004870
Douglas Gregora16548e2009-08-11 05:31:07 +00004871 T1 = getDerived().TransformType(E->getArgType1());
4872 if (T1.isNull())
4873 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004874
Douglas Gregora16548e2009-08-11 05:31:07 +00004875 T2 = getDerived().TransformType(E->getArgType2());
4876 if (T2.isNull())
4877 return SemaRef.ExprError();
4878 }
4879
4880 if (!getDerived().AlwaysRebuild() &&
4881 T1 == E->getArgType1() &&
4882 T2 == E->getArgType2())
Mike Stump11289f42009-09-09 15:08:12 +00004883 return SemaRef.Owned(E->Retain());
4884
Douglas Gregora16548e2009-08-11 05:31:07 +00004885 return getDerived().RebuildTypesCompatibleExpr(E->getBuiltinLoc(),
4886 T1, T2, E->getRParenLoc());
4887}
Mike Stump11289f42009-09-09 15:08:12 +00004888
Douglas Gregora16548e2009-08-11 05:31:07 +00004889template<typename Derived>
4890Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004891TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00004892 OwningExprResult Cond = getDerived().TransformExpr(E->getCond());
4893 if (Cond.isInvalid())
4894 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004895
Douglas Gregora16548e2009-08-11 05:31:07 +00004896 OwningExprResult LHS = getDerived().TransformExpr(E->getLHS());
4897 if (LHS.isInvalid())
4898 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004899
Douglas Gregora16548e2009-08-11 05:31:07 +00004900 OwningExprResult RHS = getDerived().TransformExpr(E->getRHS());
4901 if (RHS.isInvalid())
4902 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004903
Douglas Gregora16548e2009-08-11 05:31:07 +00004904 if (!getDerived().AlwaysRebuild() &&
4905 Cond.get() == E->getCond() &&
4906 LHS.get() == E->getLHS() &&
4907 RHS.get() == E->getRHS())
Mike Stump11289f42009-09-09 15:08:12 +00004908 return SemaRef.Owned(E->Retain());
4909
Douglas Gregora16548e2009-08-11 05:31:07 +00004910 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
4911 move(Cond), move(LHS), move(RHS),
4912 E->getRParenLoc());
4913}
Mike Stump11289f42009-09-09 15:08:12 +00004914
Douglas Gregora16548e2009-08-11 05:31:07 +00004915template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004916Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004917TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00004918 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00004919}
4920
4921template<typename Derived>
4922Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00004923TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004924 switch (E->getOperator()) {
4925 case OO_New:
4926 case OO_Delete:
4927 case OO_Array_New:
4928 case OO_Array_Delete:
4929 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
4930 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004931
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004932 case OO_Call: {
4933 // This is a call to an object's operator().
4934 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
4935
4936 // Transform the object itself.
4937 OwningExprResult Object = getDerived().TransformExpr(E->getArg(0));
4938 if (Object.isInvalid())
4939 return SemaRef.ExprError();
4940
4941 // FIXME: Poor location information
4942 SourceLocation FakeLParenLoc
4943 = SemaRef.PP.getLocForEndOfToken(
4944 static_cast<Expr *>(Object.get())->getLocEnd());
4945
4946 // Transform the call arguments.
4947 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
4948 llvm::SmallVector<SourceLocation, 4> FakeCommaLocs;
4949 for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
Douglas Gregord196a582009-12-14 19:27:10 +00004950 if (getDerived().DropCallArgument(E->getArg(I)))
4951 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004952
Douglas Gregorb08f1a72009-12-13 20:44:55 +00004953 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
4954 if (Arg.isInvalid())
4955 return SemaRef.ExprError();
4956
4957 // FIXME: Poor source location information.
4958 SourceLocation FakeCommaLoc
4959 = SemaRef.PP.getLocForEndOfToken(
4960 static_cast<Expr *>(Arg.get())->getLocEnd());
4961 FakeCommaLocs.push_back(FakeCommaLoc);
4962 Args.push_back(Arg.release());
4963 }
4964
4965 return getDerived().RebuildCallExpr(move(Object), FakeLParenLoc,
4966 move_arg(Args),
4967 FakeCommaLocs.data(),
4968 E->getLocEnd());
4969 }
4970
4971#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
4972 case OO_##Name:
4973#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
4974#include "clang/Basic/OperatorKinds.def"
4975 case OO_Subscript:
4976 // Handled below.
4977 break;
4978
4979 case OO_Conditional:
4980 llvm_unreachable("conditional operator is not actually overloadable");
4981 return SemaRef.ExprError();
4982
4983 case OO_None:
4984 case NUM_OVERLOADED_OPERATORS:
4985 llvm_unreachable("not an overloaded operator?");
4986 return SemaRef.ExprError();
4987 }
4988
Douglas Gregora16548e2009-08-11 05:31:07 +00004989 OwningExprResult Callee = getDerived().TransformExpr(E->getCallee());
4990 if (Callee.isInvalid())
4991 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00004992
John McCall47f29ea2009-12-08 09:21:05 +00004993 OwningExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00004994 if (First.isInvalid())
4995 return SemaRef.ExprError();
4996
4997 OwningExprResult Second(SemaRef);
4998 if (E->getNumArgs() == 2) {
4999 Second = getDerived().TransformExpr(E->getArg(1));
5000 if (Second.isInvalid())
5001 return SemaRef.ExprError();
5002 }
Mike Stump11289f42009-09-09 15:08:12 +00005003
Douglas Gregora16548e2009-08-11 05:31:07 +00005004 if (!getDerived().AlwaysRebuild() &&
5005 Callee.get() == E->getCallee() &&
5006 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005007 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
5008 return SemaRef.Owned(E->Retain());
5009
Douglas Gregora16548e2009-08-11 05:31:07 +00005010 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5011 E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005012 move(Callee),
Douglas Gregora16548e2009-08-11 05:31:07 +00005013 move(First),
5014 move(Second));
5015}
Mike Stump11289f42009-09-09 15:08:12 +00005016
Douglas Gregora16548e2009-08-11 05:31:07 +00005017template<typename Derived>
5018Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005019TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5020 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregora16548e2009-08-11 05:31:07 +00005023template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005024Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005025TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005026 TypeSourceInfo *OldT;
5027 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005028 {
5029 // FIXME: Source location isn't quite accurate.
Mike Stump11289f42009-09-09 15:08:12 +00005030 SourceLocation TypeStartLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005031 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5032 TemporaryBase Rebase(*this, TypeStartLoc, DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005033
John McCall97513962010-01-15 18:39:57 +00005034 OldT = E->getTypeInfoAsWritten();
5035 NewT = getDerived().TransformType(OldT);
5036 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005037 return SemaRef.ExprError();
5038 }
Mike Stump11289f42009-09-09 15:08:12 +00005039
Douglas Gregor6131b442009-12-12 18:16:41 +00005040 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005041 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005042 if (SubExpr.isInvalid())
5043 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005044
Douglas Gregora16548e2009-08-11 05:31:07 +00005045 if (!getDerived().AlwaysRebuild() &&
John McCall97513962010-01-15 18:39:57 +00005046 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005047 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005048 return SemaRef.Owned(E->Retain());
5049
Douglas Gregora16548e2009-08-11 05:31:07 +00005050 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005051 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005052 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5053 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5054 SourceLocation FakeRParenLoc
5055 = SemaRef.PP.getLocForEndOfToken(
5056 E->getSubExpr()->getSourceRange().getEnd());
5057 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005058 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005059 FakeLAngleLoc,
John McCall97513962010-01-15 18:39:57 +00005060 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005061 FakeRAngleLoc,
5062 FakeRAngleLoc,
5063 move(SubExpr),
5064 FakeRParenLoc);
5065}
Mike Stump11289f42009-09-09 15:08:12 +00005066
Douglas Gregora16548e2009-08-11 05:31:07 +00005067template<typename Derived>
5068Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005069TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5070 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005071}
Mike Stump11289f42009-09-09 15:08:12 +00005072
5073template<typename Derived>
5074Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005075TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5076 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005077}
5078
Douglas Gregora16548e2009-08-11 05:31:07 +00005079template<typename Derived>
5080Sema::OwningExprResult
5081TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005082 CXXReinterpretCastExpr *E) {
5083 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005084}
Mike Stump11289f42009-09-09 15:08:12 +00005085
Douglas Gregora16548e2009-08-11 05:31:07 +00005086template<typename Derived>
5087Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5089 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005090}
Mike Stump11289f42009-09-09 15:08:12 +00005091
Douglas Gregora16548e2009-08-11 05:31:07 +00005092template<typename Derived>
5093Sema::OwningExprResult
5094TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005095 CXXFunctionalCastExpr *E) {
John McCall97513962010-01-15 18:39:57 +00005096 TypeSourceInfo *OldT;
5097 TypeSourceInfo *NewT;
Douglas Gregora16548e2009-08-11 05:31:07 +00005098 {
5099 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005100
John McCall97513962010-01-15 18:39:57 +00005101 OldT = E->getTypeInfoAsWritten();
5102 NewT = getDerived().TransformType(OldT);
5103 if (!NewT)
Douglas Gregora16548e2009-08-11 05:31:07 +00005104 return SemaRef.ExprError();
5105 }
Mike Stump11289f42009-09-09 15:08:12 +00005106
Douglas Gregor6131b442009-12-12 18:16:41 +00005107 OwningExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005108 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005109 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() &&
John McCall97513962010-01-15 18:39:57 +00005113 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005114 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005115 return SemaRef.Owned(E->Retain());
5116
Douglas Gregora16548e2009-08-11 05:31:07 +00005117 // FIXME: The end of the type's source range is wrong
5118 return getDerived().RebuildCXXFunctionalCastExpr(
5119 /*FIXME:*/SourceRange(E->getTypeBeginLoc()),
John McCall97513962010-01-15 18:39:57 +00005120 NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005121 /*FIXME:*/E->getSubExpr()->getLocStart(),
5122 move(SubExpr),
5123 E->getRParenLoc());
5124}
Mike Stump11289f42009-09-09 15:08:12 +00005125
Douglas Gregora16548e2009-08-11 05:31:07 +00005126template<typename Derived>
5127Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005128TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005129 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005130 TypeSourceInfo *TInfo
5131 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5132 if (!TInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00005133 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005134
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005136 TInfo == E->getTypeOperandSourceInfo())
Douglas Gregora16548e2009-08-11 05:31:07 +00005137 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005138
Douglas Gregor9da64192010-04-26 22:37:10 +00005139 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5140 E->getLocStart(),
5141 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 E->getLocEnd());
5143 }
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 // We don't know whether the expression is potentially evaluated until
5146 // after we perform semantic analysis, so the expression is potentially
5147 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005148 EnterExpressionEvaluationContext Unevaluated(SemaRef,
Douglas Gregora16548e2009-08-11 05:31:07 +00005149 Action::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005150
Douglas Gregora16548e2009-08-11 05:31:07 +00005151 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5152 if (SubExpr.isInvalid())
5153 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregora16548e2009-08-11 05:31:07 +00005155 if (!getDerived().AlwaysRebuild() &&
5156 SubExpr.get() == E->getExprOperand())
Mike Stump11289f42009-09-09 15:08:12 +00005157 return SemaRef.Owned(E->Retain());
5158
Douglas Gregor9da64192010-04-26 22:37:10 +00005159 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5160 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005161 move(SubExpr),
5162 E->getLocEnd());
5163}
5164
5165template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00005166Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005167TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005168 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005169}
Mike Stump11289f42009-09-09 15:08:12 +00005170
Douglas Gregora16548e2009-08-11 05:31:07 +00005171template<typename Derived>
5172Sema::OwningExprResult
5173TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005174 CXXNullPtrLiteralExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005175 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005176}
Mike Stump11289f42009-09-09 15:08:12 +00005177
Douglas Gregora16548e2009-08-11 05:31:07 +00005178template<typename Derived>
5179Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005180TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005181 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005182
Douglas Gregora16548e2009-08-11 05:31:07 +00005183 QualType T = getDerived().TransformType(E->getType());
5184 if (T.isNull())
5185 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005186
Douglas Gregora16548e2009-08-11 05:31:07 +00005187 if (!getDerived().AlwaysRebuild() &&
5188 T == E->getType())
5189 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005190
Douglas Gregorb15af892010-01-07 23:12:05 +00005191 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005192}
Mike Stump11289f42009-09-09 15:08:12 +00005193
Douglas Gregora16548e2009-08-11 05:31:07 +00005194template<typename Derived>
5195Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005196TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005197 OwningExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
5198 if (SubExpr.isInvalid())
5199 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregora16548e2009-08-11 05:31:07 +00005201 if (!getDerived().AlwaysRebuild() &&
5202 SubExpr.get() == E->getSubExpr())
Mike Stump11289f42009-09-09 15:08:12 +00005203 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00005204
5205 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), move(SubExpr));
5206}
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregora16548e2009-08-11 05:31:07 +00005208template<typename Derived>
5209Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005210TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00005211 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005212 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5213 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005214 if (!Param)
5215 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005216
Chandler Carruth794da4c2010-02-08 06:42:49 +00005217 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005218 Param == E->getParam())
5219 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005220
Douglas Gregor033f6752009-12-23 23:03:06 +00005221 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00005222}
Mike Stump11289f42009-09-09 15:08:12 +00005223
Douglas Gregora16548e2009-08-11 05:31:07 +00005224template<typename Derived>
5225Sema::OwningExprResult
Douglas Gregor747eb782010-07-08 06:14:04 +00005226TreeTransform<Derived>::TransformCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005227 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5228
5229 QualType T = getDerived().TransformType(E->getType());
5230 if (T.isNull())
5231 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregora16548e2009-08-11 05:31:07 +00005233 if (!getDerived().AlwaysRebuild() &&
5234 T == E->getType())
Mike Stump11289f42009-09-09 15:08:12 +00005235 return SemaRef.Owned(E->Retain());
5236
Douglas Gregor747eb782010-07-08 06:14:04 +00005237 return getDerived().RebuildCXXScalarValueInitExpr(E->getTypeBeginLoc(),
5238 /*FIXME:*/E->getTypeBeginLoc(),
5239 T,
5240 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005241}
Mike Stump11289f42009-09-09 15:08:12 +00005242
Douglas Gregora16548e2009-08-11 05:31:07 +00005243template<typename Derived>
5244Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005245TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005246 // Transform the type that we're allocating
5247 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
5248 QualType AllocType = getDerived().TransformType(E->getAllocatedType());
5249 if (AllocType.isNull())
5250 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252 // Transform the size of the array we're allocating (if any).
5253 OwningExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
5254 if (ArraySize.isInvalid())
5255 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005256
Douglas Gregora16548e2009-08-11 05:31:07 +00005257 // Transform the placement arguments (if any).
5258 bool ArgumentChanged = false;
5259 ASTOwningVector<&ActionBase::DeleteExpr> PlacementArgs(SemaRef);
5260 for (unsigned I = 0, N = E->getNumPlacementArgs(); I != N; ++I) {
5261 OwningExprResult Arg = getDerived().TransformExpr(E->getPlacementArg(I));
5262 if (Arg.isInvalid())
5263 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265 ArgumentChanged = ArgumentChanged || Arg.get() != E->getPlacementArg(I);
5266 PlacementArgs.push_back(Arg.take());
5267 }
Mike Stump11289f42009-09-09 15:08:12 +00005268
Douglas Gregorebe10102009-08-20 07:17:43 +00005269 // transform the constructor arguments (if any).
Douglas Gregora16548e2009-08-11 05:31:07 +00005270 ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(SemaRef);
5271 for (unsigned I = 0, N = E->getNumConstructorArgs(); I != N; ++I) {
Douglas Gregor1b30b3c2010-05-26 07:10:06 +00005272 if (getDerived().DropCallArgument(E->getConstructorArg(I)))
5273 break;
5274
Douglas Gregora16548e2009-08-11 05:31:07 +00005275 OwningExprResult Arg = getDerived().TransformExpr(E->getConstructorArg(I));
5276 if (Arg.isInvalid())
5277 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005278
Douglas Gregora16548e2009-08-11 05:31:07 +00005279 ArgumentChanged = ArgumentChanged || Arg.get() != E->getConstructorArg(I);
5280 ConstructorArgs.push_back(Arg.take());
5281 }
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregord2d9da02010-02-26 00:38:10 +00005283 // Transform constructor, new operator, and delete operator.
5284 CXXConstructorDecl *Constructor = 0;
5285 if (E->getConstructor()) {
5286 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005287 getDerived().TransformDecl(E->getLocStart(),
5288 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005289 if (!Constructor)
5290 return SemaRef.ExprError();
5291 }
5292
5293 FunctionDecl *OperatorNew = 0;
5294 if (E->getOperatorNew()) {
5295 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005296 getDerived().TransformDecl(E->getLocStart(),
5297 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005298 if (!OperatorNew)
5299 return SemaRef.ExprError();
5300 }
5301
5302 FunctionDecl *OperatorDelete = 0;
5303 if (E->getOperatorDelete()) {
5304 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005305 getDerived().TransformDecl(E->getLocStart(),
5306 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005307 if (!OperatorDelete)
5308 return SemaRef.ExprError();
5309 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005310
Douglas Gregora16548e2009-08-11 05:31:07 +00005311 if (!getDerived().AlwaysRebuild() &&
5312 AllocType == E->getAllocatedType() &&
5313 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005314 Constructor == E->getConstructor() &&
5315 OperatorNew == E->getOperatorNew() &&
5316 OperatorDelete == E->getOperatorDelete() &&
5317 !ArgumentChanged) {
5318 // Mark any declarations we need as referenced.
5319 // FIXME: instantiation-specific.
5320 if (Constructor)
5321 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
5322 if (OperatorNew)
5323 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
5324 if (OperatorDelete)
5325 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005326 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005327 }
Mike Stump11289f42009-09-09 15:08:12 +00005328
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005329 if (!ArraySize.get()) {
5330 // If no array size was specified, but the new expression was
5331 // instantiated with an array type (e.g., "new T" where T is
5332 // instantiated with "int[4]"), extract the outer bound from the
5333 // array type as our array size. We do this with constant and
5334 // dependently-sized array types.
5335 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
5336 if (!ArrayT) {
5337 // Do nothing
5338 } else if (const ConstantArrayType *ConsArrayT
5339 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005340 ArraySize
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005341 = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005342 ConsArrayT->getSize(),
Douglas Gregor2e9c7952009-12-22 17:13:37 +00005343 SemaRef.Context.getSizeType(),
5344 /*FIXME:*/E->getLocStart()));
5345 AllocType = ConsArrayT->getElementType();
5346 } else if (const DependentSizedArrayType *DepArrayT
5347 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
5348 if (DepArrayT->getSizeExpr()) {
5349 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
5350 AllocType = DepArrayT->getElementType();
5351 }
5352 }
5353 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005354 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
5355 E->isGlobalNew(),
5356 /*FIXME:*/E->getLocStart(),
5357 move_arg(PlacementArgs),
5358 /*FIXME:*/E->getLocStart(),
5359 E->isParenTypeId(),
5360 AllocType,
5361 /*FIXME:*/E->getLocStart(),
5362 /*FIXME:*/SourceRange(),
5363 move(ArraySize),
5364 /*FIXME:*/E->getLocStart(),
5365 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00005366 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00005367}
Mike Stump11289f42009-09-09 15:08:12 +00005368
Douglas Gregora16548e2009-08-11 05:31:07 +00005369template<typename Derived>
5370Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005371TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005372 OwningExprResult Operand = getDerived().TransformExpr(E->getArgument());
5373 if (Operand.isInvalid())
5374 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005375
Douglas Gregord2d9da02010-02-26 00:38:10 +00005376 // Transform the delete operator, if known.
5377 FunctionDecl *OperatorDelete = 0;
5378 if (E->getOperatorDelete()) {
5379 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005380 getDerived().TransformDecl(E->getLocStart(),
5381 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00005382 if (!OperatorDelete)
5383 return SemaRef.ExprError();
5384 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005385
Douglas Gregora16548e2009-08-11 05:31:07 +00005386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00005387 Operand.get() == E->getArgument() &&
5388 OperatorDelete == E->getOperatorDelete()) {
5389 // Mark any declarations we need as referenced.
5390 // FIXME: instantiation-specific.
5391 if (OperatorDelete)
5392 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Mike Stump11289f42009-09-09 15:08:12 +00005393 return SemaRef.Owned(E->Retain());
Douglas Gregord2d9da02010-02-26 00:38:10 +00005394 }
Mike Stump11289f42009-09-09 15:08:12 +00005395
Douglas Gregora16548e2009-08-11 05:31:07 +00005396 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
5397 E->isGlobalDelete(),
5398 E->isArrayForm(),
5399 move(Operand));
5400}
Mike Stump11289f42009-09-09 15:08:12 +00005401
Douglas Gregora16548e2009-08-11 05:31:07 +00005402template<typename Derived>
5403Sema::OwningExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00005404TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005405 CXXPseudoDestructorExpr *E) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00005406 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
5407 if (Base.isInvalid())
5408 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005409
Douglas Gregor678f90d2010-02-25 01:56:36 +00005410 Sema::TypeTy *ObjectTypePtr = 0;
5411 bool MayBePseudoDestructor = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005412 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005413 E->getOperatorLoc(),
5414 E->isArrow()? tok::arrow : tok::period,
5415 ObjectTypePtr,
5416 MayBePseudoDestructor);
5417 if (Base.isInvalid())
5418 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005419
Douglas Gregor678f90d2010-02-25 01:56:36 +00005420 QualType ObjectType = QualType::getFromOpaquePtr(ObjectTypePtr);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005421 NestedNameSpecifier *Qualifier
5422 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregor90d554e2010-02-21 18:36:56 +00005423 E->getQualifierRange(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005424 ObjectType);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005425 if (E->getQualifier() && !Qualifier)
5426 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005427
Douglas Gregor678f90d2010-02-25 01:56:36 +00005428 PseudoDestructorTypeStorage Destroyed;
5429 if (E->getDestroyedTypeInfo()) {
5430 TypeSourceInfo *DestroyedTypeInfo
5431 = getDerived().TransformType(E->getDestroyedTypeInfo(), ObjectType);
5432 if (!DestroyedTypeInfo)
5433 return SemaRef.ExprError();
5434 Destroyed = DestroyedTypeInfo;
5435 } else if (ObjectType->isDependentType()) {
5436 // We aren't likely to be able to resolve the identifier down to a type
5437 // now anyway, so just retain the identifier.
5438 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
5439 E->getDestroyedTypeLoc());
5440 } else {
5441 // Look for a destructor known with the given name.
5442 CXXScopeSpec SS;
5443 if (Qualifier) {
5444 SS.setScopeRep(Qualifier);
5445 SS.setRange(E->getQualifierRange());
5446 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447
Douglas Gregor678f90d2010-02-25 01:56:36 +00005448 Sema::TypeTy *T = SemaRef.getDestructorName(E->getTildeLoc(),
5449 *E->getDestroyedTypeIdentifier(),
5450 E->getDestroyedTypeLoc(),
5451 /*Scope=*/0,
5452 SS, ObjectTypePtr,
5453 false);
5454 if (!T)
5455 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005456
Douglas Gregor678f90d2010-02-25 01:56:36 +00005457 Destroyed
5458 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
5459 E->getDestroyedTypeLoc());
5460 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005461
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005462 TypeSourceInfo *ScopeTypeInfo = 0;
5463 if (E->getScopeTypeInfo()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005464 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005465 ObjectType);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005466 if (!ScopeTypeInfo)
Douglas Gregorad8a3362009-09-04 17:36:40 +00005467 return SemaRef.ExprError();
5468 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005469
Douglas Gregorad8a3362009-09-04 17:36:40 +00005470 return getDerived().RebuildCXXPseudoDestructorExpr(move(Base),
5471 E->getOperatorLoc(),
5472 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00005473 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00005474 E->getQualifierRange(),
5475 ScopeTypeInfo,
5476 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00005477 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00005478 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00005479}
Mike Stump11289f42009-09-09 15:08:12 +00005480
Douglas Gregorad8a3362009-09-04 17:36:40 +00005481template<typename Derived>
5482Sema::OwningExprResult
John McCalld14a8642009-11-21 08:51:07 +00005483TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005484 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00005485 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
5486
5487 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
5488 Sema::LookupOrdinaryName);
5489
5490 // Transform all the decls.
5491 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
5492 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005493 NamedDecl *InstD = static_cast<NamedDecl*>(
5494 getDerived().TransformDecl(Old->getNameLoc(),
5495 *I));
John McCall84d87672009-12-10 09:41:52 +00005496 if (!InstD) {
5497 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5498 // This can happen because of dependent hiding.
5499 if (isa<UsingShadowDecl>(*I))
5500 continue;
5501 else
5502 return SemaRef.ExprError();
5503 }
John McCalle66edc12009-11-24 19:00:30 +00005504
5505 // Expand using declarations.
5506 if (isa<UsingDecl>(InstD)) {
5507 UsingDecl *UD = cast<UsingDecl>(InstD);
5508 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5509 E = UD->shadow_end(); I != E; ++I)
5510 R.addDecl(*I);
5511 continue;
5512 }
5513
5514 R.addDecl(InstD);
5515 }
5516
5517 // Resolve a kind, but don't do any further analysis. If it's
5518 // ambiguous, the callee needs to deal with it.
5519 R.resolveKind();
5520
5521 // Rebuild the nested-name qualifier, if present.
5522 CXXScopeSpec SS;
5523 NestedNameSpecifier *Qualifier = 0;
5524 if (Old->getQualifier()) {
5525 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005526 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00005527 if (!Qualifier)
5528 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005529
John McCalle66edc12009-11-24 19:00:30 +00005530 SS.setScopeRep(Qualifier);
5531 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005532 }
5533
Douglas Gregor9262f472010-04-27 18:19:34 +00005534 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00005535 CXXRecordDecl *NamingClass
5536 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
5537 Old->getNameLoc(),
5538 Old->getNamingClass()));
5539 if (!NamingClass)
5540 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005541
Douglas Gregorda7be082010-04-27 16:10:10 +00005542 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00005543 }
5544
5545 // If we have no template arguments, it's a normal declaration name.
5546 if (!Old->hasExplicitTemplateArgs())
5547 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
5548
5549 // If we have template arguments, rebuild them, then rebuild the
5550 // templateid expression.
5551 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
5552 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5553 TemplateArgumentLoc Loc;
5554 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I], Loc))
5555 return SemaRef.ExprError();
5556 TransArgs.addArgument(Loc);
5557 }
5558
5559 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
5560 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005561}
Mike Stump11289f42009-09-09 15:08:12 +00005562
Douglas Gregora16548e2009-08-11 05:31:07 +00005563template<typename Derived>
5564Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005565TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
Mike Stump11289f42009-09-09 15:08:12 +00005567
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 QualType T = getDerived().TransformType(E->getQueriedType());
5569 if (T.isNull())
5570 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 if (!getDerived().AlwaysRebuild() &&
5573 T == E->getQueriedType())
5574 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregora16548e2009-08-11 05:31:07 +00005576 // FIXME: Bad location information
5577 SourceLocation FakeLParenLoc
5578 = SemaRef.PP.getLocForEndOfToken(E->getLocStart());
Mike Stump11289f42009-09-09 15:08:12 +00005579
5580 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005581 E->getLocStart(),
5582 /*FIXME:*/FakeLParenLoc,
5583 T,
5584 E->getLocEnd());
5585}
Mike Stump11289f42009-09-09 15:08:12 +00005586
Douglas Gregora16548e2009-08-11 05:31:07 +00005587template<typename Derived>
5588Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005589TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005590 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005591 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00005592 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005593 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005594 if (!NNS)
5595 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005596
5597 DeclarationName Name
Douglas Gregorf816bd72009-09-03 22:13:48 +00005598 = getDerived().TransformDeclarationName(E->getDeclName(), E->getLocation());
5599 if (!Name)
5600 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
John McCalle66edc12009-11-24 19:00:30 +00005602 if (!E->hasExplicitTemplateArgs()) {
5603 if (!getDerived().AlwaysRebuild() &&
5604 NNS == E->getQualifier() &&
5605 Name == E->getDeclName())
5606 return SemaRef.Owned(E->Retain());
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCalle66edc12009-11-24 19:00:30 +00005608 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5609 E->getQualifierRange(),
5610 Name, E->getLocation(),
5611 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00005612 }
John McCall6b51f282009-11-23 01:53:49 +00005613
5614 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005615 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005616 TemplateArgumentLoc Loc;
5617 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregora16548e2009-08-11 05:31:07 +00005618 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005619 TransArgs.addArgument(Loc);
Douglas Gregora16548e2009-08-11 05:31:07 +00005620 }
5621
John McCalle66edc12009-11-24 19:00:30 +00005622 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
5623 E->getQualifierRange(),
5624 Name, E->getLocation(),
5625 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005626}
5627
5628template<typename Derived>
5629Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00005631 // CXXConstructExprs are always implicit, so when we have a
5632 // 1-argument construction we just transform that argument.
5633 if (E->getNumArgs() == 1 ||
5634 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
5635 return getDerived().TransformExpr(E->getArg(0));
5636
Douglas Gregora16548e2009-08-11 05:31:07 +00005637 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
5638
5639 QualType T = getDerived().TransformType(E->getType());
5640 if (T.isNull())
5641 return SemaRef.ExprError();
5642
5643 CXXConstructorDecl *Constructor
5644 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005645 getDerived().TransformDecl(E->getLocStart(),
5646 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005647 if (!Constructor)
5648 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005649
Douglas Gregora16548e2009-08-11 05:31:07 +00005650 bool ArgumentChanged = false;
5651 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
Mike Stump11289f42009-09-09 15:08:12 +00005652 for (CXXConstructExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005653 ArgEnd = E->arg_end();
5654 Arg != ArgEnd; ++Arg) {
Douglas Gregord196a582009-12-14 19:27:10 +00005655 if (getDerived().DropCallArgument(*Arg)) {
5656 ArgumentChanged = true;
5657 break;
5658 }
5659
Douglas Gregora16548e2009-08-11 05:31:07 +00005660 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5661 if (TransArg.isInvalid())
5662 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
Douglas Gregora16548e2009-08-11 05:31:07 +00005664 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5665 Args.push_back(TransArg.takeAs<Expr>());
5666 }
5667
5668 if (!getDerived().AlwaysRebuild() &&
5669 T == E->getType() &&
5670 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00005671 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00005672 // Mark the constructor as referenced.
5673 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00005674 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
Douglas Gregora16548e2009-08-11 05:31:07 +00005675 return SemaRef.Owned(E->Retain());
Douglas Gregorde550352010-02-26 00:01:57 +00005676 }
Mike Stump11289f42009-09-09 15:08:12 +00005677
Douglas Gregordb121ba2009-12-14 16:27:04 +00005678 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
5679 Constructor, E->isElidable(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005680 move_arg(Args));
5681}
Mike Stump11289f42009-09-09 15:08:12 +00005682
Douglas Gregora16548e2009-08-11 05:31:07 +00005683/// \brief Transform a C++ temporary-binding expression.
5684///
Douglas Gregor363b1512009-12-24 18:51:59 +00005685/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
5686/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005687template<typename Derived>
5688Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005689TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00005690 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005691}
Mike Stump11289f42009-09-09 15:08:12 +00005692
Anders Carlssonba6c4372010-01-29 02:39:32 +00005693/// \brief Transform a C++ reference-binding expression.
5694///
5695/// Since CXXBindReferenceExpr nodes are implicitly generated, we just
5696/// transform the subexpression and return that.
5697template<typename Derived>
5698Sema::OwningExprResult
5699TreeTransform<Derived>::TransformCXXBindReferenceExpr(CXXBindReferenceExpr *E) {
5700 return getDerived().TransformExpr(E->getSubExpr());
5701}
5702
Mike Stump11289f42009-09-09 15:08:12 +00005703/// \brief Transform a C++ expression that contains temporaries that should
Douglas Gregora16548e2009-08-11 05:31:07 +00005704/// be destroyed after the expression is evaluated.
5705///
Douglas Gregor363b1512009-12-24 18:51:59 +00005706/// Since CXXExprWithTemporaries nodes are implicitly generated, we
5707/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00005708template<typename Derived>
5709Sema::OwningExprResult
5710TreeTransform<Derived>::TransformCXXExprWithTemporaries(
Douglas Gregor363b1512009-12-24 18:51:59 +00005711 CXXExprWithTemporaries *E) {
5712 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005713}
Mike Stump11289f42009-09-09 15:08:12 +00005714
Douglas Gregora16548e2009-08-11 05:31:07 +00005715template<typename Derived>
5716Sema::OwningExprResult
5717TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005718 CXXTemporaryObjectExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005719 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5720 QualType T = getDerived().TransformType(E->getType());
5721 if (T.isNull())
5722 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005723
Douglas Gregora16548e2009-08-11 05:31:07 +00005724 CXXConstructorDecl *Constructor
5725 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00005726 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005727 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005728 if (!Constructor)
5729 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005730
Douglas Gregora16548e2009-08-11 05:31:07 +00005731 bool ArgumentChanged = false;
5732 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5733 Args.reserve(E->getNumArgs());
Mike Stump11289f42009-09-09 15:08:12 +00005734 for (CXXTemporaryObjectExpr::arg_iterator Arg = E->arg_begin(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 ArgEnd = E->arg_end();
5736 Arg != ArgEnd; ++Arg) {
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005737 if (getDerived().DropCallArgument(*Arg)) {
5738 ArgumentChanged = true;
5739 break;
5740 }
5741
Douglas Gregora16548e2009-08-11 05:31:07 +00005742 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5743 if (TransArg.isInvalid())
5744 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5747 Args.push_back((Expr *)TransArg.release());
5748 }
Mike Stump11289f42009-09-09 15:08:12 +00005749
Douglas Gregora16548e2009-08-11 05:31:07 +00005750 if (!getDerived().AlwaysRebuild() &&
5751 T == E->getType() &&
5752 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005753 !ArgumentChanged) {
5754 // FIXME: Instantiation-specific
5755 SemaRef.MarkDeclarationReferenced(E->getTypeBeginLoc(), Constructor);
Chandler Carruthb32b3442010-03-31 18:34:58 +00005756 return SemaRef.MaybeBindToTemporary(E->Retain());
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00005757 }
Mike Stump11289f42009-09-09 15:08:12 +00005758
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 // FIXME: Bogus location information
5760 SourceLocation CommaLoc;
5761 if (Args.size() > 1) {
5762 Expr *First = (Expr *)Args[0];
Mike Stump11289f42009-09-09 15:08:12 +00005763 CommaLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005764 = SemaRef.PP.getLocForEndOfToken(First->getSourceRange().getEnd());
5765 }
5766 return getDerived().RebuildCXXTemporaryObjectExpr(E->getTypeBeginLoc(),
5767 T,
5768 /*FIXME:*/E->getTypeBeginLoc(),
5769 move_arg(Args),
5770 &CommaLoc,
5771 E->getLocEnd());
5772}
Mike Stump11289f42009-09-09 15:08:12 +00005773
Douglas Gregora16548e2009-08-11 05:31:07 +00005774template<typename Derived>
5775Sema::OwningExprResult
5776TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005777 CXXUnresolvedConstructExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 TemporaryBase Rebase(*this, E->getTypeBeginLoc(), DeclarationName());
5779 QualType T = getDerived().TransformType(E->getTypeAsWritten());
5780 if (T.isNull())
5781 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005782
Douglas Gregora16548e2009-08-11 05:31:07 +00005783 bool ArgumentChanged = false;
5784 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
5785 llvm::SmallVector<SourceLocation, 8> FakeCommaLocs;
5786 for (CXXUnresolvedConstructExpr::arg_iterator Arg = E->arg_begin(),
5787 ArgEnd = E->arg_end();
5788 Arg != ArgEnd; ++Arg) {
5789 OwningExprResult TransArg = getDerived().TransformExpr(*Arg);
5790 if (TransArg.isInvalid())
5791 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005792
Douglas Gregora16548e2009-08-11 05:31:07 +00005793 ArgumentChanged = ArgumentChanged || TransArg.get() != *Arg;
5794 FakeCommaLocs.push_back(
5795 SemaRef.PP.getLocForEndOfToken((*Arg)->getLocEnd()));
5796 Args.push_back(TransArg.takeAs<Expr>());
5797 }
Mike Stump11289f42009-09-09 15:08:12 +00005798
Douglas Gregora16548e2009-08-11 05:31:07 +00005799 if (!getDerived().AlwaysRebuild() &&
5800 T == E->getTypeAsWritten() &&
5801 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00005802 return SemaRef.Owned(E->Retain());
5803
Douglas Gregora16548e2009-08-11 05:31:07 +00005804 // FIXME: we're faking the locations of the commas
5805 return getDerived().RebuildCXXUnresolvedConstructExpr(E->getTypeBeginLoc(),
5806 T,
5807 E->getLParenLoc(),
5808 move_arg(Args),
5809 FakeCommaLocs.data(),
5810 E->getRParenLoc());
5811}
Mike Stump11289f42009-09-09 15:08:12 +00005812
Douglas Gregora16548e2009-08-11 05:31:07 +00005813template<typename Derived>
5814Sema::OwningExprResult
John McCall8cd78132009-11-19 22:55:06 +00005815TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005816 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005818 OwningExprResult Base(SemaRef, (Expr*) 0);
5819 Expr *OldBase;
5820 QualType BaseType;
5821 QualType ObjectType;
5822 if (!E->isImplicitAccess()) {
5823 OldBase = E->getBase();
5824 Base = getDerived().TransformExpr(OldBase);
5825 if (Base.isInvalid())
5826 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005827
John McCall2d74de92009-12-01 22:10:20 +00005828 // Start the member reference and compute the object's type.
5829 Sema::TypeTy *ObjectTy = 0;
Douglas Gregore610ada2010-02-24 18:44:31 +00005830 bool MayBePseudoDestructor = false;
John McCall2d74de92009-12-01 22:10:20 +00005831 Base = SemaRef.ActOnStartCXXMemberReference(0, move(Base),
5832 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005833 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00005834 ObjectTy,
5835 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00005836 if (Base.isInvalid())
5837 return SemaRef.ExprError();
5838
5839 ObjectType = QualType::getFromOpaquePtr(ObjectTy);
5840 BaseType = ((Expr*) Base.get())->getType();
5841 } else {
5842 OldBase = 0;
5843 BaseType = getDerived().TransformType(E->getBaseType());
5844 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
5845 }
Mike Stump11289f42009-09-09 15:08:12 +00005846
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005847 // Transform the first part of the nested-name-specifier that qualifies
5848 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00005849 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00005850 = getDerived().TransformFirstQualifierInScope(
5851 E->getFirstQualifierFoundInScope(),
5852 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00005853
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005854 NestedNameSpecifier *Qualifier = 0;
5855 if (E->getQualifier()) {
5856 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
5857 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00005858 ObjectType,
5859 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005860 if (!Qualifier)
5861 return SemaRef.ExprError();
5862 }
Mike Stump11289f42009-09-09 15:08:12 +00005863
5864 DeclarationName Name
Douglas Gregorc59e5612009-10-19 22:04:39 +00005865 = getDerived().TransformDeclarationName(E->getMember(), E->getMemberLoc(),
John McCall2d74de92009-12-01 22:10:20 +00005866 ObjectType);
Douglas Gregorf816bd72009-09-03 22:13:48 +00005867 if (!Name)
5868 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005869
John McCall2d74de92009-12-01 22:10:20 +00005870 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00005871 // This is a reference to a member without an explicitly-specified
5872 // template argument list. Optimize for this common case.
5873 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00005874 Base.get() == OldBase &&
5875 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00005876 Qualifier == E->getQualifier() &&
5877 Name == E->getMember() &&
5878 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Mike Stump11289f42009-09-09 15:08:12 +00005879 return SemaRef.Owned(E->Retain());
5880
John McCall8cd78132009-11-19 22:55:06 +00005881 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005882 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00005883 E->isArrow(),
5884 E->getOperatorLoc(),
5885 Qualifier,
5886 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00005887 FirstQualifierInScope,
Douglas Gregor308047d2009-09-09 00:23:06 +00005888 Name,
5889 E->getMemberLoc(),
John McCall10eae182009-11-30 22:42:35 +00005890 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00005891 }
5892
John McCall6b51f282009-11-23 01:53:49 +00005893 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor308047d2009-09-09 00:23:06 +00005894 for (unsigned I = 0, N = E->getNumTemplateArgs(); I != N; ++I) {
John McCall6b51f282009-11-23 01:53:49 +00005895 TemplateArgumentLoc Loc;
5896 if (getDerived().TransformTemplateArgument(E->getTemplateArgs()[I], Loc))
Douglas Gregor308047d2009-09-09 00:23:06 +00005897 return SemaRef.ExprError();
John McCall6b51f282009-11-23 01:53:49 +00005898 TransArgs.addArgument(Loc);
Douglas Gregor308047d2009-09-09 00:23:06 +00005899 }
Mike Stump11289f42009-09-09 15:08:12 +00005900
John McCall8cd78132009-11-19 22:55:06 +00005901 return getDerived().RebuildCXXDependentScopeMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00005902 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 E->isArrow(),
5904 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00005905 Qualifier,
5906 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00005907 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00005908 Name,
5909 E->getMemberLoc(),
5910 &TransArgs);
5911}
5912
5913template<typename Derived>
5914Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005915TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00005916 // Transform the base of the expression.
John McCall2d74de92009-12-01 22:10:20 +00005917 OwningExprResult Base(SemaRef, (Expr*) 0);
5918 QualType BaseType;
5919 if (!Old->isImplicitAccess()) {
5920 Base = getDerived().TransformExpr(Old->getBase());
5921 if (Base.isInvalid())
5922 return SemaRef.ExprError();
5923 BaseType = ((Expr*) Base.get())->getType();
5924 } else {
5925 BaseType = getDerived().TransformType(Old->getBaseType());
5926 }
John McCall10eae182009-11-30 22:42:35 +00005927
5928 NestedNameSpecifier *Qualifier = 0;
5929 if (Old->getQualifier()) {
5930 Qualifier
5931 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005932 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00005933 if (Qualifier == 0)
5934 return SemaRef.ExprError();
5935 }
5936
5937 LookupResult R(SemaRef, Old->getMemberName(), Old->getMemberLoc(),
5938 Sema::LookupOrdinaryName);
5939
5940 // Transform all the decls.
5941 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
5942 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005943 NamedDecl *InstD = static_cast<NamedDecl*>(
5944 getDerived().TransformDecl(Old->getMemberLoc(),
5945 *I));
John McCall84d87672009-12-10 09:41:52 +00005946 if (!InstD) {
5947 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
5948 // This can happen because of dependent hiding.
5949 if (isa<UsingShadowDecl>(*I))
5950 continue;
5951 else
5952 return SemaRef.ExprError();
5953 }
John McCall10eae182009-11-30 22:42:35 +00005954
5955 // Expand using declarations.
5956 if (isa<UsingDecl>(InstD)) {
5957 UsingDecl *UD = cast<UsingDecl>(InstD);
5958 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
5959 E = UD->shadow_end(); I != E; ++I)
5960 R.addDecl(*I);
5961 continue;
5962 }
5963
5964 R.addDecl(InstD);
5965 }
5966
5967 R.resolveKind();
5968
Douglas Gregor9262f472010-04-27 18:19:34 +00005969 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00005970 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005971 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00005972 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00005973 Old->getMemberLoc(),
5974 Old->getNamingClass()));
5975 if (!NamingClass)
5976 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005977
Douglas Gregorda7be082010-04-27 16:10:10 +00005978 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00005979 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005980
John McCall10eae182009-11-30 22:42:35 +00005981 TemplateArgumentListInfo TransArgs;
5982 if (Old->hasExplicitTemplateArgs()) {
5983 TransArgs.setLAngleLoc(Old->getLAngleLoc());
5984 TransArgs.setRAngleLoc(Old->getRAngleLoc());
5985 for (unsigned I = 0, N = Old->getNumTemplateArgs(); I != N; ++I) {
5986 TemplateArgumentLoc Loc;
5987 if (getDerived().TransformTemplateArgument(Old->getTemplateArgs()[I],
5988 Loc))
5989 return SemaRef.ExprError();
5990 TransArgs.addArgument(Loc);
5991 }
5992 }
John McCall38836f02010-01-15 08:34:02 +00005993
5994 // FIXME: to do this check properly, we will need to preserve the
5995 // first-qualifier-in-scope here, just in case we had a dependent
5996 // base (and therefore couldn't do the check) and a
5997 // nested-name-qualifier (and therefore could do the lookup).
5998 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005999
John McCall10eae182009-11-30 22:42:35 +00006000 return getDerived().RebuildUnresolvedMemberExpr(move(Base),
John McCall2d74de92009-12-01 22:10:20 +00006001 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006002 Old->getOperatorLoc(),
6003 Old->isArrow(),
6004 Qualifier,
6005 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006006 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006007 R,
6008 (Old->hasExplicitTemplateArgs()
6009 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006010}
6011
6012template<typename Derived>
6013Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006014TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006015 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006016}
6017
Mike Stump11289f42009-09-09 15:08:12 +00006018template<typename Derived>
6019Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006020TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006021 TypeSourceInfo *EncodedTypeInfo
6022 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6023 if (!EncodedTypeInfo)
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006025
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006027 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Mike Stump11289f42009-09-09 15:08:12 +00006028 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006029
6030 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006031 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 E->getRParenLoc());
6033}
Mike Stump11289f42009-09-09 15:08:12 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035template<typename Derived>
6036Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006037TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006038 // Transform arguments.
6039 bool ArgChanged = false;
6040 ASTOwningVector<&ActionBase::DeleteExpr> Args(SemaRef);
6041 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
6042 OwningExprResult Arg = getDerived().TransformExpr(E->getArg(I));
6043 if (Arg.isInvalid())
6044 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006045
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006046 ArgChanged = ArgChanged || Arg.get() != E->getArg(I);
6047 Args.push_back(Arg.takeAs<Expr>());
6048 }
6049
6050 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6051 // Class message: transform the receiver type.
6052 TypeSourceInfo *ReceiverTypeInfo
6053 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6054 if (!ReceiverTypeInfo)
6055 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006056
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006057 // If nothing changed, just retain the existing message send.
6058 if (!getDerived().AlwaysRebuild() &&
6059 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
6060 return SemaRef.Owned(E->Retain());
6061
6062 // Build a new class message send.
6063 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6064 E->getSelector(),
6065 E->getMethodDecl(),
6066 E->getLeftLoc(),
6067 move_arg(Args),
6068 E->getRightLoc());
6069 }
6070
6071 // Instance message: transform the receiver
6072 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6073 "Only class and instance messages may be instantiated");
6074 OwningExprResult Receiver
6075 = getDerived().TransformExpr(E->getInstanceReceiver());
6076 if (Receiver.isInvalid())
6077 return SemaRef.ExprError();
6078
6079 // If nothing changed, just retain the existing message send.
6080 if (!getDerived().AlwaysRebuild() &&
6081 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
6082 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006083
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006084 // Build a new instance message send.
6085 return getDerived().RebuildObjCMessageExpr(move(Receiver),
6086 E->getSelector(),
6087 E->getMethodDecl(),
6088 E->getLeftLoc(),
6089 move_arg(Args),
6090 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006091}
6092
Mike Stump11289f42009-09-09 15:08:12 +00006093template<typename Derived>
6094Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006095TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006096 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006097}
6098
Mike Stump11289f42009-09-09 15:08:12 +00006099template<typename Derived>
6100Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006101TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006102 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006103}
6104
Mike Stump11289f42009-09-09 15:08:12 +00006105template<typename Derived>
6106Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006107TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006108 // Transform the base expression.
6109 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6110 if (Base.isInvalid())
6111 return SemaRef.ExprError();
6112
6113 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006114
Douglas Gregord51d90d2010-04-26 20:11:03 +00006115 // If nothing changed, just retain the existing expression.
6116 if (!getDerived().AlwaysRebuild() &&
6117 Base.get() == E->getBase())
6118 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006119
Douglas Gregord51d90d2010-04-26 20:11:03 +00006120 return getDerived().RebuildObjCIvarRefExpr(move(Base), E->getDecl(),
6121 E->getLocation(),
6122 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006123}
6124
Mike Stump11289f42009-09-09 15:08:12 +00006125template<typename Derived>
6126Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006127TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
Douglas Gregor9faee212010-04-26 20:47:02 +00006128 // Transform the base expression.
6129 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6130 if (Base.isInvalid())
6131 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006132
Douglas Gregor9faee212010-04-26 20:47:02 +00006133 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006134
Douglas Gregor9faee212010-04-26 20:47:02 +00006135 // If nothing changed, just retain the existing expression.
6136 if (!getDerived().AlwaysRebuild() &&
6137 Base.get() == E->getBase())
6138 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006139
Douglas Gregor9faee212010-04-26 20:47:02 +00006140 return getDerived().RebuildObjCPropertyRefExpr(move(Base), E->getProperty(),
6141 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006142}
6143
Mike Stump11289f42009-09-09 15:08:12 +00006144template<typename Derived>
6145Sema::OwningExprResult
Fariborz Jahanian9a846652009-08-20 17:02:02 +00006146TreeTransform<Derived>::TransformObjCImplicitSetterGetterRefExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006147 ObjCImplicitSetterGetterRefExpr *E) {
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006148 // If this implicit setter/getter refers to class methods, it cannot have any
6149 // dependent parts. Just retain the existing declaration.
6150 if (E->getInterfaceDecl())
6151 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006152
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006153 // Transform the base expression.
6154 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6155 if (Base.isInvalid())
6156 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006157
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006158 // We don't need to transform the getters/setters; they will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006159
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006160 // If nothing changed, just retain the existing expression.
6161 if (!getDerived().AlwaysRebuild() &&
6162 Base.get() == E->getBase())
6163 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006164
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00006165 return getDerived().RebuildObjCImplicitSetterGetterRefExpr(
6166 E->getGetterMethod(),
6167 E->getType(),
6168 E->getSetterMethod(),
6169 E->getLocation(),
6170 move(Base));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006171
Douglas Gregora16548e2009-08-11 05:31:07 +00006172}
6173
Mike Stump11289f42009-09-09 15:08:12 +00006174template<typename Derived>
6175Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006176TreeTransform<Derived>::TransformObjCSuperExpr(ObjCSuperExpr *E) {
Douglas Gregor21515a92010-04-22 17:28:13 +00006177 // Can never occur in a dependent context.
Mike Stump11289f42009-09-09 15:08:12 +00006178 return SemaRef.Owned(E->Retain());
Douglas Gregora16548e2009-08-11 05:31:07 +00006179}
6180
Mike Stump11289f42009-09-09 15:08:12 +00006181template<typename Derived>
6182Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006183TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006184 // Transform the base expression.
6185 OwningExprResult Base = getDerived().TransformExpr(E->getBase());
6186 if (Base.isInvalid())
6187 return SemaRef.ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006188
Douglas Gregord51d90d2010-04-26 20:11:03 +00006189 // If nothing changed, just retain the existing expression.
6190 if (!getDerived().AlwaysRebuild() &&
6191 Base.get() == E->getBase())
6192 return SemaRef.Owned(E->Retain());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006193
Douglas Gregord51d90d2010-04-26 20:11:03 +00006194 return getDerived().RebuildObjCIsaExpr(move(Base), E->getIsaMemberLoc(),
6195 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006196}
6197
Mike Stump11289f42009-09-09 15:08:12 +00006198template<typename Derived>
6199Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006200TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 bool ArgumentChanged = false;
6202 ASTOwningVector<&ActionBase::DeleteExpr> SubExprs(SemaRef);
6203 for (unsigned I = 0, N = E->getNumSubExprs(); I != N; ++I) {
6204 OwningExprResult SubExpr = getDerived().TransformExpr(E->getExpr(I));
6205 if (SubExpr.isInvalid())
6206 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006207
Douglas Gregora16548e2009-08-11 05:31:07 +00006208 ArgumentChanged = ArgumentChanged || SubExpr.get() != E->getExpr(I);
6209 SubExprs.push_back(SubExpr.takeAs<Expr>());
6210 }
Mike Stump11289f42009-09-09 15:08:12 +00006211
Douglas Gregora16548e2009-08-11 05:31:07 +00006212 if (!getDerived().AlwaysRebuild() &&
6213 !ArgumentChanged)
Mike Stump11289f42009-09-09 15:08:12 +00006214 return SemaRef.Owned(E->Retain());
6215
Douglas Gregora16548e2009-08-11 05:31:07 +00006216 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6217 move_arg(SubExprs),
6218 E->getRParenLoc());
6219}
6220
Mike Stump11289f42009-09-09 15:08:12 +00006221template<typename Derived>
6222Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006223TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006224 SourceLocation CaretLoc(E->getExprLoc());
6225
6226 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6227 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6228 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6229 llvm::SmallVector<ParmVarDecl*, 4> Params;
6230 llvm::SmallVector<QualType, 4> ParamTypes;
6231
6232 // Parameter substitution.
6233 const BlockDecl *BD = E->getBlockDecl();
6234 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6235 EN = BD->param_end(); P != EN; ++P) {
6236 ParmVarDecl *OldParm = (*P);
6237 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6238 QualType NewType = NewParm->getType();
6239 Params.push_back(NewParm);
6240 ParamTypes.push_back(NewParm->getType());
6241 }
6242
6243 const FunctionType *BExprFunctionType = E->getFunctionType();
6244 QualType BExprResultType = BExprFunctionType->getResultType();
6245 if (!BExprResultType.isNull()) {
6246 if (!BExprResultType->isDependentType())
6247 CurBlock->ReturnType = BExprResultType;
6248 else if (BExprResultType != SemaRef.Context.DependentTy)
6249 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6250 }
6251
6252 // Transform the body
6253 OwningStmtResult Body = getDerived().TransformStmt(E->getBody());
6254 if (Body.isInvalid())
6255 return SemaRef.ExprError();
6256 // Set the parameters on the block decl.
6257 if (!Params.empty())
6258 CurBlock->TheDecl->setParams(Params.data(), Params.size());
6259
6260 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6261 CurBlock->ReturnType,
6262 ParamTypes.data(),
6263 ParamTypes.size(),
6264 BD->isVariadic(),
6265 0);
6266
6267 CurBlock->FunctionType = FunctionType;
6268 return SemaRef.ActOnBlockStmtExpr(CaretLoc, move(Body), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006269}
6270
Mike Stump11289f42009-09-09 15:08:12 +00006271template<typename Derived>
6272Sema::OwningExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00006274 NestedNameSpecifier *Qualifier = 0;
6275
6276 ValueDecl *ND
6277 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
6278 E->getDecl()));
6279 if (!ND)
6280 return SemaRef.ExprError();
6281
6282 if (!getDerived().AlwaysRebuild() &&
6283 ND == E->getDecl()) {
6284 // Mark it referenced in the new context regardless.
6285 // FIXME: this is a bit instantiation-specific.
6286 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
6287
6288 return SemaRef.Owned(E->Retain());
6289 }
6290
6291 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
6292 ND, E->getLocation(), 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00006293}
Mike Stump11289f42009-09-09 15:08:12 +00006294
Douglas Gregora16548e2009-08-11 05:31:07 +00006295//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00006296// Type reconstruction
6297//===----------------------------------------------------------------------===//
6298
Mike Stump11289f42009-09-09 15:08:12 +00006299template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006300QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
6301 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006302 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006303 getDerived().getBaseEntity());
6304}
6305
Mike Stump11289f42009-09-09 15:08:12 +00006306template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00006307QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
6308 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00006309 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006310 getDerived().getBaseEntity());
6311}
6312
Mike Stump11289f42009-09-09 15:08:12 +00006313template<typename Derived>
6314QualType
John McCall70dd5f62009-10-30 00:06:24 +00006315TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
6316 bool WrittenAsLValue,
6317 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006318 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00006319 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006320}
6321
6322template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006323QualType
John McCall70dd5f62009-10-30 00:06:24 +00006324TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
6325 QualType ClassType,
6326 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00006327 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00006328 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006329}
6330
6331template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006332QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00006333TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
6334 ArrayType::ArraySizeModifier SizeMod,
6335 const llvm::APInt *Size,
6336 Expr *SizeExpr,
6337 unsigned IndexTypeQuals,
6338 SourceRange BracketsRange) {
6339 if (SizeExpr || !Size)
6340 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
6341 IndexTypeQuals, BracketsRange,
6342 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00006343
6344 QualType Types[] = {
6345 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
6346 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
6347 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00006348 };
6349 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
6350 QualType SizeType;
6351 for (unsigned I = 0; I != NumTypes; ++I)
6352 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
6353 SizeType = Types[I];
6354 break;
6355 }
Mike Stump11289f42009-09-09 15:08:12 +00006356
Douglas Gregord6ff3322009-08-04 16:50:30 +00006357 IntegerLiteral ArraySize(*Size, SizeType, /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006358 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006359 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00006360 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00006361}
Mike Stump11289f42009-09-09 15:08:12 +00006362
Douglas Gregord6ff3322009-08-04 16:50:30 +00006363template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006364QualType
6365TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006366 ArrayType::ArraySizeModifier SizeMod,
6367 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00006368 unsigned IndexTypeQuals,
6369 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006370 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006371 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006372}
6373
6374template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006375QualType
Mike Stump11289f42009-09-09 15:08:12 +00006376TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006377 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00006378 unsigned IndexTypeQuals,
6379 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006380 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00006381 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006382}
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregord6ff3322009-08-04 16:50:30 +00006384template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006385QualType
6386TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006387 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006388 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006389 unsigned IndexTypeQuals,
6390 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006391 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006392 SizeExpr.takeAs<Expr>(),
6393 IndexTypeQuals, BracketsRange);
6394}
6395
6396template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006397QualType
6398TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006399 ArrayType::ArraySizeModifier SizeMod,
Douglas Gregora16548e2009-08-11 05:31:07 +00006400 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006401 unsigned IndexTypeQuals,
6402 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00006403 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006404 SizeExpr.takeAs<Expr>(),
6405 IndexTypeQuals, BracketsRange);
6406}
6407
6408template<typename Derived>
6409QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Chris Lattner37141f42010-06-23 06:00:24 +00006410 unsigned NumElements,
6411 VectorType::AltiVecSpecific AltiVecSpec) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006412 // FIXME: semantic checking!
Chris Lattner37141f42010-06-23 06:00:24 +00006413 return SemaRef.Context.getVectorType(ElementType, NumElements, AltiVecSpec);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006414}
Mike Stump11289f42009-09-09 15:08:12 +00006415
Douglas Gregord6ff3322009-08-04 16:50:30 +00006416template<typename Derived>
6417QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
6418 unsigned NumElements,
6419 SourceLocation AttributeLoc) {
6420 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
6421 NumElements, true);
6422 IntegerLiteral *VectorSize
Mike Stump11289f42009-09-09 15:08:12 +00006423 = new (SemaRef.Context) IntegerLiteral(numElements, SemaRef.Context.IntTy,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006424 AttributeLoc);
6425 return SemaRef.BuildExtVectorType(ElementType, SemaRef.Owned(VectorSize),
6426 AttributeLoc);
6427}
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregord6ff3322009-08-04 16:50:30 +00006429template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006430QualType
6431TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006432 ExprArg SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006433 SourceLocation AttributeLoc) {
6434 return SemaRef.BuildExtVectorType(ElementType, move(SizeExpr), AttributeLoc);
6435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregord6ff3322009-08-04 16:50:30 +00006437template<typename Derived>
6438QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00006439 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006440 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00006441 bool Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006442 unsigned Quals) {
Mike Stump11289f42009-09-09 15:08:12 +00006443 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00006444 Quals,
6445 getDerived().getBaseLocation(),
6446 getDerived().getBaseEntity());
6447}
Mike Stump11289f42009-09-09 15:08:12 +00006448
Douglas Gregord6ff3322009-08-04 16:50:30 +00006449template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00006450QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
6451 return SemaRef.Context.getFunctionNoProtoType(T);
6452}
6453
6454template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00006455QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
6456 assert(D && "no decl found");
6457 if (D->isInvalidDecl()) return QualType();
6458
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006459 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00006460 TypeDecl *Ty;
6461 if (isa<UsingDecl>(D)) {
6462 UsingDecl *Using = cast<UsingDecl>(D);
6463 assert(Using->isTypeName() &&
6464 "UnresolvedUsingTypenameDecl transformed to non-typename using");
6465
6466 // A valid resolved using typename decl points to exactly one type decl.
6467 assert(++Using->shadow_begin() == Using->shadow_end());
6468 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006469
John McCallb96ec562009-12-04 22:46:56 +00006470 } else {
6471 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
6472 "UnresolvedUsingTypenameDecl transformed to non-using decl");
6473 Ty = cast<UnresolvedUsingTypenameDecl>(D);
6474 }
6475
6476 return SemaRef.Context.getTypeDeclType(Ty);
6477}
6478
6479template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006480QualType TreeTransform<Derived>::RebuildTypeOfExprType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006481 return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
6482}
6483
6484template<typename Derived>
6485QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
6486 return SemaRef.Context.getTypeOfType(Underlying);
6487}
6488
6489template<typename Derived>
Douglas Gregora16548e2009-08-11 05:31:07 +00006490QualType TreeTransform<Derived>::RebuildDecltypeType(ExprArg E) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00006491 return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
6492}
6493
6494template<typename Derived>
6495QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00006496 TemplateName Template,
6497 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00006498 const TemplateArgumentListInfo &TemplateArgs) {
6499 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00006500}
Mike Stump11289f42009-09-09 15:08:12 +00006501
Douglas Gregor1135c352009-08-06 05:28:30 +00006502template<typename Derived>
6503NestedNameSpecifier *
6504TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6505 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006506 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006507 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00006508 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00006509 CXXScopeSpec SS;
6510 // FIXME: The source location information is all wrong.
6511 SS.setRange(Range);
6512 SS.setScopeRep(Prefix);
6513 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00006514 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00006515 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006516 ObjectType,
6517 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00006518 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00006519}
6520
6521template<typename Derived>
6522NestedNameSpecifier *
6523TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6524 SourceRange Range,
6525 NamespaceDecl *NS) {
6526 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
6527}
6528
6529template<typename Derived>
6530NestedNameSpecifier *
6531TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
6532 SourceRange Range,
6533 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006534 QualType T) {
6535 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00006536 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00006537 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00006538 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
6539 T.getTypePtr());
6540 }
Mike Stump11289f42009-09-09 15:08:12 +00006541
Douglas Gregor1135c352009-08-06 05:28:30 +00006542 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
6543 return 0;
6544}
Mike Stump11289f42009-09-09 15:08:12 +00006545
Douglas Gregor71dc5092009-08-06 06:41:21 +00006546template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006547TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006548TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6549 bool TemplateKW,
6550 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00006551 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00006552 Template);
6553}
6554
6555template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006556TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00006557TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor308047d2009-09-09 00:23:06 +00006558 const IdentifierInfo &II,
6559 QualType ObjectType) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00006560 CXXScopeSpec SS;
6561 SS.setRange(SourceRange(getDerived().getBaseLocation()));
Mike Stump11289f42009-09-09 15:08:12 +00006562 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00006563 UnqualifiedId Name;
6564 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00006565 Sema::TemplateTy Template;
6566 getSema().ActOnDependentTemplateName(/*Scope=*/0,
6567 /*FIXME:*/getDerived().getBaseLocation(),
6568 SS,
6569 Name,
6570 ObjectType.getAsOpaquePtr(),
6571 /*EnteringContext=*/false,
6572 Template);
6573 return Template.template getAsVal<TemplateName>();
Douglas Gregor71dc5092009-08-06 06:41:21 +00006574}
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00006577TemplateName
6578TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
6579 OverloadedOperatorKind Operator,
6580 QualType ObjectType) {
6581 CXXScopeSpec SS;
6582 SS.setRange(SourceRange(getDerived().getBaseLocation()));
6583 SS.setScopeRep(Qualifier);
6584 UnqualifiedId Name;
6585 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
6586 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
6587 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00006588 Sema::TemplateTy Template;
6589 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00006590 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00006591 SS,
6592 Name,
6593 ObjectType.getAsOpaquePtr(),
6594 /*EnteringContext=*/false,
6595 Template);
6596 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00006597}
Alexis Hunta8136cc2010-05-05 15:23:54 +00006598
Douglas Gregor71395fa2009-11-04 00:56:37 +00006599template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00006600Sema::OwningExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006601TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
6602 SourceLocation OpLoc,
6603 ExprArg Callee,
6604 ExprArg First,
6605 ExprArg Second) {
6606 Expr *FirstExpr = (Expr *)First.get();
6607 Expr *SecondExpr = (Expr *)Second.get();
John McCalld14a8642009-11-21 08:51:07 +00006608 Expr *CalleeExpr = ((Expr *)Callee.get())->IgnoreParenCasts();
Douglas Gregora16548e2009-08-11 05:31:07 +00006609 bool isPostIncDec = SecondExpr && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00006610
Douglas Gregora16548e2009-08-11 05:31:07 +00006611 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00006612 if (Op == OO_Subscript) {
6613 if (!FirstExpr->getType()->isOverloadableType() &&
6614 !SecondExpr->getType()->isOverloadableType())
6615 return getSema().CreateBuiltinArraySubscriptExpr(move(First),
John McCalld14a8642009-11-21 08:51:07 +00006616 CalleeExpr->getLocStart(),
Sebastian Redladba46e2009-10-29 20:17:01 +00006617 move(Second), OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00006618 } else if (Op == OO_Arrow) {
6619 // -> is never a builtin operation.
6620 return SemaRef.BuildOverloadedArrowExpr(0, move(First), OpLoc);
Sebastian Redladba46e2009-10-29 20:17:01 +00006621 } else if (SecondExpr == 0 || isPostIncDec) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006622 if (!FirstExpr->getType()->isOverloadableType()) {
6623 // The argument is not of overloadable type, so try to create a
6624 // built-in unary operation.
Mike Stump11289f42009-09-09 15:08:12 +00006625 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006626 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00006627
Douglas Gregora16548e2009-08-11 05:31:07 +00006628 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, move(First));
6629 }
6630 } else {
Mike Stump11289f42009-09-09 15:08:12 +00006631 if (!FirstExpr->getType()->isOverloadableType() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 !SecondExpr->getType()->isOverloadableType()) {
6633 // Neither of the arguments is an overloadable type, so try to
6634 // create a built-in binary operation.
6635 BinaryOperator::Opcode Opc = BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006636 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006637 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, FirstExpr, SecondExpr);
6638 if (Result.isInvalid())
6639 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006640
Douglas Gregora16548e2009-08-11 05:31:07 +00006641 First.release();
6642 Second.release();
6643 return move(Result);
6644 }
6645 }
Mike Stump11289f42009-09-09 15:08:12 +00006646
6647 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00006648 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00006649 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00006650
John McCalld14a8642009-11-21 08:51:07 +00006651 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(CalleeExpr)) {
6652 assert(ULE->requiresADL());
6653
6654 // FIXME: Do we have to check
6655 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00006656 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00006657 } else {
John McCall4c4c1df2010-01-26 03:27:55 +00006658 Functions.addDecl(cast<DeclRefExpr>(CalleeExpr)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00006659 }
Mike Stump11289f42009-09-09 15:08:12 +00006660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661 // Add any functions found via argument-dependent lookup.
6662 Expr *Args[2] = { FirstExpr, SecondExpr };
6663 unsigned NumArgs = 1 + (SecondExpr != 0);
Mike Stump11289f42009-09-09 15:08:12 +00006664
Douglas Gregora16548e2009-08-11 05:31:07 +00006665 // Create the overloaded operator invocation for unary operators.
6666 if (NumArgs == 1 || isPostIncDec) {
Mike Stump11289f42009-09-09 15:08:12 +00006667 UnaryOperator::Opcode Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00006668 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
6669 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(First));
6670 }
Mike Stump11289f42009-09-09 15:08:12 +00006671
Sebastian Redladba46e2009-10-29 20:17:01 +00006672 if (Op == OO_Subscript)
John McCalld14a8642009-11-21 08:51:07 +00006673 return SemaRef.CreateOverloadedArraySubscriptExpr(CalleeExpr->getLocStart(),
6674 OpLoc,
6675 move(First),
6676 move(Second));
Sebastian Redladba46e2009-10-29 20:17:01 +00006677
Douglas Gregora16548e2009-08-11 05:31:07 +00006678 // Create the overloaded operator invocation for binary operators.
Mike Stump11289f42009-09-09 15:08:12 +00006679 BinaryOperator::Opcode Opc =
Douglas Gregora16548e2009-08-11 05:31:07 +00006680 BinaryOperator::getOverloadedOpcode(Op);
Mike Stump11289f42009-09-09 15:08:12 +00006681 OwningExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00006682 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
6683 if (Result.isInvalid())
6684 return SemaRef.ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006685
Douglas Gregora16548e2009-08-11 05:31:07 +00006686 First.release();
6687 Second.release();
Mike Stump11289f42009-09-09 15:08:12 +00006688 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00006689}
Mike Stump11289f42009-09-09 15:08:12 +00006690
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006691template<typename Derived>
Alexis Hunta8136cc2010-05-05 15:23:54 +00006692Sema::OwningExprResult
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006693TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(ExprArg Base,
6694 SourceLocation OperatorLoc,
6695 bool isArrow,
6696 NestedNameSpecifier *Qualifier,
6697 SourceRange QualifierRange,
6698 TypeSourceInfo *ScopeType,
6699 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006700 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006701 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006702 CXXScopeSpec SS;
6703 if (Qualifier) {
6704 SS.setRange(QualifierRange);
6705 SS.setScopeRep(Qualifier);
6706 }
6707
6708 Expr *BaseE = (Expr *)Base.get();
6709 QualType BaseType = BaseE->getType();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006710 if (BaseE->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006711 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00006712 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00006713 !BaseType->getAs<PointerType>()->getPointeeType()
6714 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006715 // This pseudo-destructor expression is still a pseudo-destructor.
6716 return SemaRef.BuildPseudoDestructorExpr(move(Base), OperatorLoc,
6717 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006718 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006719 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006720 /*FIXME?*/true);
6721 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006722
Douglas Gregor678f90d2010-02-25 01:56:36 +00006723 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006724 DeclarationName Name
6725 = SemaRef.Context.DeclarationNames.getCXXDestructorName(
6726 SemaRef.Context.getCanonicalType(DestroyedType->getType()));
Alexis Hunta8136cc2010-05-05 15:23:54 +00006727
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006728 // FIXME: the ScopeType should be tacked onto SS.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006729
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006730 return getSema().BuildMemberReferenceExpr(move(Base), BaseType,
6731 OperatorLoc, isArrow,
6732 SS, /*FIXME: FirstQualifier*/ 0,
Douglas Gregor678f90d2010-02-25 01:56:36 +00006733 Name, Destroyed.getLocation(),
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006734 /*TemplateArgs*/ 0);
6735}
6736
Douglas Gregord6ff3322009-08-04 16:50:30 +00006737} // end namespace clang
6738
6739#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H